span_layout.h Source File - ClanLib SDK
Description: span_layout.h Source File

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