mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:17:44 +00:00
WindowServer+LibGfx: Move title bar button layout to WindowTheme
This commit is contained in:
parent
1ab8939077
commit
208cb995ba
4 changed files with 36 additions and 24 deletions
|
@ -177,4 +177,32 @@ IntRect ClassicWindowTheme::frame_rect_for_window(WindowType window_type, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector<IntRect> ClassicWindowTheme::layout_buttons(WindowType window_type, const IntRect& window_rect, const Palette& palette, size_t buttons) const
|
||||||
|
{
|
||||||
|
int window_button_width = palette.window_title_button_width();
|
||||||
|
int window_button_height = palette.window_title_button_height();
|
||||||
|
int pos;
|
||||||
|
Vector<IntRect> button_rects;
|
||||||
|
if (window_type == WindowType::Notification)
|
||||||
|
pos = title_bar_rect(window_type, window_rect, palette).top() + 2;
|
||||||
|
else
|
||||||
|
pos = title_bar_text_rect(window_type, window_rect, palette).right() + 1;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < buttons; i++) {
|
||||||
|
if (window_type == WindowType::Notification) {
|
||||||
|
// The button height & width have to be equal or it leaks out of its area
|
||||||
|
Gfx::IntRect rect { 0, pos, window_button_height, window_button_height };
|
||||||
|
rect.center_horizontally_within(title_bar_rect(window_type, window_rect, palette));
|
||||||
|
button_rects.append(rect);
|
||||||
|
pos += window_button_height;
|
||||||
|
} else {
|
||||||
|
pos -= window_button_width;
|
||||||
|
Gfx::IntRect rect { pos, 0, window_button_width, window_button_height };
|
||||||
|
rect.center_vertically_within(title_bar_text_rect(window_type, window_rect, palette));
|
||||||
|
button_rects.append(rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return button_rects;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibGfx/WindowTheme.h>
|
|
||||||
#include <LibGfx/Color.h>
|
#include <LibGfx/Color.h>
|
||||||
|
#include <LibGfx/WindowTheme.h>
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
|
@ -45,6 +45,8 @@ public:
|
||||||
|
|
||||||
virtual IntRect frame_rect_for_window(WindowType, const IntRect& window_rect, const Palette&) const override;
|
virtual IntRect frame_rect_for_window(WindowType, const IntRect& window_rect, const Palette&) const override;
|
||||||
|
|
||||||
|
virtual Vector<IntRect> layout_buttons(WindowType, const IntRect& window_rect, const Palette&, size_t buttons) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct FrameColors {
|
struct FrameColors {
|
||||||
Color title_color;
|
Color title_color;
|
||||||
|
|
|
@ -59,6 +59,8 @@ public:
|
||||||
|
|
||||||
virtual IntRect frame_rect_for_window(WindowType, const IntRect& window_rect, const Palette&) const = 0;
|
virtual IntRect frame_rect_for_window(WindowType, const IntRect& window_rect, const Palette&) const = 0;
|
||||||
|
|
||||||
|
virtual Vector<IntRect> layout_buttons(WindowType, const IntRect& window_rect, const Palette&, size_t buttons) const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
WindowTheme() { }
|
WindowTheme() { }
|
||||||
};
|
};
|
||||||
|
|
|
@ -261,29 +261,9 @@ void WindowFrame::notify_window_rect_changed(const Gfx::IntRect& old_rect, const
|
||||||
|
|
||||||
void WindowFrame::layout_buttons()
|
void WindowFrame::layout_buttons()
|
||||||
{
|
{
|
||||||
auto palette = WindowManager::the().palette();
|
auto button_rects = Gfx::WindowTheme::current().layout_buttons(to_theme_window_type(m_window.type()), m_window.rect(), WindowManager::the().palette(), m_buttons.size());
|
||||||
int window_button_width = palette.window_title_button_width();
|
for (size_t i = 0; i < m_buttons.size(); i++)
|
||||||
int window_button_height = palette.window_title_button_height();
|
m_buttons[i].set_relative_rect(button_rects[i]);
|
||||||
int pos;
|
|
||||||
if (m_window.type() == WindowType::Notification)
|
|
||||||
pos = title_bar_rect().top() + 2;
|
|
||||||
else
|
|
||||||
pos = title_bar_text_rect().right() + 1;
|
|
||||||
|
|
||||||
for (auto& button : m_buttons) {
|
|
||||||
if (m_window.type() == WindowType::Notification) {
|
|
||||||
// The button height & width have to be equal or it leaks out of its area
|
|
||||||
Gfx::IntRect rect { 0, pos, window_button_height, window_button_height };
|
|
||||||
rect.center_horizontally_within(title_bar_rect());
|
|
||||||
button.set_relative_rect(rect);
|
|
||||||
pos += window_button_height;
|
|
||||||
} else {
|
|
||||||
pos -= window_button_width;
|
|
||||||
Gfx::IntRect rect { pos, 0, window_button_width, window_button_height };
|
|
||||||
rect.center_vertically_within(title_bar_text_rect());
|
|
||||||
button.set_relative_rect(rect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowFrame::on_mouse_event(const MouseEvent& event)
|
void WindowFrame::on_mouse_event(const MouseEvent& event)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue