How can i make this label change according to the switches state?

What do you want to achieve?

i want to create a switch for an led with a label that changes according to the switches state

What have you tried so far?

i added an event that changes the “off” label to on when i click on the switch, but i cant seem to be able change it back to off when i click the switch again, ive attached a screen capture of the problem.

Screenshot or video

Others

  • **SquareLine Studio version:1.4.0
  • **Operating system:windows 11

You should select the SET TEXT VALUE WHEN CHECKED action for the event in SquareLine Studio, where you can set the ON/OFF texts for the label.

1 Like
void Switch_Changed(lv_event_t *e)
{
	bool checked = lv_obj_has_state(ui_Switch, LV_STATE_CHECKED);
	if (checked)
		lv_label_set_text(ui_Label, "On");
	else
		lv_label_set_text(ui_Label, "Off");
}
1 Like