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: 8
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: 791
Registered: August 2007
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: 792
Registered: September 2012
Location: Poland, Kraków
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


Ultimate++ - 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: 239
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: Debug No Longer Works
Next Topic: New system of feature requests on our forums- please read and use!
Goto Forum:
  


Current Time: Wed Nov 25 08:23:57 CET 2020

Total time taken to generate the page: 0.01263 seconds