label_view.h Source File - ClanLib SDK
Description: label_view.h Source File

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 {
40 left,
41 right,
42 center,
43 justify/*,
44 start,
45 end*/
46 };
47
48 enum class LineBreakMode
49 {
50 //word_wrapping,
51 //char_wrapping,
52 clipping,
53 truncating_head,
54 truncating_tail,
55 truncating_middle
56 };
57
58 class LabelViewImpl;
59
60 class LabelView : public View
61 {
62 public:
63 LabelView();
64
65 std::string text() const;
66
73 void set_text(const std::string &value, bool force_no_layout = false);
74
75 TextAlignment text_alignment() const;
76 void set_text_alignment(TextAlignment alignment);
77
78 LineBreakMode line_break_mode() const;
79 void set_line_break_mode(LineBreakMode value);
80
81 void layout_children(Canvas &canvas) override;
82
84 void reset_font();
85
86 protected:
87 void render_content(Canvas &canvas) override;
88 float calculate_preferred_width(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}
clan::Canvas
2D Graphics Canvas
Definition canvas.h:72
clan::LabelView
Definition label_view.h:61
clan::LabelView::render_content
void render_content(Canvas &canvas) override
Renders the content of a view.
clan::LabelView::reset_font
void reset_font()
Update the font in according to style.
clan::LabelView::line_break_mode
LineBreakMode line_break_mode() const
clan::LabelView::calculate_last_baseline_offset
float calculate_last_baseline_offset(Canvas &canvas, float width) override
Calculates the offset to the last baseline.
clan::LabelView::calculate_preferred_width
float calculate_preferred_width(Canvas &canvas) override
Calculates the preferred width of this view.
clan::LabelView::layout_children
void layout_children(Canvas &canvas) override
Sets the view geometry for all children of this view.
clan::LabelView::set_text
void set_text(const std::string &value, bool force_no_layout=false)
Set text for display to the user.
clan::LabelView::calculate_preferred_height
float calculate_preferred_height(Canvas &canvas, float width) override
Calculates the preferred height of this view.
clan::LabelView::LabelView
LabelView()
clan::LabelView::set_text_alignment
void set_text_alignment(TextAlignment alignment)
clan::LabelView::calculate_first_baseline_offset
float calculate_first_baseline_offset(Canvas &canvas, float width) override
Calculates the offset to the first baseline.
clan::LabelView::text_alignment
TextAlignment text_alignment() const
clan::LabelView::text
std::string text() const
clan::LabelView::set_line_break_mode
void set_line_break_mode(LineBreakMode value)
clan::View
View for an area of the user interface.
Definition view.h:66
clan::View::canvas
Canvas canvas() const
clan::Origin::center
@ center
clan::Handedness::right
@ right
clan::Handedness::left
@ left
clan
Definition clanapp.h:36
clan::LineBreakMode
LineBreakMode
Definition label_view.h:49
clan::LineBreakMode::truncating_head
@ truncating_head
clan::LineBreakMode::truncating_middle
@ truncating_middle
clan::LineBreakMode::truncating_tail
@ truncating_tail
clan::LineBreakMode::clipping
@ clipping
clan::TextAlignment
TextAlignment
Definition label_view.h:39
clan::TextAlignment::justify
@ justify