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 {
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();
}

View file

@ -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;

View file

@ -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);
}

View file

@ -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:

View file

@ -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))
{
}

View file

@ -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;

View file

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

View file

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

View file

@ -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: