1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:07:46 +00:00

Add a little About app and hook it up to the system menu's "About..." entry.

Added icons and customizable text alignment to GLabel.
This commit is contained in:
Andreas Kling 2019-02-12 15:23:07 +01:00
parent d6326d6c2e
commit d74b131c27
11 changed files with 118 additions and 2 deletions

View file

@ -1,5 +1,6 @@
#include "GLabel.h"
#include <SharedGraphics/Painter.h>
#include <SharedGraphics/GraphicsBitmap.h>
GLabel::GLabel(GWidget* parent)
: GWidget(parent)
@ -10,6 +11,11 @@ GLabel::~GLabel()
{
}
void GLabel::set_icon(RetainPtr<GraphicsBitmap>&& icon)
{
m_icon = move(icon);
}
void GLabel::set_text(String&& text)
{
if (text == m_text)
@ -18,11 +24,15 @@ void GLabel::set_text(String&& text)
update();
}
void GLabel::paint_event(GPaintEvent& event)
void GLabel::paint_event(GPaintEvent&)
{
Painter painter(*this);
if (fill_with_background_color())
painter.fill_rect({ 0, 0, width(), height() }, background_color());
if (m_icon) {
auto icon_location = rect().center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2));
painter.blit_with_alpha(icon_location, *m_icon, m_icon->rect());
}
if (!text().is_empty())
painter.draw_text({ 4, 4, width(), height() }, text(), TextAlignment::TopLeft, foreground_color());
painter.draw_text({ 0, 0, width(), height() }, text(), m_text_alignment, foreground_color());
}

View file

@ -2,6 +2,9 @@
#include "GWidget.h"
#include <AK/AKString.h>
#include <SharedGraphics/Painter.h>
class GraphicsBitmap;
class GLabel final : public GWidget {
public:
@ -11,11 +14,20 @@ public:
String text() const { return m_text; }
void set_text(String&&);
void set_icon(RetainPtr<GraphicsBitmap>&&);
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
GraphicsBitmap* icon() { return m_icon.ptr(); }
TextAlignment text_alignment() const { return m_text_alignment; }
void set_text_alignment(TextAlignment text_alignment) { m_text_alignment = text_alignment; }
private:
virtual void paint_event(GPaintEvent&) override;
virtual const char* class_name() const override { return "GLabel"; }
String m_text;
RetainPtr<GraphicsBitmap> m_icon;
TextAlignment m_text_alignment { TextAlignment::Center };
};

View file

@ -10,6 +10,7 @@ GStatusBar::GStatusBar(GWidget* parent)
set_preferred_size({ 0, 16 });
set_layout(make<GBoxLayout>(Orientation::Horizontal));
m_label = new GLabel(this);
m_label->set_text_alignment(TextAlignment::CenterLeft);
m_label->set_fill_with_background_color(false);
}