|
|
Home » U++ Library support » RichText,QTF,RTF... » Constant font size in resizeable RichEdit?
|
|
|
|
|
|
|
Re: Constant font size in resizeable RichEdit? [message #40945 is a reply to message #40933] |
Fri, 11 October 2013 11:02   |
iST1
Messages: 107 Registered: August 2013
|
Experienced Member |
|
|
Both solutions do not come:
class ExtRichEdit : public RichEdit {
public:
typedef AppRichEdit CLASSNAME;
float zoomlevel;
//==========================================================================================
virtual void MouseWheel(Point p, int zdelta, dword keyflags) {
if (keyflags == K_CTRL) {
// Zooms font
float fzdelta = zdelta;
zoomlevel+= (fzdelta / 240.0); // One bump on the mouse wheel is 120 on my machine
RefreshLayoutDeep();
} else {
// Scrolls down
RichEdit::MouseWheel(p, zdelta, keyflags);
}
}
//==========================================================================================
void Layout() {
RichEdit::Layout();
#if 0
//Mirek's solution: to big font
SetPage(Size(minmax(GetSize().cx, 50, 10000), INT_MAX));
#else
//Alendar's solution: to small font
long editor_cx = GetSize().cx;
long adaptive_cx = (editor_cx * zoomlevel); // Smaller the number, the bigger the text
SetPage(Size(adaptive_cx, INT_MAX));
#endif
}
};
GUI_APP_MAIN
{
ExtRichEdit edit;
TopWindow r;
r.Add(edit.SizePos());
TopWindow wnd;
SplitterFrame sp;
wnd.AddFrame(sp.Right(r, 300));
wnd.AddFrame(NullFrame());
wnd.Run();
}
|
|
|
|
|
|
Re: Constant font size in resizeable RichEdit? [message #41029 is a reply to message #41020] |
Tue, 22 October 2013 16:10   |
 |
koldo
Messages: 3432 Registered: August 2008
|
Senior Veteran |
|
|
My proposal:
class RichEdit2 : public RichEdit {
public:
RichEdit2() {
zoomlevel = 7;
}
virtual void Layout() {
RichEdit::Layout();
SetPage(Size(int(zoomlevel*GetSize().cx), INT_MAX)); // Smaller the total, the bigger the text
}
virtual void MouseWheel(Point p, int zdelta, dword keyflags) {
if (keyflags == K_CTRL) { // Zooms font
zoomlevel += zdelta/240.;
if (zoomlevel < 1)
zoomlevel = 10;
else if (zoomlevel > 9)
zoomlevel = 1;
RefreshLayoutDeep();
} else // Scrolls down
RichEdit::MouseWheel(p, zdelta, keyflags);
}
double zoomlevel;
};
Best regards
Iñaki
[Updated on: Tue, 22 October 2013 16:11] Report message to a moderator
|
|
|
|
|
|
|
|
Re: Constant font size in resizeable RichEdit? [message #50785 is a reply to message #41077] |
Tue, 18 December 2018 16:41  |
Tooraj
Messages: 2 Registered: December 2018 Location: Frankfurt am Main
|
Junior Member |
|
|
It seems, that this important change was forgotten for RichTextView:
For RichTextView the override needs to be slightly modified:
class RichTextView2 : public RichTextView {
public:
RichTextView2() {
zoomlevel = 7;
}
virtual void Layout() {
RichTextView::Layout();
PageWidth( int(zoomlevel*GetSize().cx) ); // Smaller the total, the bigger the text
}
virtual void MouseWheel(Point p, int zdelta, dword keyflags) {
if (keyflags == K_CTRL) { // Zooms font
zoomlevel += zdelta/240.;
if (zoomlevel < 1)
zoomlevel = 10;
else if (zoomlevel > 9)
zoomlevel = 1;
RefreshLayoutDeep();
} else // Scrolls down
RichTextView::MouseWheel(p, zdelta, keyflags);
}
double zoomlevel;
};
[Updated on: Wed, 19 December 2018 11:33] by Moderator Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat Apr 26 15:04:46 CEST 2025
Total time taken to generate the page: 0.00577 seconds
|
|
|