ladybird/Libraries/LibGUI/GGroupBox.cpp
Andreas Kling a79bac428b 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.
2019-12-24 21:27:16 +01:00

43 lines
1 KiB
C++

#include <LibDraw/Palette.h>
#include <LibDraw/StylePainter.h>
#include <LibGUI/GGroupBox.h>
#include <LibGUI/GPainter.h>
GGroupBox::GGroupBox(GWidget* parent)
: GGroupBox({}, parent)
{
}
GGroupBox::GGroupBox(const StringView& title, GWidget* parent)
: GWidget(parent)
, m_title(title)
{
}
GGroupBox::~GGroupBox()
{
}
void GGroupBox::paint_event(GPaintEvent& event)
{
GPainter painter(*this);
painter.add_clip_rect(event.rect());
Rect frame_rect {
0, font().glyph_height() / 2,
width(), height() - font().glyph_height() / 2
};
StylePainter::paint_frame(painter, frame_rect, palette(), FrameShape::Box, FrameShadow::Sunken, 2);
Rect text_rect { 4, 0, font().width(m_title) + 6, font().glyph_height() };
painter.fill_rect(text_rect, palette().button());
painter.draw_text(text_rect, m_title, TextAlignment::Center, palette().button_text());
}
void GGroupBox::set_title(const StringView& title)
{
if (m_title == title)
return;
m_title = title;
update();
}