Button Events Triggering unused variable 'target' error

What do you want to achieve?

Working Buttons for an ESP32S Screen, change to screen2

What have you tried so far?

GPT says that this modification will fix the errors.
It does however each time you export UI in SquareLine, even to adjust text position it rewrites the entire UI.C file, removing our fix making me do it each and every time I export UI.
Fixed Code

void ui_event_Button1(lv_event_t * e) {
    lv_event_code_t event_code = lv_event_get_code(e);
    if (event_code == LV_EVENT_CLICKED) {
        _ui_screen_change(&ui_SettingScreen, LV_SCR_LOAD_ANIM_NONE, 1, 0, &ui_SettingScreen_screen_init);
    }
}

Arduino IDE Error log.
/Users//Documents/Arduino1/Fireplacebackupspj/libraries/ui/src/ui.c: In function 'ui_event_Button1': /Users/gabe/Documents/Arduino1/Fireplacebackupspj/libraries/ui/src/ui.c:127:66: error: unused variable 'target' [-Werror=unused-variable] lv_event_code_t event_code = lv_event_get_code(e);lv_obj_t * target = lv_event_get_target(e);

Squareline UI.C button Code:

void ui_event_Button1( lv_event_t * e) {
    lv_event_code_t event_code = lv_event_get_code(e);lv_obj_t * target = lv_event_get_target(e);
if ( event_code == LV_EVENT_CLICKED) {
      _ui_screen_change( &ui_SettingScreen, LV_SCR_LOAD_ANIM_NONE, 1, 0, &ui_SettingScreen_screen_init);
}

Screenshot or video

Others

  • SquareLine Studio version:
  • Operating system:
  • Target hardware:

Compilers generally shouldn’t give error, just warning, if there’s a declared but unused variable, as it shouldn’t cause any problems and would be optimized away by the compiler. But we know some compilers and programmers prefer this very strict approach, so we’ll check if we can disable this prepared ‘target’ variable in the export when it’s not really needed. Thanks for the feedback.


Can you see any options that may be missing?
I belive I have all required elements filled out. So I am unsure why it thinks the target is missing.

You’re not missing anything. The ‘target’ internal variable of the callback function could be used when for example you need to check the value/state of the widget, but since it’s a simple ‘CLICKED’ trigger there’s no need for that, no code is generated that uses ‘target’, but unfortunately the variable ‘target’ is still prepared by the exported code and is not liked by your compiler. What you can do now is adding the ‘-Wno-unused-variable’ or ‘-Wno-unused’ flags to your compiler settings, after ‘-Wall’ or ‘-Wextra’ flags if they’re there. That way you’ll only get a warning and your code will hopefully compile fine.

1 Like