Checkbox future improvments

Started by billarhos, 30 December 2018, 12:29:32

billarhos

Hi,
I am trying to set initial value to checkbox without sending to me back a signal event. This is happening on initializing. It is important for me this two callbacks not to be triggered
in initializing progress. Only to set the visible part of checkbox (On/Off).

Now it is ok because i am using some booleans to avoid this.

This can be prevented by adding a "SetState(bool onOff)" function without triggering any callbacks in it.


pCheckBox = GAME_MANAGER->getGuiTheme()->load("CheckBox");
pCheckBox->setPosition(GAME_MANAGER->layoutWidth(450), GAME_MANAGER->layoutHeight(280));
pCheckBox->setSize(GAME_MANAGER->layoutWidth(100), GAME_MANAGER->layoutHeight(50));

pCheckBox->connect("Checked", [=]()
{
//do something here but only when user check this
});

pCheckBox->connect("Unchecked", [=]()
{
//do something here but only when user uncheck this
});

if (MEMORY_MANAGER->readDataBool(MemoryMain::checkBoxStatus))
pCheckBox->check();
else
pCheckBox->uncheck();




Also a general callback with the name "changed"  it would be a good idea.

thank you


texus

Can't you just call the connect function after reading the data?

It's a bit more verbose than "changed", but you can do the following:
Code (cpp) Select
pCheckBox->connect("Checked Unchecked", [=](bool) {});

The bool parameter is optional, you can still use a function without parameters if you don't care about the new state.

billarhos

Didn't know or think both of them. Thank you Texus.