mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:28:13 +00:00
LibGUI+LibDraw: Add "Palette" concept for scoped color theming
GApplication now has a palette. This palette contains all the system theme colors by default, and is inherited by a new top-level GWidget. New child widgets inherit their parents palette. It is possible to override the GApplication palette, and the palette of any GWidget. The Palette object contains a bunch of colors, each corresponding to a ColorRole. Each role has a convenience getter as well. Each GWidget now has a background_role() and foreground_role(), which are then looked up in their current palette when painting. This means that you no longer alter the background color of a widget by setting it directly, rather you alter either its background role, or the widget's palette.
This commit is contained in:
parent
cb4e51a7a5
commit
a79bac428b
62 changed files with 448 additions and 410 deletions
|
@ -1,3 +1,4 @@
|
|||
#include <LibDraw/Palette.h>
|
||||
#include <LibDraw/StylePainter.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
|
@ -6,8 +7,6 @@
|
|||
GTabWidget::GTabWidget(GWidget* parent)
|
||||
: GWidget(parent)
|
||||
{
|
||||
set_fill_with_background_color(true);
|
||||
set_background_color(SystemColor::Window);
|
||||
}
|
||||
|
||||
GTabWidget::~GTabWidget()
|
||||
|
@ -112,19 +111,19 @@ void GTabWidget::paint_event(GPaintEvent& event)
|
|||
auto container_rect = this->container_rect();
|
||||
auto padding_rect = container_rect;
|
||||
for (int i = 0; i < container_padding(); ++i) {
|
||||
painter.draw_rect(padding_rect, background_color());
|
||||
painter.draw_rect(padding_rect, palette().button());
|
||||
padding_rect.shrink(2, 2);
|
||||
}
|
||||
|
||||
StylePainter::paint_frame(painter, container_rect, FrameShape::Container, FrameShadow::Raised, 2);
|
||||
StylePainter::paint_frame(painter, container_rect, palette(), FrameShape::Container, FrameShadow::Raised, 2);
|
||||
|
||||
for (int i = 0; i < m_tabs.size(); ++i) {
|
||||
if (m_tabs[i].widget == m_active_widget)
|
||||
continue;
|
||||
bool hovered = i == m_hovered_tab_index;
|
||||
auto button_rect = this->button_rect(i);
|
||||
StylePainter::paint_tab_button(painter, button_rect, false, hovered, m_tabs[i].widget->is_enabled());
|
||||
painter.draw_text(button_rect.translated(0, 1), m_tabs[i].title, TextAlignment::Center, SystemColor::ButtonText);
|
||||
StylePainter::paint_tab_button(painter, button_rect, palette(), false, hovered, m_tabs[i].widget->is_enabled());
|
||||
painter.draw_text(button_rect.translated(0, 1), m_tabs[i].title, TextAlignment::Center, palette().button_text());
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_tabs.size(); ++i) {
|
||||
|
@ -132,9 +131,9 @@ void GTabWidget::paint_event(GPaintEvent& event)
|
|||
continue;
|
||||
bool hovered = i == m_hovered_tab_index;
|
||||
auto button_rect = this->button_rect(i);
|
||||
StylePainter::paint_tab_button(painter, button_rect, true, hovered, m_tabs[i].widget->is_enabled());
|
||||
painter.draw_text(button_rect.translated(0, 1), m_tabs[i].title, TextAlignment::Center, SystemColor::ButtonText);
|
||||
painter.draw_line(button_rect.bottom_left().translated(1, 1), button_rect.bottom_right().translated(-1, 1), SystemColor::Button);
|
||||
StylePainter::paint_tab_button(painter, button_rect, palette(), true, hovered, m_tabs[i].widget->is_enabled());
|
||||
painter.draw_text(button_rect.translated(0, 1), m_tabs[i].title, TextAlignment::Center, palette().button_text());
|
||||
painter.draw_line(button_rect.bottom_left().translated(1, 1), button_rect.bottom_right().translated(-1, 1), palette().button());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue