You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Merge pull request #8407 from Jylhis/popup_item_select_hide
Update PopupMenu hiding
This commit is contained in:
@@ -34724,6 +34724,13 @@
|
|||||||
Returns a boolean that indicates whether or not the PopupMenu will hide on item selection.
|
Returns a boolean that indicates whether or not the PopupMenu will hide on item selection.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</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">
|
<method name="is_item_checkable" qualifiers="const">
|
||||||
<return type="bool">
|
<return type="bool">
|
||||||
</return>
|
</return>
|
||||||
@@ -34774,6 +34781,13 @@
|
|||||||
Sets whether or not the PopupMenu will hide on item selection.
|
Sets whether or not the PopupMenu will hide on item selection.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</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">
|
<method name="set_item_ID">
|
||||||
<argument index="0" name="idx" type="int">
|
<argument index="0" name="idx" type="int">
|
||||||
</argument>
|
</argument>
|
||||||
|
|||||||
@@ -3270,6 +3270,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
|
|||||||
|
|
||||||
PopupMenu *p;
|
PopupMenu *p;
|
||||||
p = edit_menu->get_popup();
|
p = edit_menu->get_popup();
|
||||||
|
p->set_hide_on_checkable_item_selection(false);
|
||||||
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_snap", TTR("Use Snap")), SNAP_USE);
|
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_snap", TTR("Use Snap")), SNAP_USE);
|
||||||
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_grid", TTR("Show Grid")), SNAP_SHOW_GRID);
|
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_grid", TTR("Show Grid")), SNAP_SHOW_GRID);
|
||||||
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_rotation_snap", TTR("Use Rotation Snap")), SNAP_USE_ROTATION);
|
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_rotation_snap", TTR("Use Rotation Snap")), SNAP_USE_ROTATION);
|
||||||
@@ -3291,6 +3292,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
|
|||||||
skeleton_menu->add_separator();
|
skeleton_menu->add_separator();
|
||||||
skeleton_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_set_ik_chain", TTR("Make IK Chain")), SKELETON_SET_IK_CHAIN);
|
skeleton_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_set_ik_chain", TTR("Make IK Chain")), SKELETON_SET_IK_CHAIN);
|
||||||
skeleton_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_clear_ik_chain", TTR("Clear IK Chain")), SKELETON_CLEAR_IK_CHAIN);
|
skeleton_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/skeleton_clear_ik_chain", TTR("Clear IK Chain")), SKELETON_CLEAR_IK_CHAIN);
|
||||||
|
skeleton_menu->set_hide_on_checkable_item_selection(false);
|
||||||
skeleton_menu->connect("id_pressed", this, "_popup_callback");
|
skeleton_menu->connect("id_pressed", this, "_popup_callback");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -792,6 +792,7 @@ TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) {
|
|||||||
hb_tools->add_child(snap_mode_button);
|
hb_tools->add_child(snap_mode_button);
|
||||||
snap_mode_button->set_text(TTR("<None>"));
|
snap_mode_button->set_text(TTR("<None>"));
|
||||||
PopupMenu *p = snap_mode_button->get_popup();
|
PopupMenu *p = snap_mode_button->get_popup();
|
||||||
|
p->set_hide_on_checkable_item_selection(false);
|
||||||
p->add_item(TTR("<None>"), 0);
|
p->add_item(TTR("<None>"), 0);
|
||||||
p->add_item(TTR("Pixel Snap"), 1);
|
p->add_item(TTR("Pixel Snap"), 1);
|
||||||
p->add_item(TTR("Grid Snap"), 2);
|
p->add_item(TTR("Grid Snap"), 2);
|
||||||
|
|||||||
@@ -884,7 +884,7 @@ void PopupMenu::activate_item(int p_item) {
|
|||||||
while (pop) {
|
while (pop) {
|
||||||
// We close all parents that are chained together,
|
// We close all parents that are chained together,
|
||||||
// with hide_on_item_selection enabled
|
// 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();
|
pop->hide();
|
||||||
next = next->get_parent();
|
next = next->get_parent();
|
||||||
pop = next->cast_to<PopupMenu>();
|
pop = next->cast_to<PopupMenu>();
|
||||||
@@ -895,8 +895,8 @@ void PopupMenu::activate_item(int p_item) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Hides popup by default; unless otherwise specified
|
// Hides popup by default; unless otherwise specified
|
||||||
// by using set_hide_on_item_selection
|
// by using set_hide_on_item_selection and set_hide_on_checkable_item_selection
|
||||||
if (hide_on_item_selection) {
|
if ((items[p_item].checkable && hide_on_checkable_item_selection) || (!items[p_item].checkable && hide_on_item_selection)) {
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1019,6 +1019,16 @@ bool PopupMenu::is_hide_on_item_selection() {
|
|||||||
return 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 {
|
String PopupMenu::get_tooltip(const Point2 &p_pos) const {
|
||||||
|
|
||||||
int over = _get_mouse_over(p_pos);
|
int over = _get_mouse_over(p_pos);
|
||||||
@@ -1107,10 +1117,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("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("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);
|
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_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_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("id_pressed", PropertyInfo(Variant::INT, "ID")));
|
||||||
ADD_SIGNAL(MethodInfo("index_pressed", PropertyInfo(Variant::INT, "index")));
|
ADD_SIGNAL(MethodInfo("index_pressed", PropertyInfo(Variant::INT, "index")));
|
||||||
@@ -1128,6 +1142,7 @@ PopupMenu::PopupMenu() {
|
|||||||
set_focus_mode(FOCUS_ALL);
|
set_focus_mode(FOCUS_ALL);
|
||||||
set_as_toplevel(true);
|
set_as_toplevel(true);
|
||||||
set_hide_on_item_selection(true);
|
set_hide_on_item_selection(true);
|
||||||
|
set_hide_on_checkable_item_selection(true);
|
||||||
|
|
||||||
submenu_timer = memnew(Timer);
|
submenu_timer = memnew(Timer);
|
||||||
submenu_timer->set_wait_time(0.3);
|
submenu_timer->set_wait_time(0.3);
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ class PopupMenu : public Popup {
|
|||||||
|
|
||||||
bool invalidated_click;
|
bool invalidated_click;
|
||||||
bool hide_on_item_selection;
|
bool hide_on_item_selection;
|
||||||
|
bool hide_on_checkable_item_selection;
|
||||||
Vector2 moved;
|
Vector2 moved;
|
||||||
|
|
||||||
Array _get_items() const;
|
Array _get_items() const;
|
||||||
@@ -168,6 +169,9 @@ public:
|
|||||||
void set_hide_on_item_selection(bool p_enabled);
|
void set_hide_on_item_selection(bool p_enabled);
|
||||||
bool is_hide_on_item_selection();
|
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();
|
||||||
~PopupMenu();
|
~PopupMenu();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user