diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-30 01:23:32 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-30 01:36:41 +0100 |
commit | 7dc5a3ead86627d11b1bf8d243750e5e3390c067 (patch) | |
tree | bfcab42f5b00c5b368ac9ee4a288d7c0d9c4bd01 /Services/Taskbar | |
parent | b2bba5ce5c06d40e2fbcfff4cf1412532f93ae6b (diff) | |
download | serenity-7dc5a3ead86627d11b1bf8d243750e5e3390c067.zip |
LibGUI: Rewrite layout system in terms of min and max sizes
This patch removes size policies and preferred sizes, and replaces them
with min-size and max-size for each widget.
Box layout now works in 3 passes:
1) Set all items (widgets/spacers) to their min-size
2) Distribute remaining space evenly, respecting max-size
3) Place widgets one after the other, adding spacing in between
I've also added convenience helpers for setting a fixed size (which is
the same as setting min-size and max-size to the same value.)
This significantly reduces the verbosity of widget layout and makes GML
a bit more pleasant to write, too. :^)
Diffstat (limited to 'Services/Taskbar')
-rw-r--r-- | Services/Taskbar/TaskbarWindow.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/Services/Taskbar/TaskbarWindow.cpp b/Services/Taskbar/TaskbarWindow.cpp index de5d3d2a99..9ad590c495 100644 --- a/Services/Taskbar/TaskbarWindow.cpp +++ b/Services/Taskbar/TaskbarWindow.cpp @@ -96,7 +96,6 @@ TaskbarWindow::~TaskbarWindow() void TaskbarWindow::create_quick_launch_bar() { auto& quick_launch_bar = main_widget()->add<GUI::Frame>(); - quick_launch_bar.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); quick_launch_bar.set_layout<GUI::HorizontalBoxLayout>(); quick_launch_bar.layout()->set_spacing(0); quick_launch_bar.layout()->set_margins({ 3, 0, 3, 0 }); @@ -116,9 +115,9 @@ void TaskbarWindow::create_quick_launch_bar() if (!af->is_valid()) continue; auto app_executable = af->executable(); + const int button_size = 24; auto& button = quick_launch_bar.add<GUI::Button>(); - button.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed); - button.set_preferred_size(24, 24); + button.set_fixed_size(button_size, button_size); button.set_button_style(Gfx::ButtonStyle::CoolBar); button.set_icon(af->icon().bitmap_for_size(16)); button.set_tooltip(af->name()); @@ -143,10 +142,10 @@ void TaskbarWindow::create_quick_launch_bar() if (!first) total_width += quick_launch_bar.layout()->spacing(); first = false; - total_width += button.preferred_width(); + total_width += button_size; } - quick_launch_bar.set_preferred_size(total_width, 24); + quick_launch_bar.set_fixed_size(total_width, 24); } void TaskbarWindow::on_screen_rect_change(const Gfx::IntRect& rect) @@ -158,9 +157,8 @@ void TaskbarWindow::on_screen_rect_change(const Gfx::IntRect& rect) NonnullRefPtr<GUI::Button> TaskbarWindow::create_button(const WindowIdentifier& identifier) { auto& button = main_widget()->add<TaskbarButton>(identifier); - button.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill); - button.set_min_size({ 20, 22 }); - button.set_max_size({ 140, 22 }); + button.set_min_size(20, 23); + button.set_max_size(140, 23); button.set_text_alignment(Gfx::TextAlignment::CenterLeft); button.set_icon(*m_default_icon); return button; |