U++ framework
Do not panic. Ask here before giving up.

Home » Community » Newbie corner » How to get rect of small square of OptionBox (Custom OptionBox Ctrl)
How to get rect of small square of OptionBox [message #62062] Mon, 21 September 2026 07:24 Go to next message
DiaosLu
Messages: 5
Registered: July 2026
Promising Member
I am making a custom OptionBox which change selection state only by clicking on the small square.

However, I cannot find how to get the Rect of square accurately, anyone can help?
Re: How to get rect of small square of OptionBox [message #62064 is a reply to message #62062] Mon, 21 September 2026 19:01 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1284
Registered: August 2007
Senior Contributor
Hi,

One way (usually something like this, if you want to build your own  ctrl...)

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct MyApp : TopWindow  {
	Point pos = Null;
	bool pressed = false;
	Rect target  = Null;
	MyApp()
	{
		Sizeable().Zoomable().CenterScreen().SetRect(0, 0, 400, 400);
	}
	
	void Paint(Draw& w) override
	{
		w.DrawRect(GetView(), Black());
		w.DrawRect(target, pressed ? Green() : target.Contains(pos) ? Red() :  White());
	}
	
	void Layout() override
	{
		Rect r = GetView();
		target = r.CenterRect(r.GetSize() / 4);
	}
	
	void LeftDown(Point pt, dword) override
	{
		SetCapture();
		pressed = target.Contains(pt);
		Refresh();
	}
	
	void LeftUp(Point pt, dword) override
	{
		ReleaseCapture();
		pressed = false;
		Refresh();
	}
	
	void MouseMove(Point pt, dword) override
	{
		pos = pt;
		Refresh();
	}
};

GUI_APP_MAIN
{
	MyApp().Run();
}

Best regards,
Oblivion


Re: How to get rect of small square of OptionBox [message #62065 is a reply to message #62064] Tue, 22 September 2026 04:09 Go to previous message
DiaosLu
Messages: 5
Registered: July 2026
Promising Member
HI, Oblivion. Thank you for your reply.

Let me make a clarification. I know the flow of custom ctrl, and I have made a working custom OptionBox. The only thing is I can't figure out the accurate Rect of square in OptionBox.
Previous Topic: Problem DUMP INT64_MIN
Next Topic: New system of feature requests on our forums- please read and use!
Goto Forum:
  


Current Time: Tue Sep 29 15:29:58 GMT+2 2026

Total time taken to generate the page: 0.09457 seconds