[GH-ISSUE #164] How can I add RichTextCtrl to Status bar? #72

Open
opened 2026-05-05 03:37:48 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @nicesai on GitHub (Oct 15, 2023).
Original GitHub issue: https://github.com/ultimatepp/ultimatepp/issues/164

How can I add RichTextCtrl to Status bar? And use that instead to show rich text messages?
I cannot add directly using AddFrame as its not a InfoCtrl.

I tried the following and add it to status bar, but its interfering with other status bar functions like progress bar etc.

`

struct RichInfoCtrl : InfoCtrl {
    RichTextCtrl richCtrl;
        
    RichInfoCtrl() {
        richCtrl.HSizePosZ(0, 0).VSizePosZ(0, 0);
        this->Add(richCtrl);
        Set(" "); // to clear default "Ready" text
        richCtrl = "Ready";  // use richtext instead
    }
    
    void SetMsg(String str) {
        richCtrl = str;
    }
};

`

Is there a recommended way to add RichTextCtrl to status bar?

Originally created by @nicesai on GitHub (Oct 15, 2023). Original GitHub issue: https://github.com/ultimatepp/ultimatepp/issues/164 How can I add RichTextCtrl to Status bar? And use that instead to show rich text messages? I cannot add directly using AddFrame as its not a InfoCtrl. I tried the following and add it to status bar, but its interfering with other status bar functions like progress bar etc. ` struct RichInfoCtrl : InfoCtrl { RichTextCtrl richCtrl; RichInfoCtrl() { richCtrl.HSizePosZ(0, 0).VSizePosZ(0, 0); this->Add(richCtrl); Set(" "); // to clear default "Ready" text richCtrl = "Ready"; // use richtext instead } void SetMsg(String str) { richCtrl = str; } }; ` Is there a recommended way to add RichTextCtrl to status bar?
Author
Owner

@ismail-yilmaz commented on GitHub (Oct 15, 2023):

How can I add RichTextCtrl to Status bar? And use that instead to show rich text messages? I cannot add directly using AddFrame as its not a InfoCtrl.

I tried the following and add it to status bar, but its interfering with other status bar functions like progress bar etc.

`

struct RichInfoCtrl : InfoCtrl {
    RichTextCtrl richCtrl;
        
    RichInfoCtrl() {
        richCtrl.HSizePosZ(0, 0).VSizePosZ(0, 0);
        this->Add(richCtrl);
        Set(" "); // to clear default "Ready" text
        richCtrl = "Ready";  // use richtext instead
    }
    
    void SetMsg(String str) {
        richCtrl = str;
    }
};

`

Is there a recommended way to add RichTextCtrl to status bar?

You can use smart text (RichText) in info widgets. Just use DrawSmartText function to paint text in the display.
Below is the modified version of uppsrc/reference/StatusBar example. It adds rich text support (Remember: there are also other ways to achive this):

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct PosDisplay : Display {
	virtual void Paint(Draw& w, const Rect& r, const Value& q,
	                   Color ink, Color paper, dword style) const {

		if(q.Is<String>())
			Upp::DrawSmartText(w, 0, 0, r.Width(), q.To<String>()); // Draws the rich text;
	}
};

struct App : TopWindow {
	StatusBar   status;
	InfoCtrl    x, y;
	PosDisplay  dx, dy;

	virtual void MouseMove(Point p, dword)
	{

		String sx, sy;

		sx << "\1[g@4=/ x: " << p.x << " ]"; // Rich text, green, centered, italic
		sy << "\1[g@3>_ y: " << p.y << " ]"; // Rich text, red, right aligned, underlined

		x.Set(PaintRect(dx, sx));
		y.Set(PaintRect(dy, sy));
	}

	App() {
		Sizeable();
		SetFrame(FieldFrame());
		AddFrame(status);
		status.AddFrame(x.Left(100));
		status.AddFrame(y.Left(100));
	}
};

GUI_APP_MAIN
{
	App().Run();
}

`

Edit: Simplified the example.

Best regards,

<!-- gh-comment-id:1763358158 --> @ismail-yilmaz commented on GitHub (Oct 15, 2023): > How can I add RichTextCtrl to Status bar? And use that instead to show rich text messages? I cannot add directly using AddFrame as its not a InfoCtrl. > > I tried the following and add it to status bar, but its interfering with other status bar functions like progress bar etc. > > ` > > ``` > struct RichInfoCtrl : InfoCtrl { > RichTextCtrl richCtrl; > > RichInfoCtrl() { > richCtrl.HSizePosZ(0, 0).VSizePosZ(0, 0); > this->Add(richCtrl); > Set(" "); // to clear default "Ready" text > richCtrl = "Ready"; // use richtext instead > } > > void SetMsg(String str) { > richCtrl = str; > } > }; > ``` > > ` > > Is there a recommended way to add RichTextCtrl to status bar? You can use smart text (RichText) in info widgets. Just use DrawSmartText function to paint text in the display. Below is the modified version of uppsrc/reference/StatusBar example. It adds rich text support (Remember: there are also other ways to achive this): #include <CtrlLib/CtrlLib.h> using namespace Upp; struct PosDisplay : Display { virtual void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const { if(q.Is<String>()) Upp::DrawSmartText(w, 0, 0, r.Width(), q.To<String>()); // Draws the rich text; } }; struct App : TopWindow { StatusBar status; InfoCtrl x, y; PosDisplay dx, dy; virtual void MouseMove(Point p, dword) { String sx, sy; sx << "\1[g@4=/ x: " << p.x << " ]"; // Rich text, green, centered, italic sy << "\1[g@3>_ y: " << p.y << " ]"; // Rich text, red, right aligned, underlined x.Set(PaintRect(dx, sx)); y.Set(PaintRect(dy, sy)); } App() { Sizeable(); SetFrame(FieldFrame()); AddFrame(status); status.AddFrame(x.Left(100)); status.AddFrame(y.Left(100)); } }; GUI_APP_MAIN { App().Run(); } ` Edit: Simplified the example. Best regards,
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/ultimatepp#72
No description provided.