FifeGUI 0.3.0
A C++ GUI library designed for games.
label.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_WIDGETS_LABEL_HPP_
6#define INCLUDE_FIFECHAN_WIDGETS_LABEL_HPP_
7
8// Standard library includes
9#include <string>
10
11// Platform config include
12#include "fifechan/platform.hpp"
13
14// Project headers (subdirs before local)
15#include "fifechan/graphics.hpp"
16#include "fifechan/widget.hpp"
17
18namespace fcn
19{
25 class FIFEGUI_API Label : public Widget
26 {
27 public:
28 Label();
29
37 explicit Label(std::string caption);
38
45 std::string const & getCaption() const;
46
56 void setCaption(std::string const & caption);
57
66 void setAlignment(Graphics::Alignment alignment);
67
77
85
93
94 // Inherited from Widget
95
97
98 void resizeToContent(bool recursion = true) override;
99 void adjustSize() override;
100 void draw(Graphics* graphics) override;
101
102 protected:
112 void adjustSizeImpl();
113
117 std::string mCaption;
118
122 Graphics::Alignment mAlignment{Graphics::Alignment::Left};
123
127 Graphics::VerticalAlignment mVerticalAlignment{Graphics::VerticalAlignment::Center};
128 };
129} // namespace fcn
130
131#endif // INCLUDE_FIFECHAN_WIDGETS_LABEL_HPP_
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
VerticalAlignment
Vertical alignments for text drawing.
Definition graphics.hpp:74
Alignment
Horizontal alignments for text drawing.
Definition graphics.hpp:64
void draw(Graphics *graphics) override
Draws the widget.
Definition label.cpp:104
void setVerticalAlignment(Graphics::VerticalAlignment alignment)
Sets the vertical alignment of the caption.
Definition label.cpp:53
void setAlignment(Graphics::Alignment alignment)
Sets the alignment of the caption.
Definition label.cpp:43
void adjustSize() override
Resizes the widget's size to fit the content exactly.
Definition label.cpp:70
void resizeToContent(bool recursion=true) override
Resizes the widget's size to fit the content exactly, calls recursively all childs.
Definition label.cpp:63
std::string const & getCaption() const
Gets the caption of the label.
Definition label.cpp:32
Graphics::Alignment getAlignment() const
Gets the alignment of the caption.
Definition label.cpp:48
void setCaption(std::string const &caption)
Sets the caption of the label.
Definition label.cpp:37
Graphics::Alignment mAlignment
Holds the horizontal alignment of the caption.
Definition label.hpp:122
std::string mCaption
Holds the caption of the label.
Definition label.hpp:117
Graphics::VerticalAlignment mVerticalAlignment
Holds the vertical alignment of the caption.
Definition label.hpp:127
Graphics::VerticalAlignment getVerticalAlignment() const
Gets the vertical alignment of the caption.
Definition label.cpp:58
void adjustSizeImpl()
Adjusts the size of the label to fit the caption.
Definition label.cpp:75
Widget()
Constructor.
Definition widget.cpp:52
virtual void resizeToContent(bool recursion=true)
Resizes the widget's size to fit the content exactly, calls recursively all childs.
Definition widget.hpp:1580
Used replacement tokens by configure_file():