span_layout.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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
36namespace 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 {
62 public:
65
67 {
69
70 enum class Type
71 {
77 inside
79
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
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
180
183
187 void set_cursor_pos(std::string::size_type pos);
188
192 void set_cursor_overwrite_mode(bool enable);
193
198
202 std::string get_combined_text() const;
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}
2D Graphics Canvas
Definition: canvas.h:72
Floating point color description class (for float).
Definition: color.h:799
Font class.
Definition: font.h:60
Image class.
Definition: image.h:59
2D (x,y) point structure - Integer
Definition: point.h:62
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:489
2D (width,height) size structure - Integer
Definition: size.h:171
Span layout class.
Definition: span_layout.h:61
Size find_preferred_size(Canvas &canvas)
Find preferred size.
HitTestResult hit_test(Canvas &canvas, const Point &pos)
Hit test.
int get_last_baseline_offset()
Returns the baseline offset for the last baseline.
void set_selection_colors(const Colorf &foreground, const Colorf &background)
Set selection colors.
void set_cursor_color(const Colorf &color)
Sets the cursor color.
void layout(Canvas &canvas, int max_width)
Layout.
void clear()
Clear.
std::vector< Rect > get_rect_by_id(int id) const
Get Rect By Id.
void set_selection_range(std::string::size_type start, std::string::size_type end)
Set selection range.
Size get_size() const
Get Size.
void set_cursor_overwrite_mode(bool enable)
Toggles whether the cursor caret is shown as a solid box or a line.
void hide_cursor()
Hides the cursor caret.
int get_first_baseline_offset()
Returns the baseline offset for the first baseline.
void show_cursor()
Shows the cursor caret.
void set_component_geometry()
Set component geometry.
void add_text(const std::string &text, const Font &font, const Colorf &color=StandardColorf::white(), int id=-1)
Add text.
Rect get_rect() const
Get Rect.
void set_align(SpanAlign align)
Sets the text alignment.
void set_cursor_pos(std::string::size_type pos)
Sets the cursor position.
void set_position(const Point &pos)
Set position.
std::string get_combined_text() const
Get Combined text.
void draw_layout_ellipsis(Canvas &canvas, const Rect &content_rect)
Draw layout generating ellipsis for clipped text.
void add_image(const Image &image, int baseline_offset=0, int id=-1)
Add image.
void add_component(T *component, int baseline_offset=0, int id=-1)
Add component.
void draw_layout(Canvas &canvas)
Draw layout.
static Colorf white()
Definition: color.h:1884
SpanAlign
Span Align.
Definition: span_layout.h:52
@ span_right
Definition: span_layout.h:54
@ span_justify
Definition: span_layout.h:56
@ span_center
Definition: span_layout.h:55
@ span_left
Definition: span_layout.h:53
Definition: clanapp.h:36
@ color
value is an url
Definition: span_layout.h:67
int object_id
Definition: span_layout.h:80
enum clan::SpanLayout::HitTestResult::Type type
Type
Definition: span_layout.h:71
int offset
Definition: span_layout.h:81
HitTestResult()
Definition: span_layout.h:68