label_view.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 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 
36 namespace 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,
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 
76  void set_text_alignment(TextAlignment alignment);
77 
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 }
LineBreakMode
Definition: label_view.h:48
Definition: clanapp.h:35
View for an area of the user interface.
Definition: view.h:65
2D Graphics Canvas
Definition: canvas.h:71
void layout_children(Canvas &canvas) override
Sets the view geometry for all children of this view.
float calculate_last_baseline_offset(Canvas &canvas, float width) override
Calculates the offset to the last baseline.
void set_text_alignment(TextAlignment alignment)
Definition: label_view.h:60
void render_content(Canvas &canvas) override
Renders the content of a view.
std::string text() const
void set_line_break_mode(LineBreakMode value)
float calculate_first_baseline_offset(Canvas &canvas, float width) override
Calculates the offset to the first baseline.
float calculate_preferred_width(Canvas &canvas) override
Calculates the preferred width of this view.
LineBreakMode line_break_mode() const
TextAlignment
Definition: label_view.h:38
Canvas canvas() const
void reset_font()
Update the font in according to style.
void set_text(const std::string &value, bool force_no_layout=false)
Set text for display to the user.
TextAlignment text_alignment() const
float calculate_preferred_height(Canvas &canvas, float width) override
Calculates the preferred height of this view.