diff options
author | Jylhis <markus@jylhis.com> | 2017-04-14 14:49:00 +0300 |
---|---|---|
committer | Jylhis <markus@jylhis.com> | 2017-04-14 15:00:38 +0300 |
commit | 8ccb9d13c31e3dc2a7bad00edb3676e45f16b05e (patch) | |
tree | 966b1daa128522c34edf29a59403df1b1b72526c | |
parent | a96e795241aaa512e11b1c2085db2c955200ad40 (diff) |
Update PopupMenu hiding
Make PopupMenu hiding distinguish between checkable item and non checkable
item.
-rw-r--r-- | doc/base/classes.xml | 14 | ||||
-rw-r--r-- | scene/gui/popup_menu.cpp | 21 | ||||
-rw-r--r-- | scene/gui/popup_menu.h | 4 |
3 files changed, 36 insertions, 3 deletions
diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 7f9bb4a972..67930af368 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -34517,6 +34517,13 @@ Returns a boolean that indicates whether or not the PopupMenu will hide on item selection. </description> </method> + <method name="is_hide_on_checkable_item_selection"> + <return type="bool"> + </return> + <description> + Returns a boolean that indicates whether or not the PopupMenu will hide on checkable item selection. + </description> + </method> <method name="is_item_checkable" qualifiers="const"> <return type="bool"> </return> @@ -34567,6 +34574,13 @@ Sets whether or not the PopupMenu will hide on item selection. </description> </method> + <method name="set_hide_on_checkable_item_selection"> + <argument index="0" name="enable" type="bool"> + </argument> + <description> + Sets whether or not the PopupMenu will hide on checkable item selection. + </description> + </method> <method name="set_item_ID"> <argument index="0" name="idx" type="int"> </argument> diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 6ac6eac655..f683d7b428 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -878,7 +878,7 @@ void PopupMenu::activate_item(int p_item) { while (pop) { // We close all parents that are chained together, // with hide_on_item_selection enabled - if (hide_on_item_selection && pop->is_hide_on_item_selection()) { + if ((items[p_item].checkable && hide_on_checkable_item_selection && pop->is_hide_on_checkable_item_selection()) || (!items[p_item].checkable && hide_on_item_selection && pop->is_hide_on_item_selection())) { pop->hide(); next = next->get_parent(); pop = next->cast_to<PopupMenu>(); @@ -889,8 +889,8 @@ void PopupMenu::activate_item(int p_item) { } } // Hides popup by default; unless otherwise specified - // by using set_hide_on_item_selection - if (hide_on_item_selection) { + // by using set_hide_on_item_selection and set_hide_on_checkable_item_selection + if ((items[p_item].checkable && hide_on_checkable_item_selection) || (!items[p_item].checkable && hide_on_item_selection)) { hide(); } } @@ -1013,6 +1013,16 @@ bool PopupMenu::is_hide_on_item_selection() { return hide_on_item_selection; } +void PopupMenu::set_hide_on_checkable_item_selection(bool p_enabled) { + + hide_on_checkable_item_selection = p_enabled; +} + +bool PopupMenu::is_hide_on_checkable_item_selection() { + + return hide_on_checkable_item_selection; +} + String PopupMenu::get_tooltip(const Point2 &p_pos) const { int over = _get_mouse_over(p_pos); @@ -1101,10 +1111,14 @@ void PopupMenu::_bind_methods() { ClassDB::bind_method(D_METHOD("set_hide_on_item_selection", "enable"), &PopupMenu::set_hide_on_item_selection); ClassDB::bind_method(D_METHOD("is_hide_on_item_selection"), &PopupMenu::is_hide_on_item_selection); + ClassDB::bind_method(D_METHOD("set_hide_on_checkable_item_selection", "enable"), &PopupMenu::set_hide_on_checkable_item_selection); + ClassDB::bind_method(D_METHOD("is_hide_on_checkable_item_selection"), &PopupMenu::is_hide_on_checkable_item_selection); + ClassDB::bind_method(D_METHOD("_submenu_timeout"), &PopupMenu::_submenu_timeout); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_items", "_get_items"); ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "hide_on_item_selection"), "set_hide_on_item_selection", "is_hide_on_item_selection"); + ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "hide_on_checkable_item_selection"), "set_hide_on_checkable_item_selection", "is_hide_on_checkable_item_selection"); ADD_SIGNAL(MethodInfo("id_pressed", PropertyInfo(Variant::INT, "ID"))); ADD_SIGNAL(MethodInfo("index_pressed", PropertyInfo(Variant::INT, "index"))); @@ -1122,6 +1136,7 @@ PopupMenu::PopupMenu() { set_focus_mode(FOCUS_ALL); set_as_toplevel(true); set_hide_on_item_selection(true); + set_hide_on_checkable_item_selection(true); submenu_timer = memnew(Timer); submenu_timer->set_wait_time(0.3); diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index de809f29d3..7cd5f3b98b 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -85,6 +85,7 @@ class PopupMenu : public Popup { bool invalidated_click; bool hide_on_item_selection; + bool hide_on_checkable_item_selection; Vector2 moved; Array _get_items() const; @@ -168,6 +169,9 @@ public: void set_hide_on_item_selection(bool p_enabled); bool is_hide_on_item_selection(); + void set_hide_on_checkable_item_selection(bool p_enabled); + bool is_hide_on_checkable_item_selection(); + PopupMenu(); ~PopupMenu(); }; |