From 2d088c5f3df062b703da7da093a5808ffec9ee2d Mon Sep 17 00:00:00 2001 From: Mounir Tohami <53877170+WhalesState@users.noreply.github.com> Date: Thu, 17 Oct 2024 21:06:42 +0300 Subject: [PATCH 1/2] Fix `BottomPanel` excessive width. --- editor/gui/editor_bottom_panel.cpp | 72 +++++++++++++++++++++++++++++- editor/gui/editor_bottom_panel.h | 7 +++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/editor/gui/editor_bottom_panel.cpp b/editor/gui/editor_bottom_panel.cpp index 3cb95a392677..d742fc323ecb 100644 --- a/editor/gui/editor_bottom_panel.cpp +++ b/editor/gui/editor_bottom_panel.cpp @@ -43,6 +43,7 @@ #include "scene/gui/box_container.h" #include "scene/gui/button.h" #include "scene/gui/link_button.h" +#include "scene/gui/scroll_container.h" // The metadata key used to store and retrieve the version text to copy to the clipboard. static const String META_TEXT_TO_COPY = "text_to_copy"; @@ -51,6 +52,19 @@ void EditorBottomPanel::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: { expand_button->set_icon(get_editor_theme_icon(SNAME("ExpandBottomDock"))); + left_button->set_icon(get_editor_theme_icon(SNAME("Back"))); + right_button->set_icon(get_editor_theme_icon(SNAME("Forward"))); + } break; + + case NOTIFICATION_TRANSLATION_CHANGED: + case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: { + if (is_layout_rtl()) { + bottom_hbox->move_child(left_button, button_scroll->get_index() + 1); + bottom_hbox->move_child(right_button, 0); + } else { + bottom_hbox->move_child(right_button, button_scroll->get_index() + 1); + bottom_hbox->move_child(left_button, 0); + } } break; } } @@ -64,6 +78,33 @@ void EditorBottomPanel::_switch_by_control(bool p_visible, Control *p_control) { } } +void EditorBottomPanel::_scroll(bool p_right) { + HScrollBar *h_scroll = button_scroll->get_h_scroll_bar(); + if (Input::get_singleton()->is_key_pressed(Key::CTRL)) { + h_scroll->set_value(p_right ? h_scroll->get_max() : 0); + } else if (Input::get_singleton()->is_key_pressed(Key::SHIFT)) { + h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * (p_right ? 1 : -1)); + } else { + h_scroll->set_value(h_scroll->get_value() + (h_scroll->get_page() * 0.5) * (p_right ? 1 : -1)); + } +} + +void EditorBottomPanel::_update_scroll_buttons() { + bool show_arrows = button_hbox->get_size().width > button_scroll->get_size().width; + left_button->set_visible(show_arrows); + right_button->set_visible(show_arrows); + + if (show_arrows) { + _update_disabled_buttons(); + } +} + +void EditorBottomPanel::_update_disabled_buttons() { + HScrollBar *h_scroll = button_scroll->get_h_scroll_bar(); + left_button->set_disabled(h_scroll->get_value() == 0); + right_button->set_disabled(h_scroll->get_value() + h_scroll->get_page() == h_scroll->get_max()); +} + void EditorBottomPanel::_switch_to_item(bool p_visible, int p_idx) { ERR_FAIL_INDEX(p_idx, items.size()); @@ -91,6 +132,7 @@ void EditorBottomPanel::_switch_to_item(bool p_visible, int p_idx) { EditorNode::get_top_split()->hide(); } expand_button->show(); + button_scroll->ensure_control_visible(items[p_idx].button); } else { add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SNAME("BottomPanel"), EditorStringName(EditorStyles))); items[p_idx].button->set_pressed_no_signal(false); @@ -255,9 +297,35 @@ EditorBottomPanel::EditorBottomPanel() { bottom_hbox->set_custom_minimum_size(Size2(0, 24 * EDSCALE)); // Adjust for the height of the "Expand Bottom Dock" icon. item_vbox->add_child(bottom_hbox); + left_button = memnew(Button); + left_button->set_tooltip_text(TTR("Scroll Left\nHold Ctrl to scroll to the begining.\nHold Shift to scroll one page.")); + left_button->set_theme_type_variation("BottomPanelButton"); + left_button->set_focus_mode(Control::FOCUS_NONE); + left_button->connect(SceneStringName(pressed), callable_mp(this, &EditorBottomPanel::_scroll).bind(false)); + bottom_hbox->add_child(left_button); + left_button->hide(); + + button_scroll = memnew(ScrollContainer); + button_scroll->set_h_size_flags(Control::SIZE_EXPAND_FILL); + button_scroll->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_SHOW_NEVER); + button_scroll->set_vertical_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED); + button_scroll->get_h_scroll_bar()->connect(CoreStringName(changed), callable_mp(this, &EditorBottomPanel::_update_scroll_buttons), CONNECT_DEFERRED); + button_scroll->get_h_scroll_bar()->connect(SceneStringName(value_changed), callable_mp(this, &EditorBottomPanel::_update_disabled_buttons).unbind(1), CONNECT_DEFERRED); + bottom_hbox->add_child(button_scroll); + + right_button = memnew(Button); + right_button->set_tooltip_text(TTR("Scroll Right\nHold Ctrl to scroll to the end.\nHold Shift to scroll one page.")); + right_button->set_theme_type_variation("BottomPanelButton"); + right_button->set_focus_mode(Control::FOCUS_NONE); + right_button->connect(SceneStringName(pressed), callable_mp(this, &EditorBottomPanel::_scroll).bind(true)); + bottom_hbox->add_child(right_button); + right_button->hide(); + + callable_mp(this, &EditorBottomPanel::_update_scroll_buttons).call_deferred(); + button_hbox = memnew(HBoxContainer); - button_hbox->set_h_size_flags(Control::SIZE_EXPAND_FILL); - bottom_hbox->add_child(button_hbox); + button_hbox->set_h_size_flags(Control::SIZE_EXPAND | Control::SIZE_SHRINK_BEGIN); + button_scroll->add_child(button_hbox); editor_toaster = memnew(EditorToaster); bottom_hbox->add_child(editor_toaster); diff --git a/editor/gui/editor_bottom_panel.h b/editor/gui/editor_bottom_panel.h index 95c767dae5d8..e2e3bba6d808 100644 --- a/editor/gui/editor_bottom_panel.h +++ b/editor/gui/editor_bottom_panel.h @@ -39,6 +39,7 @@ class EditorToaster; class HBoxContainer; class LinkButton; class VBoxContainer; +class ScrollContainer; class EditorBottomPanel : public PanelContainer { GDCLASS(EditorBottomPanel, PanelContainer); @@ -53,6 +54,9 @@ class EditorBottomPanel : public PanelContainer { VBoxContainer *item_vbox = nullptr; HBoxContainer *bottom_hbox = nullptr; + Button *left_button = nullptr; + Button *right_button = nullptr; + ScrollContainer *button_scroll = nullptr; HBoxContainer *button_hbox = nullptr; EditorToaster *editor_toaster = nullptr; LinkButton *version_btn = nullptr; @@ -63,6 +67,9 @@ class EditorBottomPanel : public PanelContainer { void _switch_to_item(bool p_visible, int p_idx); void _expand_button_toggled(bool p_pressed); void _version_button_pressed(); + void _scroll(bool p_right); + void _update_scroll_buttons(); + void _update_disabled_buttons(); bool _button_drag_hover(const Vector2 &, const Variant &, Button *p_button, Control *p_control); From 8a5253979483641d82cc225038ab50994baf1c56 Mon Sep 17 00:00:00 2001 From: Aaron Benjamin Date: Thu, 17 Oct 2024 22:23:34 -0400 Subject: [PATCH 2/2] Spell Check Signed-off-by: Aaron Benjamin --- editor/gui/editor_bottom_panel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editor/gui/editor_bottom_panel.cpp b/editor/gui/editor_bottom_panel.cpp index d742fc323ecb..576dbaf3ba26 100644 --- a/editor/gui/editor_bottom_panel.cpp +++ b/editor/gui/editor_bottom_panel.cpp @@ -298,7 +298,7 @@ EditorBottomPanel::EditorBottomPanel() { item_vbox->add_child(bottom_hbox); left_button = memnew(Button); - left_button->set_tooltip_text(TTR("Scroll Left\nHold Ctrl to scroll to the begining.\nHold Shift to scroll one page.")); + left_button->set_tooltip_text(TTR("Scroll Left\nHold Ctrl to scroll to the beginning.\nHold Shift to scroll one page.")); left_button->set_theme_type_variation("BottomPanelButton"); left_button->set_focus_mode(Control::FOCUS_NONE); left_button->connect(SceneStringName(pressed), callable_mp(this, &EditorBottomPanel::_scroll).bind(false));