span_layout.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 */
28 
29 #pragma once
30 
31 #include <memory>
32 #include "../../Core/Math/rect.h"
33 #include "../../Core/Math/size.h"
34 #include "color.h"
35 
36 namespace clan
37 {
40 
41  class Font;
42  class GraphicContext;
43  class Point;
44  class Size;
45  class SpanLayout_Impl;
46  class Image;
47  class SpanComponent;
48  class Canvas;
49 
51  enum SpanAlign
52  {
57  };
58 
60  class SpanLayout
61  {
62  public:
63  SpanLayout();
64  ~SpanLayout();
65 
67  {
69 
70  enum Type
71  {
78  } type;
79 
80  int object_id;
81  int offset;
82  };
83 
85  void clear();
86 
93  void add_text(const std::string &text, const Font &font, const Colorf &color = StandardColorf::white(), int id = -1);
94 
100  void add_image(const Image &image, int baseline_offset = 0, int id = -1);
101 
102  template<typename T>
103 
109  void add_component(T *component, int baseline_offset = 0, int id = -1);
110 
115  void layout(Canvas &canvas, int max_width);
116 
120  void set_position(const Point &pos);
121 
125  Size get_size() const;
126 
130  Rect get_rect() const;
131 
135  std::vector<Rect> get_rect_by_id(int id) const;
136 
143  HitTestResult hit_test(Canvas &canvas, const Point &pos);
144 
148  void draw_layout(Canvas &canvas);
149 
154  void draw_layout_ellipsis(Canvas &canvas, const Rect &content_rect);
155 
157  void set_component_geometry();
158 
165 
170  void set_selection_range(std::string::size_type start, std::string::size_type end);
171 
176  void set_selection_colors(const Colorf &foreground, const Colorf &background);
177 
179  void show_cursor();
180 
182  void hide_cursor();
183 
187  void set_cursor_pos(std::string::size_type pos);
188 
192  void set_cursor_overwrite_mode(bool enable);
193 
197  void set_cursor_color(const Colorf &color);
198 
203 
209  void set_align(SpanAlign align);
210 
213 
216 
217  private:
218  void add_component_helper(SpanComponent *component, int baseline_offset, int id);
219 
220  std::shared_ptr<SpanLayout_Impl> impl;
221  };
222 
224 }
void clear()
Clear.
Definition: clanapp.h:35
Floating point color description class (for float).
Definition: color.h:798
int object_id
Definition: span_layout.h:80
void add_text(const std::string &text, const Font &font, const Colorf &color=StandardColorf::white(), int id=-1)
Add text.
2D Graphics Canvas
Definition: canvas.h:71
void set_position(const Point &pos)
Set position.
void draw_layout_ellipsis(Canvas &canvas, const Rect &content_rect)
Draw layout generating ellipsis for clipped text.
void show_cursor()
Shows the cursor caret.
void hide_cursor()
Hides the cursor caret.
void set_selection_colors(const Colorf &foreground, const Colorf &background)
Set selection colors.
std::vector< Rect > get_rect_by_id(int id) const
Get Rect By Id.
void add_component(T *component, int baseline_offset=0, int id=-1)
Add component.
Definition: span_layout.h:55
void set_component_geometry()
Set component geometry.
int get_first_baseline_offset()
Returns the baseline offset for the first baseline.
Definition: span_layout.h:66
std::string get_combined_text() const
Get Combined text.
SpanAlign
Span Align.
Definition: span_layout.h:51
Size get_size() const
Get Size.
Definition: span_layout.h:54
enum clan::SpanLayout::HitTestResult::Type type
void set_cursor_color(const Colorf &color)
Sets the cursor color.
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:488
Definition: span_layout.h:53
Rect get_rect() const
Get Rect.
Type
Definition: span_layout.h:70
void set_selection_range(std::string::size_type start, std::string::size_type end)
Set selection range.
Definition: span_layout.h:77
void draw_layout(Canvas &canvas)
Draw layout.
int get_last_baseline_offset()
Returns the baseline offset for the last baseline.
void set_cursor_overwrite_mode(bool enable)
Toggles whether the cursor caret is shown as a solid box or a line.
Image class.
Definition: image.h:58
2D (x,y) point structure - Integer
Definition: point.h:61
static Colorf white()
Definition: color.h:1884
int offset
Definition: span_layout.h:81
Font class.
Definition: font.h:59
void add_image(const Image &image, int baseline_offset=0, int id=-1)
Add image.
Span layout class.
Definition: span_layout.h:60
2D (width,height) size structure - Integer
Definition: size.h:170
HitTestResult()
Definition: span_layout.h:68
void set_cursor_pos(std::string::size_type pos)
Sets the cursor position.
Size find_preferred_size(Canvas &canvas)
Find preferred size.
void layout(Canvas &canvas, int max_width)
Layout.
Definition: span_layout.h:56
HitTestResult hit_test(Canvas &canvas, const Point &pos)
Hit test.
void set_align(SpanAlign align)
Sets the text alignment.