Skip to content

Commit

Permalink
Additional constructor with caption, store caption as CString
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Oct 20, 2023
1 parent 012f38d commit 49c8b56
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Control/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 5 additions & 4 deletions src/Control/Label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
22 changes: 18 additions & 4 deletions src/include/Graphics/Control/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -130,7 +144,7 @@ class Control : public CustomObject
}

Rect bounds;
String caption;
CString caption;
mutable BitSet<uint8_t, Flag> flags;
};

Expand Down

0 comments on commit 49c8b56

Please sign in to comment.