roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
roo_display::TextLabel Class Reference

Single-line, single-color text label. More...

#include <text_label.h>

Inheritance diagram for roo_display::TextLabel:
[legend]
Collaboration diagram for roo_display::TextLabel:
[legend]

Public Member Functions

template<typename String >
 TextLabel (const String &label, const Font &font, Color color, FillMode fill_mode=FillMode::kVisible)
 Construct from a string-like value (moves into internal storage).
 
 TextLabel (std::string label, const Font &font, Color color, FillMode fill_mode=FillMode::kVisible)
 Construct from an owned string.
 
void drawTo (const Surface &s) const override
 Draw this object's content, respecting the fill mode.
 
Box extents () const override
 Return the bounding box encompassing all pixels that need to be drawn.
 
Box anchorExtents () const override
 Return the bounds used for alignment.
 
const Fontfont () const
 Return the font used by the label.
 
const GlyphMetricsmetrics () const
 Return cached string metrics.
 
const std::string & label () const
 Return the label text.
 
const Color color () const
 Return the label color.
 
const FillMode fill_mode () const
 Return the fill mode.
 
void setColor (Color color)
 Set the label color.
 
void setFillMode (FillMode fill_mode)
 Set the fill mode.
 
- Public Member Functions inherited from roo_display::Drawable
virtual ~Drawable ()
 

Additional Inherited Members

- Static Public Member Functions inherited from roo_display::Drawable
static const DrawableEmpty ()
 A singleton representing a no-op drawable with no bounding box.
 

Detailed Description

Single-line, single-color text label.

Extents have height based on the font size, not the specific text. The origin is at the text baseline, and horizontally affected by the text bearing.

When using smooth fonts, you should generally specify bgcolor when drawing text labels, even over pre-filled solid backgrounds. This is because many device drivers don't support alpha blending, which is required for smooth font edges. Exceptions: offscreen/double-buffered devices, or drivers that do support alpha blending, when you want to preserve the existing non-solid background.

For changing text fields, wrap TextLabel in a Tile to reduce flicker.

See also StringViewLabel.

Definition at line 32 of file text_label.h.

Constructor & Destructor Documentation

◆ TextLabel() [1/2]

template<typename String >
roo_display::TextLabel::TextLabel ( const String label,
const Font font,
Color  color,
FillMode  fill_mode = FillMode::kVisible 
)
inline

Construct from a string-like value (moves into internal storage).

Definition at line 36 of file text_label.h.

◆ TextLabel() [2/2]

roo_display::TextLabel::TextLabel ( std::string  label,
const Font font,
Color  color,
FillMode  fill_mode = FillMode::kVisible 
)
inline

Construct from an owned string.

Definition at line 41 of file text_label.h.

Member Function Documentation

◆ anchorExtents()

Box roo_display::TextLabel::anchorExtents ( ) const
inlineoverridevirtual

Return the bounds used for alignment.

Defaults to extents(). Some drawables (notably text labels) may want different alignment bounds.

This method is called during a transaction and must not block or perform I/O.

Reimplemented from roo_display::Drawable.

Definition at line 59 of file text_label.h.

References roo_display::GlyphMetrics::advance(), roo_display::ascent, roo_display::descent, font(), roo_display::linegap, and metrics().

◆ color()

const Color roo_display::TextLabel::color ( ) const
inline

Return the label color.

Definition at line 71 of file text_label.h.

Referenced by drawTo(), roo_display::ClippedTextLabel::drawTo(), and setColor().

◆ drawTo()

void roo_display::TextLabel::drawTo ( const Surface s) const
inlineoverridevirtual

Draw this object's content, respecting the fill mode.

If s.fill_mode() == FillMode::kExtents, the method must fill the entire (clipped) extents() rectangle (using s.bgcolor() for transparent parts).

The default implementation fills the clipped extents() rectangle with bgcolor and then calls drawInteriorTo(). That can cause flicker, so override this method if a better implementation is possible.

The implementation must respect surface parameters, particularly clip_box(), and must not draw outside it. The surface clip box is pre-clipped to fit within this drawable's extents().

Reimplemented from roo_display::Drawable.

Definition at line 49 of file text_label.h.

References color(), roo_display::Font::drawHorizontalString(), fill_mode(), font(), roo_display::kExtents, and label().

◆ extents()

Box roo_display::TextLabel::extents ( ) const
inlineoverridevirtual

Return the bounding box encompassing all pixels that need to be drawn.

This method is called during a transaction and must not block or perform I/O.

Implements roo_display::Drawable.

Definition at line 57 of file text_label.h.

References roo_display::GlyphMetrics::screen_extents().

◆ fill_mode()

const FillMode roo_display::TextLabel::fill_mode ( ) const
inline

Return the fill mode.

Definition at line 73 of file text_label.h.

Referenced by drawTo(), roo_display::ClippedTextLabel::drawTo(), and setFillMode().

◆ font()

const Font & roo_display::TextLabel::font ( ) const
inline

Return the font used by the label.

Definition at line 65 of file text_label.h.

Referenced by anchorExtents(), drawTo(), and roo_display::ClippedTextLabel::drawTo().

◆ label()

const std::string & roo_display::TextLabel::label ( ) const
inline

Return the label text.

Definition at line 69 of file text_label.h.

Referenced by drawTo(), and roo_display::ClippedTextLabel::drawTo().

◆ metrics()

const GlyphMetrics & roo_display::TextLabel::metrics ( ) const
inline

Return cached string metrics.

Definition at line 67 of file text_label.h.

Referenced by anchorExtents(), and roo_display::ClippedTextLabel::anchorExtents().

◆ setColor()

void roo_display::TextLabel::setColor ( Color  color)
inline

Set the label color.

Definition at line 76 of file text_label.h.

References color().

◆ setFillMode()

void roo_display::TextLabel::setFillMode ( FillMode  fill_mode)
inline

Set the fill mode.

Definition at line 78 of file text_label.h.

References fill_mode().


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