summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-26 13:10:50 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-26 13:11:43 +0100
commit4e084793dff3475943fc732017ad27c6c99d739f (patch)
treed5e3a7c591d6fa0352e169459ec6f891089519f4
parent9fe310c470018cf21cd573ddcf9a31632d1fd816 (diff)
downloadserenity-4e084793dff3475943fc732017ad27c6c99d739f.zip
LibGUI: Tweak GUI::Label API a bit and add did_change_text() virtual
-rw-r--r--Libraries/LibGUI/Label.cpp9
-rw-r--r--Libraries/LibGUI/Label.h8
2 files changed, 10 insertions, 7 deletions
diff --git a/Libraries/LibGUI/Label.cpp b/Libraries/LibGUI/Label.cpp
index 878925fd55..60e831b4b7 100644
--- a/Libraries/LibGUI/Label.cpp
+++ b/Libraries/LibGUI/Label.cpp
@@ -32,8 +32,8 @@
namespace GUI {
-Label::Label(const StringView& text)
- : m_text(text)
+Label::Label(String text)
+ : m_text(move(text))
{
set_frame_thickness(0);
set_frame_shadow(Gfx::FrameShadow::Plain);
@@ -66,14 +66,15 @@ void Label::set_icon(const Gfx::Bitmap* icon)
update();
}
-void Label::set_text(const StringView& text)
+void Label::set_text(String text)
{
if (text == m_text)
return;
- m_text = text;
+ m_text = move(text);
if (m_autosize)
size_to_fit();
update();
+ did_change_text();
}
void Label::paint_event(PaintEvent& event)
diff --git a/Libraries/LibGUI/Label.h b/Libraries/LibGUI/Label.h
index 12d2e57278..c98c1ffec6 100644
--- a/Libraries/LibGUI/Label.h
+++ b/Libraries/LibGUI/Label.h
@@ -32,12 +32,13 @@
namespace GUI {
class Label : public Frame {
- C_OBJECT(Label)
+ C_OBJECT(Label);
+
public:
virtual ~Label() override;
String text() const { return m_text; }
- void set_text(const StringView&);
+ void set_text(String);
void set_icon(const Gfx::Bitmap*);
const Gfx::Bitmap* icon() const { return m_icon.ptr(); }
@@ -53,9 +54,10 @@ public:
void set_autosize(bool);
protected:
- explicit Label(const StringView& text = {});
+ explicit Label(String text = {});
virtual void paint_event(PaintEvent&) override;
+ virtual void did_change_text() { }
private:
void size_to_fit();