mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:48:14 +00:00
LibGUI: Allow specifying GButton text alignment.
This commit is contained in:
parent
1374195a0d
commit
89c544d97b
2 changed files with 7 additions and 2 deletions
|
@ -37,7 +37,7 @@ void GButton::paint_event(GPaintEvent& event)
|
||||||
StylePainter::paint_button(painter, rect(), m_button_style, m_being_pressed, m_hovered, m_checkable && m_checked);
|
StylePainter::paint_button(painter, rect(), m_button_style, m_being_pressed, m_hovered, m_checkable && m_checked);
|
||||||
|
|
||||||
if (!caption().is_empty() || m_icon) {
|
if (!caption().is_empty() || m_icon) {
|
||||||
auto content_rect = rect();
|
auto content_rect = rect().shrunken(10, 2);
|
||||||
auto icon_location = m_icon ? content_rect.center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2)) : Point();
|
auto icon_location = m_icon ? content_rect.center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2)) : Point();
|
||||||
if (m_being_pressed) {
|
if (m_being_pressed) {
|
||||||
content_rect.move_by(1, 1);
|
content_rect.move_by(1, 1);
|
||||||
|
@ -46,7 +46,7 @@ void GButton::paint_event(GPaintEvent& event)
|
||||||
if (m_icon)
|
if (m_icon)
|
||||||
painter.blit(icon_location, *m_icon, m_icon->rect());
|
painter.blit(icon_location, *m_icon, m_icon->rect());
|
||||||
auto& font = (m_checkable && m_checked) ? Font::default_bold_font() : this->font();
|
auto& font = (m_checkable && m_checked) ? Font::default_bold_font() : this->font();
|
||||||
painter.draw_text(content_rect, caption(), font, TextAlignment::Center, Color::Black);
|
painter.draw_text(content_rect, caption(), font, text_alignment(), Color::Black);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <AK/AKString.h>
|
#include <AK/AKString.h>
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <SharedGraphics/GraphicsBitmap.h>
|
#include <SharedGraphics/GraphicsBitmap.h>
|
||||||
|
#include <SharedGraphics/TextAlignment.h>
|
||||||
|
|
||||||
class GButton : public GWidget {
|
class GButton : public GWidget {
|
||||||
public:
|
public:
|
||||||
|
@ -24,6 +25,9 @@ public:
|
||||||
bool is_checked() const { return m_checked; }
|
bool is_checked() const { return m_checked; }
|
||||||
void set_checked(bool);
|
void set_checked(bool);
|
||||||
|
|
||||||
|
void set_text_alignment(TextAlignment text_alignment) { m_text_alignment = text_alignment; }
|
||||||
|
TextAlignment text_alignment() const { return m_text_alignment; }
|
||||||
|
|
||||||
Function<void(GButton&)> on_click;
|
Function<void(GButton&)> on_click;
|
||||||
|
|
||||||
void set_button_style(ButtonStyle style) { m_button_style = style; }
|
void set_button_style(ButtonStyle style) { m_button_style = style; }
|
||||||
|
@ -44,6 +48,7 @@ private:
|
||||||
String m_caption;
|
String m_caption;
|
||||||
RetainPtr<GraphicsBitmap> m_icon;
|
RetainPtr<GraphicsBitmap> m_icon;
|
||||||
ButtonStyle m_button_style { ButtonStyle::Normal };
|
ButtonStyle m_button_style { ButtonStyle::Normal };
|
||||||
|
TextAlignment m_text_alignment { TextAlignment::Center };
|
||||||
bool m_being_pressed { false };
|
bool m_being_pressed { false };
|
||||||
bool m_hovered { false };
|
bool m_hovered { false };
|
||||||
bool m_checkable { false };
|
bool m_checkable { false };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue