What do you want to achieve?
I have , at the moment, a simple button on a matouch 1.28 touch, that when pressed turns the relay on for what ever time was determend by the user. The button is green when released, and red when pressed/clicked. I want the button to stay red while the relay/timmer is running
I had this
void btnRelay_event_handler(lv_event_t * e) { lv_event_code_t code = lv_event_get_code(e); if (code == LV_EVENT_CLICKED && !relayActive) { // 1. Turn button red lv_obj_set_style_bg_color(ui_Button1, lv_color_hex(0xFF0000), LV_PART_MAIN);
Any help would be greatly appreciated
Hi, regarding your question, the recommended solution is to use a custom state for the button.
First, in SquareLine Studio, select your button. Go to its Styles properties and add a style definition specifically for the USER_1 state. In the properties for this new state (MAIN PART), set the Background Color to red (0xFF0000).
Once you have defined this style in the Studio, you will only need to control when this state is active from your code.
In your btnRelay_event_handler, when the LV_EVENT_CLICKED code is received and you activate the relay, you should add the custom state to the button (e.g., using lv_obj_add_state(ui_Button1, LV_STATE_USER_1)). As long as the button has this USER_1 state, the style you defined in SquareLine Studio will keep it red.
Once your timer has completed, simply remove that custom state (e.g., using lv_obj_clear_state(ui_Button1, LV_STATE_USER_1)). This will automatically revert the button to its default (green) appearance.
We hope this helps you achieve the desired behavior.