span_layout.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 
30 #pragma once
31 
32 #include <memory>
33 #include "../../Core/Math/rect.h"
34 #include "../../Core/Math/size.h"
35 #include "color.h"
36 
37 namespace clan
38 {
41 
42 class Font;
43 class GraphicContext;
44 class Point;
45 class Size;
46 class SpanLayout_Impl;
47 class Image;
48 class SpanComponent;
49 class Canvas;
50 
53 {
58 };
59 
62 {
65 public:
66  SpanLayout();
67  ~SpanLayout();
69 
71  {
73 
74  enum Type
75  {
82  } type;
83 
84  int object_id;
85  int offset;
86  };
87 
90 public:
92  void clear();
93 
100  void add_text(const std::string &text, const Font &font, const Colorf &color = Colorf::white, int id = -1);
101 
107  void add_image(const Image &image, int baseline_offset = 0, int id = -1);
108 
109  template<typename T>
110 
116  void add_component(T *component, int baseline_offset = 0, int id = -1);
117 
122  void layout(Canvas &canvas, int max_width);
123 
127  void set_position(const Point &pos);
128 
132  Size get_size() const;
133 
137  Rect get_rect() const;
138 
142  std::vector<Rect> get_rect_by_id(int id) const;
143 
144 
151  HitTestResult hit_test(Canvas &canvas, const Point &pos);
152 
156  void draw_layout(Canvas &canvas);
157 
162  void draw_layout_ellipsis(Canvas &canvas, const Rect &content_rect);
163 
165  void set_component_geometry();
166 
173 
178  void set_selection_range(std::string::size_type start, std::string::size_type end);
179 
184  void set_selection_colors(const Colorf &foreground, const Colorf &background);
185 
187  void show_cursor();
188 
190  void hide_cursor();
191 
195  void set_cursor_pos(std::string::size_type pos);
196 
200  void set_cursor_overwrite_mode(bool enable);
201 
205  void set_cursor_color(const Colorf &color);
206 
210  std::string get_combined_text() const;
211 
217  void set_align(SpanAlign align);
218 
221 
224 
226 
229 private:
230 
236  void add_component_helper(SpanComponent *component, int baseline_offset, int id);
237 
238  std::shared_ptr<SpanLayout_Impl> impl;
240 };
241 
242 }
243 
std::string get_combined_text() const
Get Combined text.
Floating point color description class (for float).
Definition: color.h:661
void clear()
Clear.
static Colorf white
Definition: color.h:1245
void layout(Canvas &canvas, int max_width)
Layout.
2D Graphics Canvas
Definition: canvas.h:70
enum clan::SpanLayout::HitTestResult::Type type
void set_selection_colors(const Colorf &foreground, const Colorf &background)
Set selection colors.
Definition: span_layout.h:56
void add_text(const std::string &text, const Font &font, const Colorf &color=Colorf::white, int id=-1)
Add text.
Definition: span_layout.h:70
void set_align(SpanAlign align)
Sets the text alignment.
void add_component(T *component, int baseline_offset=0, int id=-1)
Add component.
SpanAlign
Span Align.
Definition: span_layout.h:52
Definition: span_layout.h:55
void set_selection_range(std::string::size_type start, std::string::size_type end)
Set selection range.
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:453
int offset
Definition: span_layout.h:85
Definition: span_layout.h:54
void set_cursor_color(const Colorf &color)
Sets the cursor color.
Type
Definition: span_layout.h:74
void set_cursor_overwrite_mode(bool enable)
Toggles whether the cursor caret is shown as a solid box or a line.
void set_component_geometry()
Set component geometry.
Definition: span_layout.h:81
void add_image(const Image &image, int baseline_offset=0, int id=-1)
Add image.
HitTestResult()
Definition: span_layout.h:72
Image class.
Definition: image.h:60
void show_cursor()
Shows the cursor caret.
int get_last_baseline_offset()
Returns the baseline offset for the last baseline.
2D (x,y) point structure - Integer
Definition: point.h:63
std::vector< Rect > get_rect_by_id(int id) const
Get Rect By Id.
Size get_size() const
Get Size.
void draw_layout_ellipsis(Canvas &canvas, const Rect &content_rect)
Draw layout generating ellipsis for clipped text.
Font class.
Definition: font.h:52
Span layout class.
Definition: span_layout.h:61
2D (width,height) size structure - Integer
Definition: size.h:157
void set_position(const Point &pos)
Set position.
void hide_cursor()
Hides the cursor caret.
int get_first_baseline_offset()
Returns the baseline offset for the first baseline.
void set_cursor_pos(std::string::size_type pos)
Sets the cursor position.
Size find_preferred_size(Canvas &canvas)
Find preferred size.
void draw_layout(Canvas &canvas)
Draw layout.
Rect get_rect() const
Get Rect.
HitTestResult hit_test(Canvas &canvas, const Point &pos)
Hit test.
Definition: span_layout.h:57
int object_id
Definition: span_layout.h:84