forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibGUI: Add a simple GGroupBox widget.
This needs some work on the visual side, but it gets the job done already.
- Loading branch information
1 parent
b980c32
commit f6543c5
Showing
5 changed files
with
65 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <LibGUI/GGroupBox.h> | ||
#include <LibGUI/GPainter.h> | ||
#include <SharedGraphics/StylePainter.h> | ||
|
||
GGroupBox::GGroupBox(const String& name, GWidget* parent) | ||
: GWidget(parent) | ||
, m_name(name) | ||
{ | ||
set_fill_with_background_color(true); | ||
set_background_color(Color::LightGray); | ||
} | ||
|
||
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, FrameShape::Panel, FrameShadow::Sunken, 1); | ||
|
||
Rect text_rect { 4, 0, font().width(m_name) + 6, font().glyph_height() }; | ||
painter.fill_rect(text_rect, background_color()); | ||
painter.draw_text(text_rect, m_name, TextAlignment::Center, foreground_color()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include <LibGUI/GWidget.h> | ||
|
||
class GGroupBox : public GWidget { | ||
public: | ||
GGroupBox(const String& name, GWidget* parent); | ||
virtual ~GGroupBox() override; | ||
|
||
String name() const { return m_name; } | ||
|
||
virtual const char* class_name() const override { return "GGroupBox"; } | ||
|
||
protected: | ||
virtual void paint_event(GPaintEvent&) override; | ||
|
||
private: | ||
String m_name; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters