Class · aurore

aurore::Label

On this page
aurore/views/label.hpp
#include <aurore/views/label.hpp>

class aurore::Label : public aurore::View

Description

Some text. The Label will automatically grow as much as possible. If there is enough space, the label dimensions will fit the text. If there is not enough horizontal space available, it will wrap and expand its height. If there is not enough vertical space available to wrap, the text will be truncated instead. The truncated text will animate if the Label or one of its parents is focused. Animation will be disabled if the alignment is other than LEFT. Warning: to wrap, the label width MUST be constrained

Constructors 2

Label()

An empty label in the default font, size and colour.

label.hpp:68
~Label() override

Functions 42

virtual void draw(NVGcontext *vg,float x,float y,float width,float height,Style style,FrameContext *ctx) override

Called by frame() to draw the view onscreen. Views should not draw outside of their bounds (they may be clipped if they do so).

Overrides aurore::View::draw

label.hpp:71
virtual void onLayout() override

Called when a layout pass ends on that view.

Overrides aurore::View::onLayout

label.hpp:72
virtual void onFocusGained() override

Fired when focus is gained.

Overrides aurore::View::onFocusGained

label.hpp:73
virtual void onFocusLost() override

Fired when focus is lost.

Overrides aurore::View::onFocusLost

label.hpp:74
virtual void onParentFocusGained(View *focusedView) override

Fired when focus is gained on this view's parent, or the parent of the parent...

Overrides aurore::View::onParentFocusGained

label.hpp:75
virtual void onParentFocusLost(View *focusedView) override

Fired when focus is lost on one of this view's parents. Works similarly to onParentFocusGained().

Overrides aurore::View::onParentFocusLost

label.hpp:76
virtual void setText(const std::string &text)

Sets the text of the label.

label.hpp:81
void setHorizontalAlign(HorizontalAlign align)

Sets the alignment of the text inside the view. Will not move the view, only the text inside.

Default is CENTER.

label.hpp:90
void setVerticalAlign(VerticalAlign align)

Sets the alignment of the text inside the view. Will not move the view, only the text inside.

Only applies to single-line labels.

Default is CENTER.

label.hpp:101
void setFontSize(float value)

The font size asked, in layout units (drawn times the font scale).

label.hpp:104
void setFontScaled(bool scaled)

false: this label keeps its size whatever the font scale.

label.hpp:114
void setFontScaleMax(float max)

This label drawn at most max times its size, whatever the scale (with a scale of 1, as asked: nothing changes).

label.hpp:117
void setShrinkToFit(bool shrink)

A single line its box is too narrow for, at a scale above 1: drawn smaller until it fits, never below the size asked (then cut as before), rather than wrapped. Nothing changes at a scale of 1.

label.hpp:121
bool isShrinkingToFit()
void setShrinkToFitMin(float size)

With shrinkToFit: drawn as small as size, under the size asked and at any scale, before being cut (0, the default: the size asked).

label.hpp:126
float getDrawnFontSize()

The size it is drawn at, and the same before any shrinking to fit (what the text is measured at).

label.hpp:129
float getFullFontSize()
void setFontQuality(float value)

nanovg's quality for the glyphs (1 by default).

label.hpp:132
void setLineHeight(float value)

The height of a line, as a multiple of the font size.

label.hpp:134
void setTextColor(NVGcolor color)

The text's colour (setThemeColor follows a theme key instead).

label.hpp:136
void setFont(int font)

The font this label is drawn with (the app's default one unless set): by its id, or by the name it was loaded under (Application::loadFont*). A name not loaded leaves the font as it was. XML: fontFamily="name".

label.hpp:141
bool setFontFamily(const std::string &name)
int getFont()

The font id the label draws with.

label.hpp:145
float getFontSize()

The font size asked, before the font scale.

label.hpp:147
float getFontQuality()
float getLineHeight()
NVGcolor getTextColor()
std::string getFullText()

The whole text, as set (not cut to fit).

label.hpp:153
virtual bool getStyleProperty(const std::string &name,StyleValue *value) override

The style properties the states and transitions work on, by name: backgroundColor, borderColor, lineColor (colours), borderThickness, cornerRadius, alpha, scale (numbers); a Label adds textColor, a Rectangle color, a Button textColor. Only properties that are drawn, never laid out. A subclass adds its own by overriding both and calling the base for the others.

Overrides aurore::View::getStyleProperty

label.hpp:155
virtual bool setStyleProperty(const std::string &name,const StyleValue &value) override
virtual bool setBoundText(const std::string &text) override

Sets the view's text, for bind="text: …"; false when it has none.

Overrides aurore::View::setBoundText

label.hpp:157
virtual void onTextScaleChanged() override

Called on every view of the screens when the text scale changes (Application::setTextScale): a view that measures text marks itself dirty here.

Overrides aurore::View::onTextScaleChanged

label.hpp:158
void bindText(Observable< std::string > &text)

Its own Observable: the label shows its value, now and at each change, as long as it lives.

label.hpp:162
bool isTruncated()

The text as laid out does not fit: it is drawn cut, with an ellipsis.

label.hpp:164
void setRequiredWidth(float requiredWidth)

Set by the measure function: the width the text needs on one line.

label.hpp:170
void setEllipsisWidth(float ellipsisWidth)

Set by the measure function: the width of the ellipsis.

label.hpp:172
void setAnimated(bool animated)

If an "animated" label is too large to fit its bounds, the full text will be displayed in a scrolling animation instead of being truncated with an ellipsis ("...").

Unless the autoAnimate flag is set to false, a label will automatically be set to "animated" if it is focused or if one of its parent is.

label.hpp:182
void setAutoAnimate(bool autoAnimate)

Controls whether focus changes automatically animates the label or not. Doesn't stop the ongoing animation should there be one.

label.hpp:188
void setSingleLine(bool singleLine)

A single-line label will not wrap and increase its height, even if the remaining vertical space allows it.

Instead, it will always be truncated (if too large) to fit the horizontal space.

label.hpp:196
bool isSingleLine()
void setIsWrapping(bool isWrapping)

Internal flag set by the measure function.

label.hpp:204
void setCursor(int cursor)

Draws a blinking edit cursor before the byte cursor (CursorPosition::END: at the end; UNSET: none).

label.hpp:214

Also the functions of aurore::View (221).

Static functions 4

static void setFontScale(float scale)

Every label drawn scale times its size (1 by default), but those that keep theirs (setFontScaled(false)). It can change at any time: the labels then need laying out again (their nodes marked dirty). getFontSize() gives the size asked. Application::setTextScale does both.

label.hpp:110
static float getFontScale()
static View * create()

Makes a label for XML (<aurore:Label>).

label.hpp:167
static std::string STConverter(const std::string &text)

Simplified Chinese to Traditional Chinese

label.hpp:209

Static attributes 2

static bool OPENCC_ON = true

STConverter() applied to Traditional Chinese text.

label.hpp:211
static float FONT_SCALE = 1.0f

Protected functions 9

virtual AccessibilityRole getDefaultAccessibilityRole() override

The view's own role and label when the app gave none.

Overrides aurore::View::getDefaultAccessibilityRole

label.hpp:217
virtual std::string getDefaultAccessibilityLabel() override
float textWidth()

the text's width as drawn

label.hpp:231
void stopScrollingAnimation()
void resetScrollingAnimation()
void startScrollTimer()
void onScrollTimerFinished()
enum NVGalign getNVGHorizontalAlign()
enum NVGalign getNVGVerticalAlign()

Protected attributes 27

std::string truncatedText
std::string fullText
int font
float fontSize
bool fontScaled = true
float fontScaleMax = 1e6f
bool shrinkToFit = false
float shrinkMin = 0

setShrinkToFitMin

label.hpp:228
float fitScale = 1.0f

from onLayout, when shrinkToFit

label.hpp:229
float fittedWidth = 0

the text's width at that scale

label.hpp:230
float lineHeight
float fontQuality
NVGcolor textColor
float requiredWidth = 0
unsigned ellipsisWidth = 0
size_t stringLength = 0
bool singleLine = false
bool isWrapping = false
bool autoAnimate = true
bool animated = false

should it animate?

label.hpp:245
bool animating = false

currently animating?

label.hpp:246
int cursor = -2
Timer scrollingTimer
Animatable scrollingAnimation

Read from Aurore's headers by Doxygen at each build · library/include