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.
This commit is contained in:
Andreas Kling 2020-12-28 13:18:10 +01:00
parent 476911e1f9
commit cd9ad6a05e
Notes: sideshowbarker 2024-07-19 00:29:58 +09:00
9 changed files with 25 additions and 21 deletions

View file

@ -32,9 +32,10 @@
namespace GUI { namespace GUI {
AbstractButton::AbstractButton(const StringView& text) AbstractButton::AbstractButton(String text)
: m_text(text)
{ {
set_text(move(text));
set_focus_policy(GUI::FocusPolicy::StrongFocus); set_focus_policy(GUI::FocusPolicy::StrongFocus);
set_background_role(Gfx::ColorRole::Button); set_background_role(Gfx::ColorRole::Button);
set_foreground_role(Gfx::ColorRole::ButtonText); 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) if (m_text == text)
return; return;
m_text = text; m_text = move(text);
update(); update();
} }

View file

@ -31,13 +31,14 @@
namespace GUI { namespace GUI {
class AbstractButton : public Widget { class AbstractButton : public Widget {
C_OBJECT_ABSTRACT(AbstractButton) C_OBJECT_ABSTRACT(AbstractButton);
public: public:
virtual ~AbstractButton() override; virtual ~AbstractButton() override;
Function<void(bool)> on_checked; Function<void(bool)> on_checked;
void set_text(const StringView&); void set_text(String);
const String& text() const { return m_text; } const String& text() const { return m_text; }
bool is_exclusive() const { return m_exclusive; } bool is_exclusive() const { return m_exclusive; }
@ -59,7 +60,7 @@ public:
void set_auto_repeat_interval(int interval) { m_auto_repeat_interval = interval; } void set_auto_repeat_interval(int interval) { m_auto_repeat_interval = interval; }
protected: protected:
explicit AbstractButton(const StringView& = {}); explicit AbstractButton(String = {});
virtual void mousedown_event(MouseEvent&) override; virtual void mousedown_event(MouseEvent&) override;
virtual void mousemove_event(MouseEvent&) override; virtual void mousemove_event(MouseEvent&) override;

View file

@ -35,8 +35,8 @@
namespace GUI { namespace GUI {
Button::Button(const StringView& text) Button::Button(String text)
: AbstractButton(text) : AbstractButton(move(text))
{ {
set_focus_policy(GUI::FocusPolicy::StrongFocus); set_focus_policy(GUI::FocusPolicy::StrongFocus);
} }

View file

@ -27,7 +27,6 @@
#pragma once #pragma once
#include <AK/Function.h> #include <AK/Function.h>
#include <AK/String.h>
#include <LibGUI/AbstractButton.h> #include <LibGUI/AbstractButton.h>
#include <LibGfx/Bitmap.h> #include <LibGfx/Bitmap.h>
#include <LibGfx/StylePainter.h> #include <LibGfx/StylePainter.h>
@ -36,7 +35,8 @@
namespace GUI { namespace GUI {
class Button : public AbstractButton { class Button : public AbstractButton {
C_OBJECT(Button) C_OBJECT(Button);
public: public:
virtual ~Button() override; virtual ~Button() override;
@ -61,7 +61,7 @@ public:
virtual bool is_uncheckable() const override; virtual bool is_uncheckable() const override;
protected: protected:
explicit Button(const StringView& text = {}); explicit Button(String text = {});
virtual void paint_event(PaintEvent&) override; virtual void paint_event(PaintEvent&) override;
private: private:

View file

@ -36,8 +36,8 @@ namespace GUI {
static const int s_box_width = 13; static const int s_box_width = 13;
static const int s_box_height = 13; static const int s_box_height = 13;
CheckBox::CheckBox(const StringView& text) CheckBox::CheckBox(String text)
: AbstractButton(text) : AbstractButton(move(text))
{ {
} }

View file

@ -31,14 +31,15 @@
namespace GUI { namespace GUI {
class CheckBox : public AbstractButton { class CheckBox : public AbstractButton {
C_OBJECT(CheckBox) C_OBJECT(CheckBox);
public: public:
virtual ~CheckBox() override; virtual ~CheckBox() override;
virtual void click(unsigned modifiers = 0) override; virtual void click(unsigned modifiers = 0) override;
private: private:
explicit CheckBox(const StringView& = {}); explicit CheckBox(String = {});
// These don't make sense for a check box, so hide them. // These don't make sense for a check box, so hide them.
using AbstractButton::auto_repeat_interval; using AbstractButton::auto_repeat_interval;

View file

@ -38,7 +38,7 @@
namespace GUI { namespace GUI {
class ColorButton : public AbstractButton { class ColorButton : public AbstractButton {
C_OBJECT(ColorButton) C_OBJECT(ColorButton);
public: public:
virtual ~ColorButton() override; virtual ~ColorButton() override;

View file

@ -33,8 +33,8 @@
namespace GUI { namespace GUI {
RadioButton::RadioButton(const StringView& text) RadioButton::RadioButton(String text)
: AbstractButton(text) : AbstractButton(move(text))
{ {
} }

View file

@ -31,14 +31,15 @@
namespace GUI { namespace GUI {
class RadioButton : public AbstractButton { class RadioButton : public AbstractButton {
C_OBJECT(RadioButton) C_OBJECT(RadioButton);
public: public:
virtual ~RadioButton() override; virtual ~RadioButton() override;
virtual void click(unsigned modifiers = 0) override; virtual void click(unsigned modifiers = 0) override;
protected: protected:
explicit RadioButton(const StringView& text = {}); explicit RadioButton(String text = {});
virtual void paint_event(PaintEvent&) override; virtual void paint_event(PaintEvent&) override;
private: private: