span_layout.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 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 
52 {
57 };
58 
61 {
64 public:
68 
70  {
72 
73  enum Type
74  {
80  inside
81  } type;
82 
83  int object_id;
84  int offset;
85  };
86 
89 public:
91  void clear();
92 
99  void add_text(const std::string &text, const Font &font, const Colorf &color = Colorf::white, int id = -1);
100 
106  void add_image(const Image &image, int baseline_offset = 0, int id = -1);
107 
108  template<typename T>
109 
115  void add_component(T *component, int baseline_offset = 0, int id = -1);
116 
121  void layout(Canvas &canvas, int max_width);
122 
126  void set_position(const Point &pos);
127 
131  Size get_size() const;
132 
136  Rect get_rect() const;
137 
141  std::vector<Rect> get_rect_by_id(int id) const;
142 
149  HitTestResult hit_test(Canvas &canvas, const Point &pos);
150 
154  void draw_layout(Canvas &canvas);
155 
160  void draw_layout_ellipsis(Canvas &canvas, const Rect &content_rect);
161 
164 
171 
176  void set_selection_range(std::string::size_type start, std::string::size_type end);
177 
182  void set_selection_colors(const Colorf &foreground, const Colorf &background);
183 
185  void show_cursor();
186 
188  void hide_cursor();
189 
193  void set_cursor_pos(std::string::size_type pos);
194 
198  void set_cursor_overwrite_mode(bool enable);
199 
203  void set_cursor_color(const Colorf &color);
204 
208  std::string get_combined_text() const;
209 
215  void set_align(SpanAlign align);
216 
219 
222 
224 
227 private:
228 
234  void add_component_helper(SpanComponent *component, int baseline_offset, int id);
235 
236  std::shared_ptr<SpanLayout_Impl> impl;
238 };
239 
240 }
241 
void clear()
Clear.
@ span_right
Definition: span_layout.h:54
2D (x,y) point structure - Integer
Definition: point.h:63
@ span_left
Definition: span_layout.h:53
int offset
Definition: span_layout.h:84
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:471
@ span_justify
Definition: span_layout.h:56
@ inside
Definition: span_layout.h:80
void add_component(T *component, int baseline_offset=0, int id=-1)
Add component.
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.
Type
Definition: span_layout.h:74
void set_component_geometry()
Set component geometry.
Floating point color description class (for float).
Definition: color.h:661
enum clan::SpanLayout::HitTestResult::Type type
void set_selection_range(std::string::size_type start, std::string::size_type end)
Set selection range.
void set_align(SpanAlign align)
Sets the text alignment.
HitTestResult()
Definition: span_layout.h:71
2D Graphics Canvas
Definition: canvas.h:73
void set_cursor_overwrite_mode(bool enable)
Toggles whether the cursor caret is shown as a solid box or a line.
Size get_size() const
Get Size.
void set_position(const Point &pos)
Set position.
void hide_cursor()
Hides the cursor caret.
std::string get_combined_text() const
Get Combined text.
Font class.
Definition: font.h:54
@ outside_bottom
Definition: span_layout.h:79
void add_text(const std::string &text, const Font &font, const Colorf &color=Colorf::white, int id=-1)
Add text.
void show_cursor()
Shows the cursor caret.
void draw_layout(Canvas &canvas)
Draw layout.
void set_cursor_color(const Colorf &color)
Sets the cursor color.
SpanAlign
Span Align.
Definition: span_layout.h:52
Definition: clanapp.h:36
int object_id
Definition: span_layout.h:83
@ no_objects_available
Definition: span_layout.h:75
void draw_layout_ellipsis(Canvas &canvas, const Rect &content_rect)
Draw layout generating ellipsis for clipped text.
Image class.
Definition: image.h:60
Rect get_rect() const
Get Rect.
int get_last_baseline_offset()
Returns the baseline offset for the last baseline.
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.
@ outside_top
Definition: span_layout.h:76
@ outside_right
Definition: span_layout.h:78
HitTestResult hit_test(Canvas &canvas, const Point &pos)
Hit test.
void layout(Canvas &canvas, int max_width)
Layout.
2D (width,height) size structure - Integer
Definition: size.h:157
void add_image(const Image &image, int baseline_offset=0, int id=-1)
Add image.
Size find_preferred_size(Canvas &canvas)
Find preferred size.
Span layout class.
Definition: span_layout.h:61
@ outside_left
Definition: span_layout.h:77
@ span_center
Definition: span_layout.h:55
Definition: span_layout.h:70
static Colorf white
Definition: color.h:1251