label_view.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 The ClanLib Team
4**
5** This software is provided 'as-is', without any express or implied
6** warranty. In no event will the authors be held liable for any damages
7** arising from the use of this software.
8**
9** Permission is granted to anyone to use this software for any purpose,
10** including commercial applications, and to alter it and redistribute it
11** freely, subject to the following restrictions:
12**
13** 1. The origin of this software must not be misrepresented; you must not
14** claim that you wrote the original software. If you use this software
15** in a product, an acknowledgment in the product documentation would be
16** appreciated but is not required.
17** 2. Altered source versions must be plainly marked as such, and must not be
18** misrepresented as being the original software.
19** 3. This notice may not be removed or altered from any source distribution.
20**
21** Note: Some of the libraries ClanLib may link to may have additional
22** requirements or restrictions.
23**
24** File Author(s):
25**
26** Magnus Norddahl
27** Artem Khomenko (modified set_text())
28*/
29
30#pragma once
31
32#include "../View/view.h"
33#include "../../Display/Font/font.h"
34#include "../../Display/2D/color.h"
35
36namespace clan
37{
38 enum class TextAlignment
39 {
44 start,
45 end*/
46 };
47
48 enum class LineBreakMode
49 {
50 //word_wrapping,
51 //char_wrapping,
56 };
57
58 class LabelViewImpl;
59
60 class LabelView : public View
61 {
62 public:
64
65 std::string text() const;
66
73 void set_text(const std::string &value, bool force_no_layout = false);
74
77
80
81 void layout_children(Canvas &canvas) override;
82
84 void reset_font();
85
86 protected:
87 void render_content(Canvas &canvas) override;
89 float calculate_preferred_height(Canvas &canvas, float width) override;
90 float calculate_first_baseline_offset(Canvas &canvas, float width) override;
91 float calculate_last_baseline_offset(Canvas &canvas, float width) override;
92
93 private:
94 std::shared_ptr<LabelViewImpl> impl;
95 };
96
97}
2D Graphics Canvas
Definition canvas.h:72
void render_content(Canvas &canvas) override
Renders the content of a view.
void reset_font()
Update the font in according to style.
LineBreakMode line_break_mode() const
float calculate_last_baseline_offset(Canvas &canvas, float width) override
Calculates the offset to the last baseline.
float calculate_preferred_width(Canvas &canvas) override
Calculates the preferred width of this view.
void layout_children(Canvas &canvas) override
Sets the view geometry for all children of this view.
void set_text(const std::string &value, bool force_no_layout=false)
Set text for display to the user.
float calculate_preferred_height(Canvas &canvas, float width) override
Calculates the preferred height of this view.
void set_text_alignment(TextAlignment alignment)
float calculate_first_baseline_offset(Canvas &canvas, float width) override
Calculates the offset to the first baseline.
TextAlignment text_alignment() const
std::string text() const
void set_line_break_mode(LineBreakMode value)
Canvas canvas() const
@ center
Definition origin.h:44
@ right
Definition mat4.h:47
@ left
Definition mat4.h:46
Definition clanapp.h:36
LineBreakMode
Definition label_view.h:49
@ truncating_head
Definition label_view.h:53
@ truncating_middle
Definition label_view.h:55
@ truncating_tail
Definition label_view.h:54
@ clipping
Definition label_view.h:52
TextAlignment
Definition label_view.h:39
@ justify
Definition label_view.h:43