summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorKarol Kosek <krkk@serenityos.org>2023-02-12 10:53:11 +0100
committerLinus Groh <mail@linusgroh.de>2023-02-13 00:45:09 +0000
commitfca29eae0988a46c3297a1dc515a8ca5ade40c6e (patch)
treeba28725745d4e148ebc7de308242040679a408f2 /Userland/Libraries
parentd32b052f22d3b1ffbf009d5de17572f381cd87fa (diff)
downloadserenity-fca29eae0988a46c3297a1dc515a8ca5ade40c6e.zip
LibGUI: Store text using the new String class in the AbstractButton
This change also adds non-deprecated text() and set_text() functions and helper constructors for Button, CheckBox, and RadioButton to call the strings directly. The whole codebase at this point is still using the deprecated string functions, which the class will quietly convert to a new String.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGUI/AbstractButton.cpp11
-rw-r--r--Userland/Libraries/LibGUI/AbstractButton.h9
-rw-r--r--Userland/Libraries/LibGUI/Button.cpp7
-rw-r--r--Userland/Libraries/LibGUI/Button.h9
-rw-r--r--Userland/Libraries/LibGUI/CheckBox.cpp7
-rw-r--r--Userland/Libraries/LibGUI/CheckBox.h3
-rw-r--r--Userland/Libraries/LibGUI/RadioButton.cpp5
-rw-r--r--Userland/Libraries/LibGUI/RadioButton.h3
8 files changed, 42 insertions, 12 deletions
diff --git a/Userland/Libraries/LibGUI/AbstractButton.cpp b/Userland/Libraries/LibGUI/AbstractButton.cpp
index 9eb76abf2d..e8efed323c 100644
--- a/Userland/Libraries/LibGUI/AbstractButton.cpp
+++ b/Userland/Libraries/LibGUI/AbstractButton.cpp
@@ -15,9 +15,9 @@
namespace GUI {
-AbstractButton::AbstractButton(DeprecatedString text)
+AbstractButton::AbstractButton(String text)
{
- set_text_deprecated(move(text));
+ set_text(move(text));
set_focus_policy(GUI::FocusPolicy::StrongFocus);
set_background_role(Gfx::ColorRole::Button);
@@ -34,7 +34,12 @@ AbstractButton::AbstractButton(DeprecatedString text)
REGISTER_BOOL_PROPERTY("exclusive", is_exclusive, set_exclusive);
}
-void AbstractButton::set_text_deprecated(DeprecatedString text)
+void AbstractButton::set_text_deprecated(DeprecatedString deprecated_text)
+{
+ set_text(String::from_deprecated_string(deprecated_text).release_value_but_fixme_should_propagate_errors());
+}
+
+void AbstractButton::set_text(String text)
{
if (m_text == text)
return;
diff --git a/Userland/Libraries/LibGUI/AbstractButton.h b/Userland/Libraries/LibGUI/AbstractButton.h
index c24ab8a83b..d890abeaa1 100644
--- a/Userland/Libraries/LibGUI/AbstractButton.h
+++ b/Userland/Libraries/LibGUI/AbstractButton.h
@@ -7,6 +7,7 @@
#pragma once
+#include <AK/String.h>
#include <LibGUI/Widget.h>
#include <LibGfx/TextWrapping.h>
@@ -21,7 +22,9 @@ public:
Function<void(bool)> on_checked;
virtual void set_text_deprecated(DeprecatedString);
- DeprecatedString const& text_deprecated() const { return m_text; }
+ DeprecatedString text_deprecated() const { return m_text.to_deprecated_string(); }
+ virtual void set_text(String);
+ String const& text() const { return m_text; }
bool is_exclusive() const { return m_exclusive; }
void set_exclusive(bool b) { m_exclusive = b; }
@@ -47,7 +50,7 @@ public:
void set_auto_repeat_interval(int interval) { m_auto_repeat_interval = interval; }
protected:
- explicit AbstractButton(DeprecatedString = {});
+ explicit AbstractButton(String = {});
virtual void mousedown_event(MouseEvent&) override;
virtual void mousemove_event(MouseEvent&) override;
@@ -62,7 +65,7 @@ protected:
void paint_text(Painter&, Gfx::IntRect const&, Gfx::Font const&, Gfx::TextAlignment, Gfx::TextWrapping = Gfx::TextWrapping::DontWrap);
private:
- DeprecatedString m_text;
+ String m_text;
bool m_checked { false };
bool m_checkable { false };
bool m_hovered { false };
diff --git a/Userland/Libraries/LibGUI/Button.cpp b/Userland/Libraries/LibGUI/Button.cpp
index eccd73cc23..6f24d17786 100644
--- a/Userland/Libraries/LibGUI/Button.cpp
+++ b/Userland/Libraries/LibGUI/Button.cpp
@@ -20,7 +20,12 @@ REGISTER_WIDGET(GUI, DialogButton)
namespace GUI {
-Button::Button(DeprecatedString text)
+Button::Button(DeprecatedString deprecated_text)
+ : Button(String::from_deprecated_string(deprecated_text).release_value_but_fixme_should_propagate_errors())
+{
+}
+
+Button::Button(String text)
: AbstractButton(move(text))
{
set_min_size({ 40, 22 });
diff --git a/Userland/Libraries/LibGUI/Button.h b/Userland/Libraries/LibGUI/Button.h
index d719efdc92..9420551997 100644
--- a/Userland/Libraries/LibGUI/Button.h
+++ b/Userland/Libraries/LibGUI/Button.h
@@ -68,7 +68,8 @@ public:
virtual Optional<UISize> calculated_min_size() const override;
protected:
- explicit Button(DeprecatedString text = {});
+ explicit Button(DeprecatedString text);
+ explicit Button(String text = {});
virtual void mousedown_event(MouseEvent&) override;
virtual void mousemove_event(MouseEvent&) override;
virtual void paint_event(PaintEvent&) override;
@@ -91,7 +92,11 @@ class DialogButton final : public Button {
public:
virtual ~DialogButton() override {};
- explicit DialogButton(DeprecatedString text = {})
+ explicit DialogButton(DeprecatedString deprecated_text)
+ : DialogButton(String::from_deprecated_string(deprecated_text).release_value_but_fixme_should_propagate_errors())
+ {
+ }
+ explicit DialogButton(String text = {})
: Button(move(text))
{
set_fixed_width(80);
diff --git a/Userland/Libraries/LibGUI/CheckBox.cpp b/Userland/Libraries/LibGUI/CheckBox.cpp
index bc99c52268..8fdf0ab05b 100644
--- a/Userland/Libraries/LibGUI/CheckBox.cpp
+++ b/Userland/Libraries/LibGUI/CheckBox.cpp
@@ -20,7 +20,12 @@ static constexpr int s_box_width = 13;
static constexpr int s_box_height = 13;
static constexpr int s_horizontal_padding = 6;
-CheckBox::CheckBox(DeprecatedString text)
+CheckBox::CheckBox(DeprecatedString deprecated_text)
+ : CheckBox(String::from_deprecated_string(deprecated_text).release_value_but_fixme_should_propagate_errors())
+{
+}
+
+CheckBox::CheckBox(String text)
: AbstractButton(move(text))
{
REGISTER_BOOL_PROPERTY("autosize", is_autosize, set_autosize);
diff --git a/Userland/Libraries/LibGUI/CheckBox.h b/Userland/Libraries/LibGUI/CheckBox.h
index e266484964..2122d32f1d 100644
--- a/Userland/Libraries/LibGUI/CheckBox.h
+++ b/Userland/Libraries/LibGUI/CheckBox.h
@@ -30,7 +30,8 @@ public:
void set_checkbox_position(CheckBoxPosition value) { m_checkbox_position = value; }
protected:
- explicit CheckBox(DeprecatedString = {});
+ explicit CheckBox(DeprecatedString);
+ explicit CheckBox(String = {});
private:
void size_to_fit();
diff --git a/Userland/Libraries/LibGUI/RadioButton.cpp b/Userland/Libraries/LibGUI/RadioButton.cpp
index 0c860c9a79..f0c387ad87 100644
--- a/Userland/Libraries/LibGUI/RadioButton.cpp
+++ b/Userland/Libraries/LibGUI/RadioButton.cpp
@@ -17,6 +17,11 @@ REGISTER_WIDGET(GUI, RadioButton)
namespace GUI {
RadioButton::RadioButton(DeprecatedString text)
+ : RadioButton(String::from_deprecated_string(text).release_value_but_fixme_should_propagate_errors())
+{
+}
+
+RadioButton::RadioButton(String text)
: AbstractButton(move(text))
{
set_exclusive(true);
diff --git a/Userland/Libraries/LibGUI/RadioButton.h b/Userland/Libraries/LibGUI/RadioButton.h
index b7e5cd5040..87da825829 100644
--- a/Userland/Libraries/LibGUI/RadioButton.h
+++ b/Userland/Libraries/LibGUI/RadioButton.h
@@ -22,7 +22,8 @@ public:
virtual Optional<UISize> calculated_min_size() const override;
protected:
- explicit RadioButton(DeprecatedString text = {});
+ explicit RadioButton(DeprecatedString text);
+ explicit RadioButton(String text = {});
virtual void paint_event(PaintEvent&) override;
private: