diff options
Diffstat (limited to 'scene/gui/dialogs.cpp')
-rw-r--r-- | scene/gui/dialogs.cpp | 72 |
1 files changed, 49 insertions, 23 deletions
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 3746b667f6..3d8be38fbd 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -47,7 +47,7 @@ void AcceptDialog::_input_from_window(const Ref<InputEvent> &p_event) { } void AcceptDialog::_parent_focused() { - if (!is_exclusive() && get_flag(FLAG_POPUP)) { + if (popped_up && !is_exclusive() && get_flag(FLAG_POPUP)) { _cancel_pressed(); } } @@ -68,16 +68,25 @@ void AcceptDialog::_notification(int p_what) { parent_visible = get_parent_visible_window(); if (parent_visible) { - parent_visible->connect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible->connect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused)); } } else { + popped_up = false; if (parent_visible) { - parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible->disconnect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused)); parent_visible = nullptr; } } } break; + case NOTIFICATION_WM_WINDOW_FOCUS_IN: { + if (!is_in_edited_scene_root()) { + if (has_focus()) { + popped_up = true; + } + } + } break; + case NOTIFICATION_THEME_CHANGED: { bg_panel->add_theme_style_override("panel", theme_cache.panel_style); @@ -89,7 +98,7 @@ void AcceptDialog::_notification(int p_what) { case NOTIFICATION_EXIT_TREE: { if (parent_visible) { - parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible->disconnect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused)); parent_visible = nullptr; } } break; @@ -114,8 +123,14 @@ void AcceptDialog::_text_submitted(const String &p_text) { _ok_pressed(); } +void AcceptDialog::_post_popup() { + Window::_post_popup(); + popped_up = true; +} + void AcceptDialog::_ok_pressed() { if (hide_on_ok) { + popped_up = false; set_visible(false); } ok_pressed(); @@ -124,9 +139,10 @@ void AcceptDialog::_ok_pressed() { } void AcceptDialog::_cancel_pressed() { + popped_up = false; Window *parent_window = parent_visible; if (parent_visible) { - parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible->disconnect(SceneStringName(focus_entered), callable_mp(this, &AcceptDialog::_parent_focused)); parent_visible = nullptr; } @@ -202,7 +218,7 @@ void AcceptDialog::register_text_enter(LineEdit *p_line_edit) { } void AcceptDialog::_update_child_rects() { - Size2 dlg_size = get_size(); + Size2 dlg_size = Vector2(get_size()) / get_content_scale_factor(); float h_margins = theme_cache.panel_style->get_margin(SIDE_LEFT) + theme_cache.panel_style->get_margin(SIDE_RIGHT); float v_margins = theme_cache.panel_style->get_margin(SIDE_TOP) + theme_cache.panel_style->get_margin(SIDE_BOTTOM); @@ -210,6 +226,15 @@ void AcceptDialog::_update_child_rects() { bg_panel->set_position(Point2()); bg_panel->set_size(dlg_size); + for (int i = 0; i < buttons_hbox->get_child_count(); i++) { + Button *b = Object::cast_to<Button>(buttons_hbox->get_child(i)); + if (!b) { + continue; + } + + b->set_custom_minimum_size(Size2(theme_cache.buttons_min_width, theme_cache.buttons_min_height)); + } + // Place the buttons from the bottom edge to their minimum required size. Size2 buttons_minsize = buttons_hbox->get_combined_minimum_size(); Size2 buttons_size = Size2(dlg_size.x - h_margins, buttons_minsize.y); @@ -252,14 +277,7 @@ Size2 AcceptDialog::_get_contents_minimum_size() const { } Size2 child_minsize = c->get_combined_minimum_size(); - content_minsize.x = MAX(child_minsize.x, content_minsize.x); - content_minsize.y = MAX(child_minsize.y, content_minsize.y); - } - - // Then we take the background panel as it provides the offsets, - // which are always added to the minimum size. - if (theme_cache.panel_style.is_valid()) { - content_minsize += theme_cache.panel_style->get_minimum_size(); + content_minsize = child_minsize.max(content_minsize); } // Then we add buttons. Horizontally we're interested in whichever @@ -270,6 +288,12 @@ Size2 AcceptDialog::_get_contents_minimum_size() const { // Plus there is a separation size added on top. content_minsize.y += theme_cache.buttons_separation; + // Then we take the background panel as it provides the offsets, + // which are always added to the minimum size. + if (theme_cache.panel_style.is_valid()) { + content_minsize += theme_cache.panel_style->get_minimum_size(); + } + return content_minsize; } @@ -300,7 +324,7 @@ Button *AcceptDialog::add_button(const String &p_text, bool p_right, const Strin } button->set_meta("__right_spacer", right_spacer); - button->connect("visibility_changed", callable_mp(this, &AcceptDialog::_custom_button_visibility_changed).bind(button)); + button->connect(SceneStringName(visibility_changed), callable_mp(this, &AcceptDialog::_custom_button_visibility_changed).bind(button)); child_controls_changed(); if (is_visible()) { @@ -308,7 +332,7 @@ Button *AcceptDialog::add_button(const String &p_text, bool p_right, const Strin } if (!p_action.is_empty()) { - button->connect("pressed", callable_mp(this, &AcceptDialog::_custom_action).bind(p_action)); + button->connect(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_custom_action).bind(p_action)); } return button; @@ -322,7 +346,7 @@ Button *AcceptDialog::add_cancel_button(const String &p_cancel) { Button *b = swap_cancel_ok ? add_button(c, true) : add_button(c); - b->connect("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed)); + b->connect(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_cancel_pressed)); return b; } @@ -337,12 +361,12 @@ void AcceptDialog::remove_button(Button *p_button) { ERR_FAIL_COND_MSG(right_spacer->get_parent() != buttons_hbox, vformat("Cannot remove button %s as its associated spacer does not belong to this dialog.", p_button->get_name())); } - p_button->disconnect("visibility_changed", callable_mp(this, &AcceptDialog::_custom_button_visibility_changed)); - if (p_button->is_connected("pressed", callable_mp(this, &AcceptDialog::_custom_action))) { - p_button->disconnect("pressed", callable_mp(this, &AcceptDialog::_custom_action)); + p_button->disconnect(SceneStringName(visibility_changed), callable_mp(this, &AcceptDialog::_custom_button_visibility_changed)); + if (p_button->is_connected(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_custom_action))) { + p_button->disconnect(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_custom_action)); } - if (p_button->is_connected("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed))) { - p_button->disconnect("pressed", callable_mp(this, &AcceptDialog::_cancel_pressed)); + if (p_button->is_connected(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_cancel_pressed))) { + p_button->disconnect(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_cancel_pressed)); } if (right_spacer) { @@ -390,6 +414,8 @@ void AcceptDialog::_bind_methods() { BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, AcceptDialog, panel_style, "panel"); BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, AcceptDialog, buttons_separation); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, AcceptDialog, buttons_min_width); + BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, AcceptDialog, buttons_min_height); } bool AcceptDialog::swap_cancel_ok = false; @@ -423,7 +449,7 @@ AcceptDialog::AcceptDialog() { buttons_hbox->add_child(ok_button); buttons_hbox->add_spacer(); - ok_button->connect("pressed", callable_mp(this, &AcceptDialog::_ok_pressed)); + ok_button->connect(SceneStringName(pressed), callable_mp(this, &AcceptDialog::_ok_pressed)); set_title(ETR("Alert!")); } |