gigawidgets 0.3.55
A wxWidgets-style UI library for the Arduino Giga Display Shield.
 
Loading...
Searching...
No Matches
ui::Text Class Reference

Display text to the screen. More...

#include <text.hpp>

Inheritance diagram for ui::Text:
ui::Widget ui::EventHandlers< Widget > ui::CoreEventHandlers< T >

Public Member Functions

 Text (const String &text, fontsize_t scale=1, color_t color=COLOR_WHITE, const Position &pos={0, 0}, const Alignment &align={ALIGN_LEFT, ALIGN_TOP}, bool wrap=true)
 Construct text with the built-in font.
 
 Text (const String &text, const GFXfont &font, color_t color=COLOR_WHITE, const Position &pos={0, 0}, const Alignment &align={ALIGN_LEFT, ALIGN_TOP}, bool wrap=true)
 Construct text with a given font.
 
void draw () const override
 Render the widget to the screen.
 
Size size () const override
 Get the size of the widget.
 
void setText (const String &text)
 Set the text to display.
 
const String & getText () const
 Get the currently displayed text.
 
void setWrap (bool wrap)
 Set whether text wraps.
 
void setFont (const GFXfont &font)
 Set the font to render text in.
 
void setScale (fontsize_t scale)
 Set the scaling factor for the text.
 
void setColor (color_t new_color)
 Set the text color.
 
color_t getColor () const
 Get the current widget color.
 
uisize_t getWidthAtChar (unsigned int index) const
 Get the width (in pixels) of a substring of the total text.
 
- Public Member Functions inherited from ui::Widget
 Widget (const Position &pos={0, 0}, const Alignment &align={ALIGN_LEFT, ALIGN_TOP}, const Padding &padding={0})
 The default widget constructor.
 
virtual void render (bool force) const
 Recursively render this widget and any child widgets that need it.
 
virtual ~Widget ()
 The default widget destructor.
 
virtual void update (time_t time)
 Update any internal state of the widget, and check if it needs to be re-rendered.
 
virtual Bounds bounds () const
 Get the rendering bounds of this widget.
 
void setPosition (const Position &pos)
 Set the position of this widget.
 
Position getPosition () const
 Get the position of this widget.
 
void setAlign (const Alignment &align)
 Set the alignment of this widget.
 
void requestRedraw ()
 Tell this widget that it needs to be re-rendered.
 
void requestParentRedraw ()
 Tell the parent widget that it needs to be re-rendered.
 
bool needsRedraw () const
 Check if this widget has requested to be redrawn.
 
virtual void drawDone ()
 Reset any state variables after rendering has finished.
 
void setParent (Widget *parent)
 Set the parent widget.
 
Bounds parentBounds () const
 Get the bounds of the parent widget, if any.
 
void onpress (std::function< void(Widget &, const Event &)> callback) override
 Register a touchscreen event handler that triggers on press.
 
void onblur (std::function< void(Widget &, const Event &)> callback) override
 Register a touchscreen event handler that triggers when the widget stops being pressed.
 
void onhold (std::function< void(Widget &, const Event &, time_t)> callback) override
 Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
 
void onrelease (std::function< void(Widget &, const Event &)> callback) override
 Register a touchscreen event handler that triggers on release.
 
void click ()
 Manually trigger the onrelease event handler.
 
void press ()
 Manually trigger the onpress event handler.
 
void blur ()
 Manually trigger the onblur event handler.
 
void release ()
 Manually trigger the onrelease event handler.
 
void hold (time_t time)
 Manually trigger the onhold event handler.
 
virtual bool handleEvent (Event &event)
 Handle events from the touchscreen.
 
virtual void drawBoundingBox (time_t time) const
 Render the bounding box of this and any child widgets.
 
virtual WidgetgetWidgetById (id_t id) noexcept
 Get the first widget (this or any children) that has the given ID.
 
- Public Member Functions inherited from ui::EventHandlers< Widget >
void onpress (std::function< void(Widget &)> callback)
 Register a touchscreen event handler that triggers on press.
 
void onpress (std::function< void(const Event &)> callback)
 Register a touchscreen event handler that triggers on press.
 
void onpress (std::function< void()> callback)
 Register a touchscreen event handler that triggers on press.
 
void onrelease (std::function< void(Widget &)> callback)
 Register a touchscreen event handler that triggers when the widget stops being pressed.
 
void onrelease (std::function< void(const Event &)> callback)
 Register a touchscreen event handler that triggers when the widget stops being pressed.
 
void onrelease (std::function< void()> callback)
 Register a touchscreen event handler that triggers when the widget stops being pressed.
 
void onblur (std::function< void(Widget &)> callback)
 Register a touchscreen event handler that triggers when the widget stops being pressed.
 
void onblur (std::function< void(const Event &)> callback)
 Register a touchscreen event handler that triggers when the widget stops being pressed.
 
void onblur (std::function< void()> callback)
 Register a touchscreen event handler that triggers when the widget stops being pressed.
 
void onhold (std::function< void(Widget &, time_t)> callback)
 Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
 
void onhold (std::function< void(const Event &, time_t)> callback)
 Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
 
void onhold (std::function< void(time_t)> callback)
 Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
 
void onhold (std::function< void(Widget &)> callback)
 Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
 
void onhold (std::function< void(const Event &)> callback)
 Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
 
void onhold (std::function< void()> callback)
 Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
 
void onclick (std::function< void(Widget &)> callback)
 Register a touchscreen event handler that triggers on release.
 
void onclick (std::function< void(const Event &)> callback)
 Register a touchscreen event handler that triggers on release.
 
void onclick (std::function< void()> callback)
 Register a touchscreen event handler that triggers on release.
 
- Public Member Functions inherited from ui::CoreEventHandlers< T >
virtual void onpress (std::function< void(T &, const Event &)> callback)=0
 Register a touchscreen event handler that triggers on press.
 
virtual void onrelease (std::function< void(T &, const Event &)> callback)=0
 Register a touchscreen event handler that triggers when the widget stops being pressed.
 
virtual void onblur (std::function< void(T &, const Event &)> callback)=0
 Register a touchscreen event handler that triggers when the widget stops being pressed.
 
virtual void onhold (std::function< void(T &, const Event &, time_t)> callback)=0
 Register a touchscreen event handler that repeatedly triggers when the widget is held for a while.
 
void onclick (std::function< void(T &, const Event &)> callback)
 Register a touchscreen event handler that triggers on release.
 

Protected Attributes

const GFXfont * font
 The font to render the text in. If null, defaults to the built-in font.
 
String text
 The text to display.
 
fontsize_t scale
 A scaling factor for the text, e.g. 2x, 3x, etc.
 
color_t textColor
 The text color.
 
bool wrap
 If true, wrap the text when reaching the right side of the parent widget. If false, don't wrap, just truncate.
 
- Protected Attributes inherited from ui::Widget
Padding padding
 The padding that will be applied to any child widgets.
 
bool redrawSelf
 If true, force a redraw of this widget and any child widgets.
 

Additional Inherited Members

- Public Attributes inherited from ui::Widget
id_t id
 An optional (usually unique) identifier that can be used to search for this widget.
 

Detailed Description

Display text to the screen.

Constructor & Destructor Documentation

◆ Text() [1/2]

ui::Text::Text ( const String &  text,
fontsize_t  scale = 1,
color_t  color = COLOR_WHITE,
const Position pos = {0, 0},
const Alignment align = {ALIGN_LEFT, ALIGN_TOP},
bool  wrap = true 
)

Construct text with the built-in font.

Parameters
textThe text to display.
scaleA scaling factor for the text, e.g. 2x, 3x etc.
colorThe text color.
posThe position of the text relative to its parent.
alignThe alignment of the text relative to its parent.
wrapIf true, wrap the text when reaching the right side of the parent widget. If false, don't wrap, just truncate.

◆ Text() [2/2]

ui::Text::Text ( const String &  text,
const GFXfont &  font,
color_t  color = COLOR_WHITE,
const Position pos = {0, 0},
const Alignment align = {ALIGN_LEFT, ALIGN_TOP},
bool  wrap = true 
)

Construct text with a given font.

Parameters
textThe text to display.
fontThe font to render text in.
colorThe text color.
posThe position of the text relative to its parent.
alignThe alignment of the text relative to its parent.
wrapIf true, wrap the text when reaching the right side of the parent widget. If false, don't wrap, just truncate.

Member Function Documentation

◆ draw()

void ui::Text::draw ( ) const
overridevirtual

Render the widget to the screen.

This only gets called when widgets indicate that a redraw is needed of either themselves or their parents. Widgets that implement this method should only render graphics specific to this widget, not any children.

Implements ui::Widget.

◆ getColor()

color_t ui::Text::getColor ( ) const

Get the current widget color.

Returns
The widget color.

◆ getText()

const String & ui::Text::getText ( ) const

Get the currently displayed text.

Returns
The current text.

◆ getWidthAtChar()

uisize_t ui::Text::getWidthAtChar ( unsigned int  index) const

Get the width (in pixels) of a substring of the total text.

Parameters
indexThe end position of the substring.
Returns
The width in pixels of the substring.

◆ setColor()

void ui::Text::setColor ( color_t  new_color)

Set the text color.

Parameters
new_colorThe new text color.

◆ setFont()

void ui::Text::setFont ( const GFXfont &  font)

Set the font to render text in.

Parameters
fontThe new font to render the text in. If null, defaults to the built-in font.

◆ setScale()

void ui::Text::setScale ( fontsize_t  scale)

Set the scaling factor for the text.

Parameters
scaleThe new scaling factor for the text, e.g. 2x, 3x, etc.

◆ setText()

void ui::Text::setText ( const String &  text)

Set the text to display.

Parameters
textThe new text to display.

◆ setWrap()

void ui::Text::setWrap ( bool  wrap)

Set whether text wraps.

Parameters
wrapIf true, wrap the text when reaching the right side of the parent widget. If false, don't wrap, just truncate.

◆ size()

Size ui::Text::size ( ) const
overridevirtual

Get the size of the widget.

Returns
The width and height of the widget in pixels.
Warning
This value may be based on the size of the child widget, and so should never refer to the size of the parent widget!

Implements ui::Widget.


The documentation for this class was generated from the following file: