Skip to content
Discussion options

You must be logged in to vote

Hi, you can use assign ITEM_WIDGET directly to variable:

int brightness;
void brightness_callback(const int& value);
ItemWidget<int>* widget_ptr = ITEM_WIDGET(
                "Brightness", nullptr,
                WIDGET_RANGE(brightness, 16, 0, 256, "%u", 0, true, brightness_callback));

MENU_SCREEN(main_screen, main_items,
            widget_ptr);

void setup() {
  brightness = 128;
  // ...
  // no need this:
  // widget_ptr = static_cast<ItemWidget<int>*>(main_screen->getItemAt(0));
  widget_ptr->setValues(brightness);
  menu.refresh();
}

Also note that both Item and Widget have callbacks and for this example they have same signature and may be confising.
The item's callback behaves as

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ShishkinDmitriy
Comment options

Answer selected by forntoh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants