Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » RichText,QTF,RTF... » Constant font size in resizeable RichEdit?
Constant font size in resizeable RichEdit? [message #24118] Sun, 27 December 2009 13:29 Go to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 916
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

There is a task of making RichEdit editing some text. Control itself is resizeable. Each time I change its width, it changes font size accordingly. This is suitable for reading books, but writing text while font size heavily depends on width of the window makes serious visual problem for writer. So I want to make font size constant and independent from width of RichEdit control. Is it possible? Could you please tell how to do it?
Re: Constant font size in resizeable RichEdit? [message #24129 is a reply to message #24118] Sun, 27 December 2009 19:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11713
Registered: November 2005
Ultimate Member
I believe it would be possible to achieve it using ViewBorder or SetZoom - you would have to adjust both dynamically as the size changes.

Mirek
Re: Constant font size in resizeable RichEdit? [message #40915 is a reply to message #24129] Mon, 07 October 2013 18:18 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
SetZoom doesn't help: with value > 100 text shifted outside left border.
Re: Constant font size in resizeable RichEdit? [message #40920 is a reply to message #40915] Tue, 08 October 2013 08:05 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11713
Registered: November 2005
Ultimate Member
I am sorry, SetZoom indeed does not work, but something like

struct MyEdit : RichEdit;

void MyEdit::Layout()
{
	RichEdit::Layout();
	SetPage(Size(minmax(GetSize().cx, 50, 10000), INT_MAX));
}


does.
Re: Constant font size in resizeable RichEdit? [message #40921 is a reply to message #40920] Tue, 08 October 2013 12:22 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2922
Registered: August 2008
Veteran
Please see this nice proposal from Alendar:

http://www.ultimatepp.org/forum/index.php?t=msg&goto=407 73&#msg_40773

It includes Mirek solution plus control mouse zoom.

It could be good to include this behavior in RichEdit. It is proposed in Redmine: http://www.ultimatepp.org/redmine/issues/518


Best regards
Iñaki
Re: Constant font size in resizeable RichEdit? [message #40925 is a reply to message #40921] Tue, 08 October 2013 19:59 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11713
Registered: November 2005
Ultimate Member
koldo wrote on Tue, 08 October 2013 06:22

Please see this nice proposal from Alendar:

http://www.ultimatepp.org/forum/index.php?t=msg&goto=407 73&#msg_40773

It includes Mirek solution plus control mouse zoom.

It could be good to include this behavior in RichEdit. It is proposed in Redmine: http://www.ultimatepp.org/redmine/issues/518



I know, but it is good for specialized variants of RichEdit.

The problem is that RichEdit is intended (and used!) for WYSIWYG. Changing number of characters per line defeats that purpose.

Anyway, perhaps the right solution would be to provide derived class?
Re: Constant font size in resizeable RichEdit? [message #40933 is a reply to message #40925] Wed, 09 October 2013 08:15 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2922
Registered: August 2008
Veteran
Hello Mirek

In my case in fact it has more sense the derived than the original RichEdit as the expected behavior is:
- to maintain font size when changing control size
- Ctrl-Wheel resizes the font

Actual RichEdit is so rich that with few additional lines of code it can have this new behavior.

This way, I would just add the new behavior to actual RichEdit and I would add a SetXXX() to set the preferred behavior.


Best regards
Iñaki
Re: Constant font size in resizeable RichEdit? [message #40945 is a reply to message #40933] Fri, 11 October 2013 11:02 Go to previous messageGo to next message
iST1 is currently offline  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 #40947 is a reply to message #40945] Fri, 11 October 2013 14:21 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2922
Registered: August 2008
Veteran
Hello iST1

Mirek's solution permits a fixed zoom and Alendar's one permits variable zoom using mouse wheel or other means.


Best regards
Iñaki
Re: Constant font size in resizeable RichEdit? [message #40948 is a reply to message #40947] Fri, 11 October 2013 14:23 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
Yes, but default behavior must be, i mean, with normal font size
Re: Constant font size in resizeable RichEdit? [message #41020 is a reply to message #40948] Mon, 21 October 2013 17:58 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
In example above must be
typedef ExtRichEdit CLASSNAME;
and i still with troubles in getting a normal font's size Sad
Re: Constant font size in resizeable RichEdit? [message #41029 is a reply to message #41020] Tue, 22 October 2013 16:10 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2922
Registered: August 2008
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 #41031 is a reply to message #41029] Tue, 22 October 2013 16:28 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
Great!
Re: Constant font size in resizeable RichEdit? [message #41077 is a reply to message #41031] Tue, 29 October 2013 18:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11713
Registered: November 2005
Ultimate Member
RichEdit now has "Floating" method that does exactly this...
Re: Constant font size in resizeable RichEdit? [message #41084 is a reply to message #41077] Wed, 30 October 2013 13:04 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2922
Registered: August 2008
Veteran
Hello Mirek

This is a good addition, although it would be great to modify the zoom with the mouse wheel.

This feature works in many if not all text processing programs even in image editors and CAD programs.


Best regards
Iñaki
Re: Constant font size in resizeable RichEdit? [message #41085 is a reply to message #41084] Wed, 30 October 2013 13:07 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 11713
Registered: November 2005
Ultimate Member
koldo wrote on Wed, 30 October 2013 08:04

Hello Mirek

This is a good addition, although it would be great to modify the zoom with the mouse wheel.



Have you checked? It is supposed to work... (only in floating mode though)
Re: Constant font size in resizeable RichEdit? [message #41092 is a reply to message #41085] Wed, 30 October 2013 23:07 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 2922
Registered: August 2008
Veteran
Oh yes you are right

I did not see the change in Mouse.cpp Smile.


Best regards
Iñaki
Re: Constant font size in resizeable RichEdit? [message #50785 is a reply to message #41077] Tue, 18 December 2018 16:41 Go to previous message
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

Previous Topic: EncodeRTF bullet bug
Next Topic: RichText over an image background - weird scroll (on windows)
Goto Forum:
  


Current Time: Sat Feb 23 08:19:29 CET 2019

Total time taken to generate the page: 0.00815 seconds