1.10
label.h
1/*
2 * Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef EGT_LABEL_H
7#define EGT_LABEL_H
8
14#include <egt/detail/meta.h>
15#include <egt/image.h>
16#include <egt/imageholder.h>
17#include <egt/textwidget.h>
18#include <memory>
19#include <string>
20
21namespace egt
22{
23inline namespace v1
24{
25class Frame;
26class Painter;
27
40class EGT_API Label : public TextWidget
41{
42public:
43
47 static void default_text_align(const AlignFlags& align);
48
53 explicit Label(const std::string& text = {},
54 const AlignFlags& text_align = default_text_align()) noexcept;
55
61 Label(const std::string& text,
62 const Rect& rect,
63 const AlignFlags& text_align = default_text_align()) noexcept;
64
70 explicit Label(Frame& parent,
71 const std::string& text = {},
72 const AlignFlags& text_align = default_text_align()) noexcept;
73
80 Label(Frame& parent,
81 const std::string& text,
82 const Rect& rect,
83 const AlignFlags& text_align = default_text_align()) noexcept;
84
88 explicit Label(Serializer::Properties& props) noexcept
89 : Label(props, false)
90 {
91 }
92
93protected:
94
95 explicit Label(Serializer::Properties& props, bool is_derived) noexcept;
96
97public:
98
99 Label(const Label&) = delete;
100 Label& operator=(const Label&) = delete;
101 Label(Label&&) noexcept = default;
102 Label& operator=(Label&&) noexcept = default;
103
104 using TextWidget::text;
105
106 void draw(Painter& painter, const Rect& rect) override;
107
109 static void default_draw(const Label& widget, Painter& painter, const Rect& rect);
110
111 using TextWidget::min_size_hint;
112
113 EGT_NODISCARD Size min_size_hint() const override;
114
115protected:
116
117 void set_parent(Widget* parent) override;
118};
119
144using ImageLabel = ImageHolder<Label, Palette::ColorId::label_bg, Palette::ColorId::border, Palette::ColorId::label_text>;
145
146}
147}
148
149#endif
Alignment flags.
Definition widgetflags.h:379
A Frame is a Widget that has children widgets.
Definition frame.h:45
A Label that displays text.
Definition label.h:41
Label(const std::string &text, const Rect &rect, const AlignFlags &text_align=default_text_align()) noexcept
Label(Label &&) noexcept=default
Label(const Label &)=delete
static AlignFlags default_text_align()
Change text align.
Label & operator=(const Label &)=delete
static void default_text_align(const AlignFlags &align)
Change default text align.
Label(const std::string &text={}, const AlignFlags &text_align=default_text_align()) noexcept
Label(Serializer::Properties &props, bool is_derived) noexcept
Label(Frame &parent, const std::string &text, const Rect &rect, const AlignFlags &text_align=default_text_align()) noexcept
Drawing interface for 2D graphics.
Definition painter.h:45
Color palette that contains a 2 dimensional array of colors.
Definition palette.h:40
Abstract base serializer class.
Definition serialize.h:34
std::list< std::tuple< std::string, std::string, Serializer::Attributes > > Properties
Definition serialize.h:47
A widget with text and text related properties.
Definition textwidget.h:33
Base Widget class.
Definition widget.h:53
EGT framework namespace.
Definition animation.h:24