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
51 enum SpanAlign
52 {
53 span_left,
54 span_right,
55 span_center,
56 span_justify
57 };
58
60 class SpanLayout
61 {
64 public:
65 SpanLayout();
66 ~SpanLayout();
68
69 struct HitTestResult
70 {
71 HitTestResult() : object_id(-1), offset(0) {}
72
73 enum Type
74 {
75 no_objects_available,
76 outside_top,
77 outside_left,
78 outside_right,
79 outside_bottom,
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
163 void set_component_geometry();
164
170 Size find_preferred_size(Canvas &canvas);
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
218 int get_first_baseline_offset();
219
221 int get_last_baseline_offset();
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
clan
Definition: clanapp.h:35
clan::SpanLayout::get_combined_text
std::string get_combined_text() const
Get Combined text.
clan::Colorf
Floating point color description class (for float).
Definition: color.h:660
clan::SpanLayout::clear
void clear()
Clear.
clan::Colorf::white
static Colorf white
Definition: color.h:1251
clan::SpanLayout::layout
void layout(Canvas &canvas, int max_width)
Layout.
clan::Canvas
2D Graphics Canvas
Definition: canvas.h:72
clan::SpanLayout::HitTestResult::outside_top
Definition: span_layout.h:76
clan::SpanLayout::HitTestResult::type
enum clan::SpanLayout::HitTestResult::Type type
clan::SpanLayout::set_selection_colors
void set_selection_colors(const Colorf &foreground, const Colorf &background)
Set selection colors.
clan::SpanLayout::HitTestResult::outside_left
Definition: span_layout.h:77
clan::span_center
Definition: span_layout.h:55
clan::SpanLayout::add_text
void add_text(const std::string &text, const Font &font, const Colorf &color=Colorf::white, int id=-1)
Add text.
clan::BrushType::image
clan::SpanLayout::HitTestResult
Definition: span_layout.h:69
clan::SpanLayout::set_align
void set_align(SpanAlign align)
Sets the text alignment.
clan::SpanLayout::add_component
void add_component(T *component, int baseline_offset=0, int id=-1)
Add component.
clan::SpanAlign
SpanAlign
Span Align.
Definition: span_layout.h:51
clan::span_right
Definition: span_layout.h:54
clan::SpanLayout::set_selection_range
void set_selection_range(std::string::size_type start, std::string::size_type end)
Set selection range.
clan::StyleTokenType::string
@ keyword
clan::Rect
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:470
clan::SpanLayout::HitTestResult::offset
int offset
Definition: span_layout.h:84
clan::span_left
Definition: span_layout.h:53
clan::SpanLayout::HitTestResult::no_objects_available
Definition: span_layout.h:75
clan::SpanLayout::HitTestResult::outside_right
Definition: span_layout.h:78
clan::SpanLayout::set_cursor_color
void set_cursor_color(const Colorf &color)
Sets the cursor color.
clan::SpanLayout::HitTestResult::Type
Type
Definition: span_layout.h:73
clan::SpanLayout::set_cursor_overwrite_mode
void set_cursor_overwrite_mode(bool enable)
Toggles whether the cursor caret is shown as a solid box or a line.
clan::SpanLayout::set_component_geometry
void set_component_geometry()
Set component geometry.
clan::SpanLayout::HitTestResult::inside
Definition: span_layout.h:80
clan::SpanLayout::add_image
void add_image(const Image &image, int baseline_offset=0, int id=-1)
Add image.
clan::SpanLayout::HitTestResult::HitTestResult
HitTestResult()
Definition: span_layout.h:71
clan::Image
Image class.
Definition: image.h:59
clan::SpanLayout::show_cursor
void show_cursor()
Shows the cursor caret.
clan::SpanLayout::get_last_baseline_offset
int get_last_baseline_offset()
Returns the baseline offset for the last baseline.
clan::Point
2D (x,y) point structure - Integer
Definition: point.h:62
clan::SpanLayout::get_rect_by_id
std::vector< Rect > get_rect_by_id(int id) const
Get Rect By Id.
clan::SpanLayout::get_size
Size get_size() const
Get Size.
clan::SpanLayout::draw_layout_ellipsis
void draw_layout_ellipsis(Canvas &canvas, const Rect &content_rect)
Draw layout generating ellipsis for clipped text.
clan::Font
Font class.
Definition: font.h:53
clan::SpanLayout
Span layout class.
Definition: span_layout.h:60
clan::Size
2D (width,height) size structure - Integer
Definition: size.h:156
clan::SpanLayout::set_position
void set_position(const Point &pos)
Set position.
clan::SpanLayout::hide_cursor
void hide_cursor()
Hides the cursor caret.
clan::SpanLayout::get_first_baseline_offset
int get_first_baseline_offset()
Returns the baseline offset for the first baseline.
clan::SpanLayout::set_cursor_pos
void set_cursor_pos(std::string::size_type pos)
Sets the cursor position.
clan::StyleValueType::color
value is an url
clan::SpanLayout::find_preferred_size
Size find_preferred_size(Canvas &canvas)
Find preferred size.
clan::SpanLayout::draw_layout
void draw_layout(Canvas &canvas)
Draw layout.
clan::SpanLayout::get_rect
Rect get_rect() const
Get Rect.
clan::SpanLayout::HitTestResult::outside_bottom
Definition: span_layout.h:79
clan::SpanLayout::hit_test
HitTestResult hit_test(Canvas &canvas, const Point &pos)
Hit test.
clan::SpanLayout::SpanLayout
SpanLayout()
clan::span_justify
Definition: span_layout.h:56
clan::SpanLayout::HitTestResult::object_id
int object_id
Definition: span_layout.h:83
clan::SpanLayout::~SpanLayout
~SpanLayout()
clan::Key::end