diff options
author | thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> | 2023-04-14 08:51:46 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-15 15:24:50 +0200 |
commit | aa94b944deaece5d970c5f822ba3ab80d2ef223f (patch) | |
tree | 22d2c368de342d72e7908ccf36d1e11ff3a1f622 /Userland | |
parent | ac2f1098f7fc93d85d726238e2b899e1cc2e19b9 (diff) | |
download | serenity-aa94b944deaece5d970c5f822ba3ab80d2ef223f.zip |
LibGUI: Allow Windows to auto shrink
Previously Windows automatically grew to accomodate layout changes
when obeying minimum widget size but would not automatically shrink
if so desired. Setting auto shrink true now automatically resizes
windows to their effective_min_size() every time their minimum size
updates. This will be useful for making fixed size windows responsive
to layout and font changes in the future.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGUI/Window.cpp | 32 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Window.h | 4 |
2 files changed, 27 insertions, 9 deletions
diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp index ef2da2f1cc..f5706a361c 100644 --- a/Userland/Libraries/LibGUI/Window.cpp +++ b/Userland/Libraries/LibGUI/Window.cpp @@ -615,6 +615,9 @@ void Window::handle_fonts_change_event(FontsChangeEvent& event) }); }; dispatch_fonts_change(*m_main_widget.ptr(), dispatch_fonts_change); + + if (is_auto_shrinking()) + schedule_relayout(); } void Window::handle_screen_rects_change_event(ScreenRectsChangeEvent& event) @@ -1096,6 +1099,14 @@ void Window::set_obey_widget_min_size(bool obey_widget_min_size) } } +void Window::set_auto_shrink(bool shrink) +{ + if (m_auto_shrink == shrink) + return; + m_auto_shrink = shrink; + schedule_relayout(); +} + void Window::set_maximized(bool maximized) { m_maximized = maximized; @@ -1119,16 +1130,19 @@ void Window::set_minimized(bool minimized) void Window::update_min_size() { - if (main_widget()) { - main_widget()->do_layout(); - if (m_obey_widget_min_size) { - auto min_size = main_widget()->effective_min_size(); - Gfx::IntSize size = { MUST(min_size.width().shrink_value()), MUST(min_size.height().shrink_value()) }; - m_minimum_size_when_windowless = size; - if (is_visible()) - ConnectionToWindowServer::the().async_set_window_minimum_size(m_window_id, size); - } + if (!main_widget()) + return; + main_widget()->do_layout(); + + auto min_size = main_widget()->effective_min_size(); + Gfx::IntSize size = { MUST(min_size.width().shrink_value()), MUST(min_size.height().shrink_value()) }; + if (is_obeying_widget_min_size()) { + m_minimum_size_when_windowless = size; + if (is_visible()) + ConnectionToWindowServer::the().async_set_window_minimum_size(m_window_id, size); } + if (is_auto_shrinking()) + resize(size); } void Window::schedule_relayout() diff --git a/Userland/Libraries/LibGUI/Window.h b/Userland/Libraries/LibGUI/Window.h index 41670a9753..e3f055bd68 100644 --- a/Userland/Libraries/LibGUI/Window.h +++ b/Userland/Libraries/LibGUI/Window.h @@ -63,6 +63,9 @@ public: bool is_obeying_widget_min_size() { return m_obey_widget_min_size; } void set_obey_widget_min_size(bool); + bool is_auto_shrinking() const { return m_auto_shrink; } + void set_auto_shrink(bool); + bool is_minimizable() const { return m_minimizable; } void set_minimizable(bool minimizable) { m_minimizable = minimizable; } @@ -321,6 +324,7 @@ private: bool m_moved_by_client { false }; bool m_blocks_emoji_input { false }; bool m_resizing { false }; + bool m_auto_shrink { false }; }; } |