summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/ToolBarContainer.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-04 18:21:05 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-04 18:21:05 +0100
commit21bacec13f1e825547959114f12e2f3397a45b75 (patch)
tree664d6661eb4749eb4779f1c8abed5e946ca79df0 /Libraries/LibGUI/ToolBarContainer.cpp
parentb03e1b08b515db786e340ce70a23ae85706c3f84 (diff)
downloadserenity-21bacec13f1e825547959114f12e2f3397a45b75.zip
LibGUI: Simplify ToolBarContainer by using shrink-to-fit
This class was implementing shrink-to-fit manually. No need for that anymore now that we can use Widget's shrink-to-fit mode.
Diffstat (limited to 'Libraries/LibGUI/ToolBarContainer.cpp')
-rw-r--r--Libraries/LibGUI/ToolBarContainer.cpp68
1 files changed, 10 insertions, 58 deletions
diff --git a/Libraries/LibGUI/ToolBarContainer.cpp b/Libraries/LibGUI/ToolBarContainer.cpp
index 753691e51b..d2f6b5252c 100644
--- a/Libraries/LibGUI/ToolBarContainer.cpp
+++ b/Libraries/LibGUI/ToolBarContainer.cpp
@@ -34,57 +34,6 @@ REGISTER_WIDGET(GUI, ToolBarContainer)
namespace GUI {
-void ToolBarContainer::child_event(Core::ChildEvent& event)
-{
- Frame::child_event(event);
-
- if (event.type() == Core::Event::ChildAdded) {
- if (event.child() && is<Widget>(event.child()))
- did_add_toolbar((Widget&)*event.child());
- } else if (event.type() == Core::Event::ChildRemoved) {
- if (event.child() && is<Widget>(event.child())) {
- did_remove_toolbar((Widget&)*event.child());
- }
- }
-}
-
-void ToolBarContainer::did_remove_toolbar(Widget& toolbar)
-{
- m_toolbars.remove_first_matching([&](auto& entry) { return entry.ptr() == &toolbar; });
- recompute_preferred_size();
-}
-
-void ToolBarContainer::did_add_toolbar(Widget& toolbar)
-{
- m_toolbars.append(toolbar);
- recompute_preferred_size();
-}
-
-void ToolBarContainer::custom_layout()
-{
- recompute_preferred_size();
-}
-
-void ToolBarContainer::recompute_preferred_size()
-{
- int visible_toolbar_count = 0;
- int preferred_size = 4;
-
- for (auto& toolbar : m_toolbars) {
- if (!toolbar.is_visible())
- continue;
- ++visible_toolbar_count;
- preferred_size += toolbar.min_size().secondary_size_for_orientation(m_orientation);
- }
-
- preferred_size += (visible_toolbar_count - 1) * 2;
-
- if (m_orientation == Gfx::Orientation::Horizontal)
- set_fixed_height(preferred_size);
- else
- set_fixed_width(preferred_size);
-}
-
ToolBarContainer::ToolBarContainer(Gfx::Orientation orientation)
: m_orientation(orientation)
{
@@ -97,6 +46,8 @@ ToolBarContainer::ToolBarContainer(Gfx::Orientation orientation)
auto& layout = set_layout<VerticalBoxLayout>();
layout.set_spacing(2);
layout.set_margins({ 2, 2, 2, 2 });
+
+ set_shrink_to_fit(true);
}
void ToolBarContainer::paint_event(GUI::PaintEvent& event)
@@ -104,13 +55,14 @@ void ToolBarContainer::paint_event(GUI::PaintEvent& event)
Painter painter(*this);
painter.add_clip_rect(event.rect());
- for (auto& toolbar : m_toolbars) {
- if (!toolbar.is_visible())
- continue;
- auto rect = toolbar.relative_rect();
- painter.draw_line(rect.top_left().translated(0, -1), rect.top_right().translated(0, -1), palette().threed_highlight());
- painter.draw_line(rect.bottom_left().translated(0, 1), rect.bottom_right().translated(0, 1), palette().threed_shadow1());
- }
+ for_each_child_of_type<ToolBar>([&](auto& toolbar) {
+ if (toolbar.is_visible()) {
+ auto rect = toolbar.relative_rect();
+ painter.draw_line(rect.top_left().translated(0, -1), rect.top_right().translated(0, -1), palette().threed_highlight());
+ painter.draw_line(rect.bottom_left().translated(0, 1), rect.bottom_right().translated(0, 1), palette().threed_shadow1());
+ }
+ return IterationDecision::Continue;
+ });
Frame::paint_event(event);
}