1.10
textwidget.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_TEXTWIDGET_H
7#define EGT_TEXTWIDGET_H
8
14#include <egt/detail/meta.h>
15#include <egt/image.h>
16#include <egt/signal.h>
17#include <egt/widget.h>
18#include <memory>
19#include <string>
20
21namespace egt
22{
23inline namespace v1
24{
25
32class EGT_API TextWidget : public Widget
33{
34public:
35
51 explicit TextWidget(std::string text = {},
52 const Rect& rect = {},
53 const AlignFlags& text_align = AlignFlag::center) noexcept;
54
58 explicit TextWidget(Serializer::Properties& props) noexcept
59 : TextWidget(props, false)
60 {
61 }
62
63protected:
64
65 explicit TextWidget(Serializer::Properties& props, bool is_derived) noexcept;
66
67public:
68
74 virtual void text(const std::string& str);
75
79 virtual void clear();
80
84 EGT_NODISCARD virtual const std::string& text() const { return m_text; }
85
91 void text_align(const AlignFlags& align)
92 {
93 if (detail::change_if_diff<>(m_text_align, align))
94 damage();
95 }
96
100 EGT_NODISCARD AlignFlags text_align() const { return m_text_align; }
101
105 EGT_NODISCARD virtual size_t len() const;
106
111 static Font scale_font(const Size& target, const std::string& text, const Font& font);
112
113 void serialize(Serializer& serializer) const override;
114
115protected:
116
118 EGT_NODISCARD Size text_size(const std::string& text) const;
119
121 AlignFlags m_text_align{AlignFlag::center};
122
124 std::string m_text;
125
126private:
128 void deserialize(Serializer::Properties& props);
129};
130
131}
132}
133
134#endif
Alignment flags.
Definition widgetflags.h:379
Manages a font and properties of a font.
Definition font.h:35
Abstract base serializer class.
Definition serialize.h:34
std::list< std::tuple< std::string, std::string, Serializer::Attributes > > Properties
Definition serialize.h:47
Signal class used for defining a signal and dispatching events.
Definition signal.h:30
A widget with text and text related properties.
Definition textwidget.h:33
void text_align(const AlignFlags &align)
Set the text alignment within the Label.
Definition textwidget.h:91
EGT_NODISCARD AlignFlags text_align() const
Get the text alignment within the Label.
Definition textwidget.h:100
virtual EGT_NODISCARD const std::string & text() const
Get the text of the Label.
Definition textwidget.h:84
virtual EGT_NODISCARD size_t len() const
Get the length of the text.
static Font scale_font(const Size &target, const std::string &text, const Font &font)
Given a Font, text, and a target Size, scale the font size so that the text will will fit and return ...
EGT_NODISCARD Size text_size(const std::string &text) const
Get the size of the text.
TextWidget(std::string text={}, const Rect &rect={}, const AlignFlags &text_align=AlignFlag::center) noexcept
Signal on_text_changed
Event signal.
Definition textwidget.h:43
void serialize(Serializer &serializer) const override
Serialize the widget to the specified serializer.
std::string m_text
The text.
Definition textwidget.h:124
TextWidget(Serializer::Properties &props) noexcept
Definition textwidget.h:58
virtual void clear()
Clear the text value.
TextWidget(Serializer::Properties &props, bool is_derived) noexcept
virtual void text(const std::string &str)
Set the text.
Base Widget class.
Definition widget.h:53
T & align(T &widget, const AlignFlags &a)
Helper to set alignment of a widget.
Definition widgetflags.h:624
EGT framework namespace.
Definition animation.h:24