diff options
author | Ricardo Buring <ricardo.buring@gmail.com> | 2020-10-16 01:04:30 +0200 |
---|---|---|
committer | Ricardo Buring <ricardo.buring@gmail.com> | 2022-01-15 22:52:12 +0100 |
commit | 4562106cbf1bbb7ae86a49fdee2ba9eeb69bd15e (patch) | |
tree | 03d2cddce5d083eb800ec64e6e127cdc14e3bcf7 /scene | |
parent | c99c5a1caeafab161daebdde21ccd83ecdc897d5 (diff) |
OptionButton::pressed(): give focus to selected
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/option_button.cpp | 1 | ||||
-rw-r--r-- | scene/gui/popup_menu.cpp | 7 | ||||
-rw-r--r-- | scene/gui/popup_menu.h | 1 |
3 files changed, 9 insertions, 0 deletions
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index e955fde43a..90bb316448 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -179,6 +179,7 @@ void OptionButton::pressed() { Size2 size = get_size() * get_viewport()->get_canvas_transform().get_scale(); popup->set_position(get_screen_position() + Size2(0, size.height * get_global_transform().get_scale().y)); popup->set_size(Size2(size.width, 0)); + popup->set_current_index(current); popup->popup(); } diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index f4d45fe1fa..d7139d0140 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -1269,6 +1269,13 @@ bool PopupMenu::is_item_shortcut_disabled(int p_idx) const { return items[p_idx].shortcut_is_disabled; } +void PopupMenu::set_current_index(int p_idx) { + ERR_FAIL_INDEX(p_idx, items.size()); + mouse_over = p_idx; + _scroll_to_item(mouse_over); + control->update(); +} + int PopupMenu::get_current_index() const { return mouse_over; } diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index 5d6b75cbf5..7c2212d82d 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -212,6 +212,7 @@ public: Ref<Shortcut> get_item_shortcut(int p_idx) const; int get_item_state(int p_idx) const; + void set_current_index(int p_idx); int get_current_index() const; void set_item_count(int p_count); |