From ae223e23a031396a299edaa10d251d6c78501708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gilles=20Roudi=C3=A8re?= Date: Tue, 17 Jan 2023 15:40:50 +0100 Subject: [PATCH] Limit toasts' width --- editor/editor_toaster.cpp | 55 +++++++++++++++++++++++++++++---------- editor/editor_toaster.h | 2 ++ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/editor/editor_toaster.cpp b/editor/editor_toaster.cpp index dd5d68a08ee..558423df78e 100644 --- a/editor/editor_toaster.cpp +++ b/editor/editor_toaster.cpp @@ -90,11 +90,12 @@ void EditorToaster::_notification(int p_what) { } // Hide element if it is not visible anymore. - if (modulate_fade.a <= 0) { - if (element.key->is_visible()) { - element.key->hide(); - needs_update = true; - } + if (modulate_fade.a <= 0 && element.key->is_visible()) { + element.key->hide(); + needs_update = true; + } else if (modulate_fade.a >= 0 && !element.key->is_visible()) { + element.key->show(); + needs_update = true; } } @@ -419,12 +420,21 @@ void EditorToaster::_popup_str(String p_message, Severity p_severity, String p_t // Create a new message if needed. if (control == nullptr) { - Label *label = memnew(Label); + HBoxContainer *hb = memnew(HBoxContainer); + hb->add_theme_constant_override("separation", 0); - control = popup(label, p_severity, default_message_duration, p_tooltip); + Label *label = memnew(Label); + hb->add_child(label); + + Label *count_label = memnew(Label); + hb->add_child(count_label); + + control = popup(hb, p_severity, default_message_duration, p_tooltip); toasts[control].message = p_message; toasts[control].tooltip = p_tooltip; toasts[control].count = 1; + toasts[control].message_label = label; + toasts[control].message_count_label = count_label; } else { if (toasts[control].popped) { toasts[control].count += 1; @@ -441,14 +451,31 @@ void EditorToaster::_popup_str(String p_message, Severity p_severity, String p_t main_button->queue_redraw(); } - // Retrieve the label back then update the text. - Label *label = Object::cast_to