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 » Community » Newbie corner » The Mysterious checkbox (I am positively confused by the Check box (a.k.a Option) control)
The Mysterious checkbox [message #55562] Sun, 22 November 2020 03:26 Go to next message
steveo is currently offline  steveo
Messages: 11
Registered: November 2020
Promising Member
To me a check box is a box that holds one of 2 states, either checked or not checked. It is useful to be able to respond to changes in check box state. I have spent the last hour looking over the 100 or so methods which seem to be associated with the check box and for the life of me I can't figure out how to call a method on that control which will tell me the state "checked or not checked".

Any ideas?
Re: The Mysterious checkbox [message #55567 is a reply to message #55562] Sun, 22 November 2020 09:07 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Hello steveo,

Quote:
To me a check box is a box that holds one of 2 states, either checked or not checked. It is useful to be able to respond to changes in check box state. I have spent the last hour looking over the 100 or so methods which seem to be associated with the check box and for the life of me I can't figure out how to call a method on that control which will tell me the state "checked or not checked".

Any ideas?



#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct MyAppWindow : TopWindow {
	Option option;
	MyAppWindow()
	{
		Sizeable().Zoomable().CenterScreen().SetRect(0,0, 640, 480);
		Add(option.SetLabel("Option").LeftPosZ(20).TopPosZ(20));
		option << [=] { Title(Format("Option (checbox) state: %", ~option)); };

		// OR,
		// option.WhenAction = [=] { Title(Format("Option (checbox) state: %", ~option)); };
	};
};

GUI_APP_MAIN
{
	MyAppWindow().Run();
}




Almost all trivial ctrls (widgets) follow the same pattern. If they contain a Value you can access it via a tilde (~) operator,
Or via GetData and SetData methods. And they define a WhenAction callback which can be also set by an overloaded operator.

I suggest you check the Ctrl design concepts document:

https://www.ultimatepp.org/srcdoc$CtrlCore$CtrlDesignConcept s_en-us.html

Best regards,
Oblivion


[Updated on: Sun, 22 November 2020 09:10]

Report message to a moderator

Re: The Mysterious checkbox [message #55609 is a reply to message #55567] Mon, 23 November 2020 23:21 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello Stevo and Oblivion,

I added exemplary usage to our Option documentation. I hope it will help, also thanks Stevo for the question. It is valuable information that the description might be misleading for new users and API is not so easy to use.

I would like to also proposed some improvements to Option API to be more verbose - should be much more easier to understand:
bool IsChecked();     // value == 1
bool IsUnchecked()    // value == 0
bool IsInderminate(); // value == Null


I am probably more liberal than Mirek and I would like to see more alternatives to operator overload.

Klugier


U++ - one framework to rule them all.

[Updated on: Mon, 23 November 2020 23:25]

Report message to a moderator

Re: The Mysterious checkbox [message #55618 is a reply to message #55609] Tue, 24 November 2020 10:35 Go to previous message
omari is currently offline  omari
Messages: 264
Registered: March 2010
Experienced Member
also, you can use it the easy way. think of int operator() that return : 1 if checked, 0 if not.
    Option a;
    ....
    a = 1;  // set checked
    a = 0;  // set unchecked
    a = true;  // set checked
    a = false; // set unchecked
    a = !a;  // change checked
    ....
    if(a) // checked
    {
     ...
    }




regards
omari.

[Updated on: Tue, 24 November 2020 11:37]

Report message to a moderator

Previous Topic: Reliably converting between std::vector<uint8_t> and WString
Next Topic: check if application is running
Goto Forum:
  


Current Time: Fri Mar 29 01:52:28 CET 2024

Total time taken to generate the page: 0.01386 seconds