Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
label.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019-2021 natinusala
3 Copyright 2019 p-sam
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16*/
17
18#pragma once
19
22#include <aurore/core/timer.hpp>
23#include <aurore/core/view.hpp>
24#ifdef OPENCC
25#define Opencc_BUILT_AS_STATIC
26#include <opencc.h>
27#endif
28
29namespace aurore
30{
31
34{
35 LEFT,
36 CENTER,
37 RIGHT,
38};
39
41enum class VerticalAlign
42{
44 TOP,
45 CENTER,
46 BOTTOM,
47};
48
51{
52 UNSET = -2,
53 END = -1,
54 START = 0,
55};
56
64class Label : public View
65{
66 public:
69 ~Label() override;
70
71 void draw(NVGcontext* vg, float x, float y, float width, float height, Style style, FrameContext* ctx) override;
72 void onLayout() override;
73 void onFocusGained() override;
74 void onFocusLost() override;
75 void onParentFocusGained(View* focusedView) override;
76 void onParentFocusLost(View* focusedView) override;
77
81 virtual void setText(const std::string& text);
82
91
102
104 void setFontSize(float value);
110 static void setFontScale(float scale);
112 static float getFontScale();
114 void setFontScaled(bool scaled);
117 void setFontScaleMax(float max);
121 void setShrinkToFit(bool shrink);
126 void setShrinkToFitMin(float size);
132 void setFontQuality(float value);
134 void setLineHeight(float value);
136 void setTextColor(NVGcolor color);
137
141 void setFont(int font);
142 bool setFontFamily(const std::string& name);
143
145 int getFont();
147 float getFontSize();
150 NVGcolor getTextColor();
151
153 std::string getFullText();
154
155 bool getStyleProperty(const std::string& name, StyleValue* value) override;
156 bool setStyleProperty(const std::string& name, const StyleValue& value) override;
157 bool setBoundText(const std::string& text) override;
158 void onTextScaleChanged() override;
159
165
167 static View* create();
168
173
183
189
197
200
205
209 static std::string STConverter(const std::string& text);
210
211 static inline bool OPENCC_ON = true;
212 static inline float FONT_SCALE = 1.0f;
214 void setCursor(int cursor);
215
216 protected:
218 std::string getDefaultAccessibilityLabel() override { return this->getFullText(); }
219
220 std::string truncatedText;
221 std::string fullText;
222
223 int font;
224 float fontSize;
225 bool fontScaled = true;
226 float fontScaleMax = 1e6f;
227 bool shrinkToFit = false;
228 float shrinkMin = 0;
229 float fitScale = 1.0f;
230 float fittedWidth = 0;
231 float textWidth();
234
235 NVGcolor textColor;
236
237 float requiredWidth = 0;
238 unsigned ellipsisWidth = 0;
239 size_t stringLength = 0;
240
241 bool singleLine = false;
242 bool isWrapping = false;
243
244 bool autoAnimate = true;
245 bool animated = false;
246 bool animating = false;
247 int cursor = -2;
249
252
255
258
261
262 enum NVGalign getNVGHorizontalAlign();
263 enum NVGalign getNVGVerticalAlign();
264};
265
266} // namespace aurore
Definition animation.hpp:42
Definition frame_context.hpp:30
Definition label.hpp:65
void onTextScaleChanged() override
void setFont(int font)
bool setFontFamily(const std::string &name)
virtual void setText(const std::string &text)
Time cursor_blink
Definition label.hpp:248
float fittedWidth
the text's width at that scale
Definition label.hpp:230
float getFontQuality()
enum NVGalign getNVGHorizontalAlign()
bool shrinkToFit
Definition label.hpp:227
bool getStyleProperty(const std::string &name, StyleValue *value) override
NVGcolor getTextColor()
void setAnimated(bool animated)
enum NVGalign getNVGVerticalAlign()
void onFocusGained() override
bool setBoundText(const std::string &text) override
static void setFontScale(float scale)
void setVerticalAlign(VerticalAlign align)
bool isTruncated()
The text as laid out does not fit: it is drawn cut, with an ellipsis.
int cursor
Definition label.hpp:247
void setRequiredWidth(float requiredWidth)
Set by the measure function: the width the text needs on one line.
void setCursor(int cursor)
Draws a blinking edit cursor before the byte cursor (CursorPosition::END: at the end; UNSET: none).
float getFullFontSize()
float shrinkMin
setShrinkToFitMin
Definition label.hpp:228
float fontSize
Definition label.hpp:224
Timer scrollingTimer
Definition label.hpp:250
static float FONT_SCALE
Definition label.hpp:212
bool isSingleLine()
See setSingleLine().
bool singleLine
Definition label.hpp:241
void onParentFocusLost(View *focusedView) override
void onLayout() override
void setShrinkToFitMin(float size)
unsigned ellipsisWidth
Definition label.hpp:238
AccessibilityRole getDefaultAccessibilityRole() override
Definition label.hpp:217
void draw(NVGcontext *vg, float x, float y, float width, float height, Style style, FrameContext *ctx) override
static bool OPENCC_ON
STConverter() applied to Traditional Chinese text.
Definition label.hpp:211
float fontScaleMax
Definition label.hpp:226
void setFontScaled(bool scaled)
false: this label keeps its size whatever the font scale.
void setSingleLine(bool singleLine)
bool animated
should it animate?
Definition label.hpp:245
void onFocusLost() override
size_t stringLength
Definition label.hpp:239
std::string truncatedText
Definition label.hpp:220
static std::string STConverter(const std::string &text)
std::string getFullText()
The whole text, as set (not cut to fit).
int font
Definition label.hpp:223
void bindText(Observable< std::string > &text)
float requiredWidth
Definition label.hpp:237
std::string fullText
Definition label.hpp:221
void setShrinkToFit(bool shrink)
void stopScrollingAnimation()
void onParentFocusGained(View *focusedView) override
void onScrollTimerFinished()
void setFontSize(float value)
The font size asked, in layout units (drawn times the font scale).
float fitScale
from onLayout, when shrinkToFit
Definition label.hpp:229
NVGcolor textColor
Definition label.hpp:235
static float getFontScale()
See setFontScale().
bool autoAnimate
Definition label.hpp:244
bool setStyleProperty(const std::string &name, const StyleValue &value) override
~Label() override
void startScrollTimer()
bool fontScaled
Definition label.hpp:225
Label()
An empty label in the default font, size and colour.
std::string getDefaultAccessibilityLabel() override
Definition label.hpp:218
void setAutoAnimate(bool autoAnimate)
void resetScrollingAnimation()
void setHorizontalAlign(HorizontalAlign align)
void setEllipsisWidth(float ellipsisWidth)
Set by the measure function: the width of the ellipsis.
int getFont()
The font id the label draws with.
VerticalAlign verticalAlign
Definition label.hpp:260
void setLineHeight(float value)
The height of a line, as a multiple of the font size.
void setTextColor(NVGcolor color)
The text's colour (setThemeColor follows a theme key instead).
float lineHeight
Definition label.hpp:232
bool isShrinkingToFit()
See setShrinkToFit().
static View * create()
Makes a label for XML (<aurore:Label>).
float fontQuality
Definition label.hpp:233
HorizontalAlign horizontalAlign
Definition label.hpp:259
bool animating
currently animating?
Definition label.hpp:246
float textWidth()
the text's width as drawn
void setFontScaleMax(float max)
bool isWrapping
Definition label.hpp:242
Animatable scrollingAnimation
Definition label.hpp:251
float getLineHeight()
float getFontSize()
The font size asked, before the font scale.
void setIsWrapping(bool isWrapping)
void setFontQuality(float value)
nanovg's quality for the glyphs (1 by default).
float getDrawnFontSize()
Definition observable.hpp:100
Simple wrapper around StyleValues for the array operator.
Definition style.hpp:115
Definition timer.hpp:27
Definition view.hpp:232
Definition actions.hpp:25
AccessibilityRole
Definition view_style.hpp:78
HorizontalAlign
Where a label's lines sit across its width.
Definition label.hpp:34
VerticalAlign
Where a label's text sits in its height.
Definition label.hpp:42
CursorPosition
An edit cursor's place in a label's text (Label::setCursor).
Definition label.hpp:51
@ BOTTOM
decor.bottom: along its bottom edge
@ TOP
decor.top: a strip along the top edge of the screen
retro_time_t Time
Definition time.hpp:31
Definition text.hpp:13
Definition view_style.hpp:41