Checkbox future improvments
« on: 30 December 2018, 12:29:32 »
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.

Code: [Select]
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

  • *****
  • 1334
    • View Profile
    • Texus's Blog
Re: Checkbox future improvments
« Reply #1 on: 30 December 2018, 12:38:39 »
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:
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.

Re: Checkbox future improvments
« Reply #2 on: 30 December 2018, 13:14:27 »
Didn't know or think both of them. Thank you Texus.