summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/AbstractThemePreview.cpp
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2022-05-01 15:45:14 +0100
committerLinus Groh <mail@linusgroh.de>2022-05-07 22:58:55 +0200
commit21c647dd7500bcc193cdc5934c26a845fcad1e97 (patch)
tree9ae1102d9777216ba302e5528a68cea38a15be8b /Userland/Libraries/LibGUI/AbstractThemePreview.cpp
parent28241f25dc70024b9bd39fe71d52c1456cd4ed78 (diff)
downloadserenity-21c647dd7500bcc193cdc5934c26a845fcad1e97.zip
LibGUI: Add center_window_group_within() to AbstractThemePreview
This method will center a group of window rects, within some bounds, accounting for the properties of the currently selected theme (i.e. border width, title height, etc).
Diffstat (limited to 'Userland/Libraries/LibGUI/AbstractThemePreview.cpp')
-rw-r--r--Userland/Libraries/LibGUI/AbstractThemePreview.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/AbstractThemePreview.cpp b/Userland/Libraries/LibGUI/AbstractThemePreview.cpp
index 96ae9f2351..18a4e2c11c 100644
--- a/Userland/Libraries/LibGUI/AbstractThemePreview.cpp
+++ b/Userland/Libraries/LibGUI/AbstractThemePreview.cpp
@@ -158,4 +158,31 @@ void AbstractThemePreview::paint_event(GUI::PaintEvent& event)
paint_preview(event);
}
+void AbstractThemePreview::center_window_group_within(Span<Window> windows, Gfx::IntRect const& bounds)
+{
+ VERIFY(windows.size() >= 1);
+
+ auto to_frame_rect = [&](Gfx::IntRect const& rect) {
+ return Gfx::WindowTheme::current().frame_rect_for_window(
+ Gfx::WindowTheme::WindowType::Normal, rect, m_preview_palette, 0);
+ };
+
+ auto leftmost_x_value = windows[0].rect.x();
+ auto topmost_y_value = windows[0].rect.y();
+ auto combind_frame_rect = to_frame_rect(windows[0].rect);
+ for (auto& window : windows.slice(1)) {
+ if (window.rect.x() < leftmost_x_value)
+ leftmost_x_value = window.rect.x();
+ if (window.rect.y() < topmost_y_value)
+ topmost_y_value = window.rect.y();
+ combind_frame_rect = combind_frame_rect.united(to_frame_rect(window.rect));
+ }
+
+ combind_frame_rect.center_within(bounds);
+ auto frame_offset = to_frame_rect({}).location();
+ for (auto& window : windows) {
+ window.rect.set_left(combind_frame_rect.left() + (window.rect.x() - leftmost_x_value) - frame_offset.x());
+ window.rect.set_top(combind_frame_rect.top() + (window.rect.y() - topmost_y_value) - frame_offset.y());
+ }
+}
}