From 2600669b7301899eae1660b8707c60e539fbbc78 Mon Sep 17 00:00:00 2001 From: FrHun <28605587+frhun@users.noreply.github.com> Date: Sun, 12 Jun 2022 22:18:52 +0200 Subject: [PATCH] LibGUI: Use preferred_size to emulate old is_shrink_to_fit --- Userland/Libraries/LibGUI/Widget.cpp | 9 ++++----- Userland/Libraries/LibGUI/Widget.h | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp index bbbeb1bf51..7f32b79e08 100644 --- a/Userland/Libraries/LibGUI/Widget.cpp +++ b/Userland/Libraries/LibGUI/Widget.cpp @@ -1193,12 +1193,11 @@ bool Widget::has_focus_within() const return window->focused_widget() == &effective_focus_widget || is_ancestor_of(*window->focused_widget()); } -void Widget::set_shrink_to_fit(bool b) +void Widget::set_shrink_to_fit(bool shrink_to_fit) { - if (m_shrink_to_fit == b) - return; - m_shrink_to_fit = b; - invalidate_layout(); + // This function is deprecated, and soon to be removed, it is only still here to ease the transition to UIDimensions + if (shrink_to_fit) + set_preferred_size(SpecialDimension::Fit); } bool Widget::has_pending_drop() const diff --git a/Userland/Libraries/LibGUI/Widget.h b/Userland/Libraries/LibGUI/Widget.h index 95c46661cd..6a49f2153b 100644 --- a/Userland/Libraries/LibGUI/Widget.h +++ b/Userland/Libraries/LibGUI/Widget.h @@ -312,8 +312,9 @@ public: bool load_from_gml(StringView); bool load_from_gml(StringView, RefPtr (*unregistered_child_handler)(String const&)); + // FIXME: remove this when all uses of shrink_to_fit are eliminated void set_shrink_to_fit(bool); - bool is_shrink_to_fit() const { return m_shrink_to_fit; } + bool is_shrink_to_fit() const { return preferred_width().is_shrink() || preferred_height().is_shrink(); } bool has_pending_drop() const; @@ -402,7 +403,6 @@ private: bool m_updates_enabled { true }; bool m_accepts_emoji_input { false }; bool m_accepts_command_palette { true }; - bool m_shrink_to_fit { false }; bool m_default_font { true }; NonnullRefPtr m_palette;