diff options
author | Andreas Kling <kling@serenityos.org> | 2020-12-28 13:18:10 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-12-28 15:53:10 +0100 |
commit | cd9ad6a05e179935d276e7bcebf4fe6de1e4ef22 (patch) | |
tree | 323815205ae0a1b9e4d291549d921c1467ab41f9 /Libraries | |
parent | 476911e1f90742c4bf67e9b3d1815c8211f40bdd (diff) | |
download | serenity-cd9ad6a05e179935d276e7bcebf4fe6de1e4ef22.zip |
LibGUI: Tweak AbstractButton and subclass constructors
Taking a "const StringView&" for the initial text does not achieve
anything useful. Just take a "String" and move it into storage.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/AbstractButton.cpp | 9 | ||||
-rw-r--r-- | Libraries/LibGUI/AbstractButton.h | 7 | ||||
-rw-r--r-- | Libraries/LibGUI/Button.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibGUI/Button.h | 6 | ||||
-rw-r--r-- | Libraries/LibGUI/CheckBox.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibGUI/CheckBox.h | 5 | ||||
-rw-r--r-- | Libraries/LibGUI/ColorPicker.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibGUI/RadioButton.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibGUI/RadioButton.h | 5 |
9 files changed, 25 insertions, 21 deletions
diff --git a/Libraries/LibGUI/AbstractButton.cpp b/Libraries/LibGUI/AbstractButton.cpp index d4fba8c293..6f839017f0 100644 --- a/Libraries/LibGUI/AbstractButton.cpp +++ b/Libraries/LibGUI/AbstractButton.cpp @@ -32,9 +32,10 @@ namespace GUI { -AbstractButton::AbstractButton(const StringView& text) - : m_text(text) +AbstractButton::AbstractButton(String text) { + set_text(move(text)); + set_focus_policy(GUI::FocusPolicy::StrongFocus); set_background_role(Gfx::ColorRole::Button); set_foreground_role(Gfx::ColorRole::ButtonText); @@ -54,11 +55,11 @@ AbstractButton::~AbstractButton() { } -void AbstractButton::set_text(const StringView& text) +void AbstractButton::set_text(String text) { if (m_text == text) return; - m_text = text; + m_text = move(text); update(); } diff --git a/Libraries/LibGUI/AbstractButton.h b/Libraries/LibGUI/AbstractButton.h index d4cd02b6bd..5ed4ec24c5 100644 --- a/Libraries/LibGUI/AbstractButton.h +++ b/Libraries/LibGUI/AbstractButton.h @@ -31,13 +31,14 @@ namespace GUI { class AbstractButton : public Widget { - C_OBJECT_ABSTRACT(AbstractButton) + C_OBJECT_ABSTRACT(AbstractButton); + public: virtual ~AbstractButton() override; Function<void(bool)> on_checked; - void set_text(const StringView&); + void set_text(String); const String& text() const { return m_text; } bool is_exclusive() const { return m_exclusive; } @@ -59,7 +60,7 @@ public: void set_auto_repeat_interval(int interval) { m_auto_repeat_interval = interval; } protected: - explicit AbstractButton(const StringView& = {}); + explicit AbstractButton(String = {}); virtual void mousedown_event(MouseEvent&) override; virtual void mousemove_event(MouseEvent&) override; diff --git a/Libraries/LibGUI/Button.cpp b/Libraries/LibGUI/Button.cpp index 721abed9cd..c442f04105 100644 --- a/Libraries/LibGUI/Button.cpp +++ b/Libraries/LibGUI/Button.cpp @@ -35,8 +35,8 @@ namespace GUI { -Button::Button(const StringView& text) - : AbstractButton(text) +Button::Button(String text) + : AbstractButton(move(text)) { set_focus_policy(GUI::FocusPolicy::StrongFocus); } diff --git a/Libraries/LibGUI/Button.h b/Libraries/LibGUI/Button.h index d1121a6465..ae3c416be3 100644 --- a/Libraries/LibGUI/Button.h +++ b/Libraries/LibGUI/Button.h @@ -27,7 +27,6 @@ #pragma once #include <AK/Function.h> -#include <AK/String.h> #include <LibGUI/AbstractButton.h> #include <LibGfx/Bitmap.h> #include <LibGfx/StylePainter.h> @@ -36,7 +35,8 @@ namespace GUI { class Button : public AbstractButton { - C_OBJECT(Button) + C_OBJECT(Button); + public: virtual ~Button() override; @@ -61,7 +61,7 @@ public: virtual bool is_uncheckable() const override; protected: - explicit Button(const StringView& text = {}); + explicit Button(String text = {}); virtual void paint_event(PaintEvent&) override; private: diff --git a/Libraries/LibGUI/CheckBox.cpp b/Libraries/LibGUI/CheckBox.cpp index caa37ea95a..70c98f0e25 100644 --- a/Libraries/LibGUI/CheckBox.cpp +++ b/Libraries/LibGUI/CheckBox.cpp @@ -36,8 +36,8 @@ namespace GUI { static const int s_box_width = 13; static const int s_box_height = 13; -CheckBox::CheckBox(const StringView& text) - : AbstractButton(text) +CheckBox::CheckBox(String text) + : AbstractButton(move(text)) { } diff --git a/Libraries/LibGUI/CheckBox.h b/Libraries/LibGUI/CheckBox.h index 86b21cfe2a..733a264321 100644 --- a/Libraries/LibGUI/CheckBox.h +++ b/Libraries/LibGUI/CheckBox.h @@ -31,14 +31,15 @@ namespace GUI { class CheckBox : public AbstractButton { - C_OBJECT(CheckBox) + C_OBJECT(CheckBox); + public: virtual ~CheckBox() override; virtual void click(unsigned modifiers = 0) override; private: - explicit CheckBox(const StringView& = {}); + explicit CheckBox(String = {}); // These don't make sense for a check box, so hide them. using AbstractButton::auto_repeat_interval; diff --git a/Libraries/LibGUI/ColorPicker.cpp b/Libraries/LibGUI/ColorPicker.cpp index 3986a064f5..4f3b08af56 100644 --- a/Libraries/LibGUI/ColorPicker.cpp +++ b/Libraries/LibGUI/ColorPicker.cpp @@ -38,7 +38,7 @@ namespace GUI { class ColorButton : public AbstractButton { - C_OBJECT(ColorButton) + C_OBJECT(ColorButton); public: virtual ~ColorButton() override; diff --git a/Libraries/LibGUI/RadioButton.cpp b/Libraries/LibGUI/RadioButton.cpp index 63fe1d4362..b04052fe18 100644 --- a/Libraries/LibGUI/RadioButton.cpp +++ b/Libraries/LibGUI/RadioButton.cpp @@ -33,8 +33,8 @@ namespace GUI { -RadioButton::RadioButton(const StringView& text) - : AbstractButton(text) +RadioButton::RadioButton(String text) + : AbstractButton(move(text)) { } diff --git a/Libraries/LibGUI/RadioButton.h b/Libraries/LibGUI/RadioButton.h index d4a0445da4..1c4c163755 100644 --- a/Libraries/LibGUI/RadioButton.h +++ b/Libraries/LibGUI/RadioButton.h @@ -31,14 +31,15 @@ namespace GUI { class RadioButton : public AbstractButton { - C_OBJECT(RadioButton) + C_OBJECT(RadioButton); + public: virtual ~RadioButton() override; virtual void click(unsigned modifiers = 0) override; protected: - explicit RadioButton(const StringView& text = {}); + explicit RadioButton(String text = {}); virtual void paint_event(PaintEvent&) override; private: |