Skip to content

Commit

Permalink
feat(msgbox): add function to get selected button index (#2538)
Browse files Browse the repository at this point in the history
This adds a new function lv_msgbox_get_active_btn that works analogously
to lv_msgbox_get_active_btn_text but returns the button index instead of
its text.

The index is more convenient for comparison in localized applications as
it doesn't depend on the current language.
  • Loading branch information
Johennes committed Sep 9, 2021
1 parent 32e8276 commit 52dac2b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Expand Up @@ -29,6 +29,7 @@
- fix(examples) don't compile assets unless needed
- docs(all) Proofread, fix typos and add clarifications in confusing areas
- fix(zoom) multiplication overflow with zoom calculations on 16-bit platforms
- feat(msgbox): add function to get selected button index

## v8.0.2 (16.07.2021)
- fix(theme) improve button focus of keyboard
Expand Down
2 changes: 1 addition & 1 deletion docs/widgets/extra/msgbox.md
Expand Up @@ -43,7 +43,7 @@ lv_obj_t * lv_msgbox_get_btns(lv_obj_t * mbox);
## Events
- `LV_EVENT_VALUE_CHANGED` is sent by the buttons if one of them is clicked. `LV_OBJ_FLAG_EVENT_BUBBLE` is enabled on the buttons so you can add events to the message box itself.
In the event handler, `lv_event_get_target(e)` will return the button matrix and `lv_event_get_current_target(e)` will givreturn the message box. `lv_msgbox_get_active_btn_text(msgbox)` can be used to get the text of the clicked button.
In the event handler, `lv_event_get_target(e)` will return the button matrix and `lv_event_get_current_target(e)` will return the message box. `lv_msgbox_get_active_btn(msgbox)` and `lv_msgbox_get_active_btn_text(msgbox)` can be used to get the index and text of the clicked button.
Learn more about [Events](/overview/event).
Expand Down
6 changes: 6 additions & 0 deletions src/extra/widgets/msgbox/lv_msgbox.c
Expand Up @@ -130,6 +130,12 @@ lv_obj_t * lv_msgbox_get_btns(lv_obj_t * obj)
return mbox->btns;
}

uint16_t lv_msgbox_get_active_btn(lv_obj_t * mbox)
{
lv_obj_t * btnm = lv_msgbox_get_btns(mbox);
return lv_btnmatrix_get_selected_btn(btnm);
}

const char * lv_msgbox_get_active_btn_text(lv_obj_t * mbox)
{
lv_obj_t * btnm = lv_msgbox_get_btns(mbox);
Expand Down
7 changes: 7 additions & 0 deletions src/extra/widgets/msgbox/lv_msgbox.h
Expand Up @@ -67,6 +67,13 @@ lv_obj_t * lv_msgbox_get_text(lv_obj_t * obj);

lv_obj_t * lv_msgbox_get_btns(lv_obj_t * obj);

/**
* Get the index of the selected button
* @param mbox message box object
* @return index of the button (LV_BTNMATRIX_BTN_NONE: if unset)
*/
uint16_t lv_msgbox_get_active_btn(lv_obj_t * mbox);

const char * lv_msgbox_get_active_btn_text(lv_obj_t * mbox);

void lv_msgbox_close(lv_obj_t * mbox);
Expand Down

0 comments on commit 52dac2b

Please sign in to comment.