From 49c8b561847b8c13e9de32a8e0002bed9c7c7571 Mon Sep 17 00:00:00 2001 From: mikee47 Date: Tue, 23 May 2023 12:00:00 +0100 Subject: [PATCH] Additional constructor with caption, store caption as CString --- src/Control/Button.cpp | 2 +- src/Control/Label.cpp | 9 +++++---- src/include/Graphics/Control/Control.h | 22 ++++++++++++++++++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Control/Button.cpp b/src/Control/Button.cpp index 86983185..6bd7595b 100644 --- a/src/Control/Button.cpp +++ b/src/Control/Button.cpp @@ -16,7 +16,7 @@ void Button::draw(SceneObject& scene) const text.setBackColor(backColor); text.setTextAlign(Align::Centre); text.setLineAlign(Align::Centre); - text.print(caption); + text.print(caption.c_str()); text.commit(scene); } diff --git a/src/Control/Label.cpp b/src/Control/Label.cpp index d0c07f68..e4bbd479 100644 --- a/src/Control/Label.cpp +++ b/src/Control/Label.cpp @@ -8,16 +8,17 @@ void Label::draw(SceneObject& scene) const auto backColor = getColor(Element::back); Rect r = bounds.size(); - // scene.drawRect(colors.border, r); + // scene.drawRect(getColor(Element::border), r); // r.inflate(-2, -2); scene.fillRect(backColor, r); TextBuilder text(scene); - // text.setFont(&statusFont); + text.setClip(r); + text.setFont(getFont()); text.setColor(getColor(Element::text)); text.setBackColor(backColor); - // text.setTextAlign(Align::Centre); + text.setTextAlign(getTextAlign()); text.setLineAlign(Align::Centre); - text.print(caption); + text.print(caption.c_str()); text.commit(scene); } diff --git a/src/include/Graphics/Control/Control.h b/src/include/Graphics/Control/Control.h index 08bc98c5..902ece31 100644 --- a/src/include/Graphics/Control/Control.h +++ b/src/include/Graphics/Control/Control.h @@ -39,6 +39,10 @@ class Control : public CustomObject { } + Control(const Rect& bounds, const String& caption) : bounds(bounds), caption(caption) + { + } + Renderer* createRenderer(const Location& location) const override; virtual void draw(SceneObject& scene) const = 0; @@ -47,14 +51,14 @@ class Control : public CustomObject { } - const String& getCaption() const + String getCaption() const { - return caption; + return caption.c_str(); } void setCaption(const String& value) { - if(value == caption) { + if(caption == value) { return; } this->caption = value; @@ -115,8 +119,18 @@ class Control : public CustomObject flags += Flag::dirty; } + virtual Font* getFont() const + { + return nullptr; + } + virtual Color getColor(Element element) const; + virtual Align getTextAlign() const + { + return Align::Near; + } + protected: friend class Screen; @@ -130,7 +144,7 @@ class Control : public CustomObject } Rect bounds; - String caption; + CString caption; mutable BitSet flags; };