UiUiUi
A user interface library for micro controller sketches based on U8g2
UITextLine.h
1// SPDX-License-Identifier: BSD-2-Clause
2// (C) 2022 Dirk Hillbrecht
3
4#pragma once
5
6#include "Arduino.h"
7#include <U8g2lib.h>
8
9#include "UIEnums.h"
10#include "UIPoint.h"
11#include "UISize.h"
12#include "UIArea.h"
13#include "UIWidget.h"
14
15
25class UITextLine : public UIWidget {
26
27 public:
28
30 UITextLine(const uint8_t* font,UIAlignment alignment,bool useUTF8=false,UIWidget* next=nullptr);
31
33 UITextLine(const uint8_t* font,UIAlignment alignment,UIWidget* next);
34
36 UITextLine(const uint8_t* font,bool useUTF8,UIWidget* next=nullptr);
37
39 UITextLine(const uint8_t* font,UIWidget* next);
40
42 UITextLine(const uint8_t* font);
43
49 void setText(const char* text);
50
52 void clearText();
53
61 void updateText();
62
67 UIArea* render(U8G2* display,bool force);
68
69 protected:
70
72 const uint8_t* font;
73
75 void computePreferredSize(U8G2 *display,UISize *preferredSize);
76
77 private:
78
80 const char* text;
81
83 UIAlignment alignment;
84
86 bool useUTF8;
87
89 UISize textSize;
90
92 UIPoint topLeft;
93
95 bool changed;
96
98 UIArea lastArea;
99
101 UIArea thisArea;
102
106 uint16_t getTextHeight(U8G2* display);
107
108};
109
110// end of file
Area consisting of left, top, right, and bottom value.
Definition: UIArea.h:20
Representation of a point on the display.
Definition: UIPoint.h:9
Representation of a size, i.e.
Definition: UISize.h:9
A widget containing a line of text which is set dynamically during runtime using setText().
Definition: UITextLine.h:25
UIArea * render(U8G2 *display, bool force)
Render the text line.
Definition: UITextLine.cpp:54
void computePreferredSize(U8G2 *display, UISize *preferredSize)
Generate the preferred size from the font size.
Definition: UITextLine.cpp:87
const uint8_t * font
The font of this text line.
Definition: UITextLine.h:72
void clearText()
Clear the text in this text line.
Definition: UITextLine.cpp:43
void setText(const char *text)
Set the text of the text line.
Definition: UITextLine.cpp:34
UITextLine(const uint8_t *font, UIAlignment alignment, bool useUTF8=false, UIWidget *next=nullptr)
Create a text line with the given font and alignment and a potential successor.
Definition: UITextLine.cpp:15
void updateText()
Insist that on the next render() call, the text line will update its content.
Definition: UITextLine.cpp:47
Basic widget class, ancestor of all UI widgets.
Definition: UIWidget.h:36
UISize preferredSize(U8G2 *display)
Return the preferred size of this widget, will be called before a call to layout().
Definition: UIWidget.cpp:16
UIWidget * next
Pointer to the next widget on the same level.
Definition: UIWidget.h:65