lecui 1.0.0-alpha.20
lecui C++ user interface library
tree_view.h
1//
2// tree_view.h - tree view widget interface
3//
4// lecui user interface library, part of the liblec library
5// Copyright (c) 2019 Alec Musasa (alecmus at live dot com)
6//
7// Released under the MIT license. For full details see the
8// file LICENSE.txt
9//
10
11#pragma once
12
13#if defined(LECUI_EXPORTS)
14#include "widget.h"
15#else
16#include <liblec/lecui/widgets/widget.h>
17#endif
18
19namespace liblec {
20 namespace lecui {
21 namespace widgets {
24 class lecui_api tree_view : public widget {
25 public:
27 class node {
28 public:
30 std::string name;
31
33 bool expand = false;
34
36 std::map<std::string, node> children;
37
40 node(std::string name) :
41 name(name) {}
42
43 private:
44 // Default constructor not allowed
45 node() {}
46
47 bool selected = false;
48 lecui::rect rc = { 0.f, 0.f, 0.f, 0.f };
49 lecui::rect rc_expand = { 0.f, 0.f, 0.f, 0.f };
50
51#if defined(LECUI_EXPORTS)
52 friend class widgets::tree_view_impl;
53#endif
54 };
55
56 private:
57 float _border = .5f;
58 color _color_border;
59 float _corner_radius_x = 5.f;
60 float _corner_radius_y = 5.f;
61 std::map<std::string, node> _root;
62 void* _p_special_pane_specs = nullptr;
63
64 public:
67 _rect.size({ 200.f, 200.f });
68 }
69
75 static node& insert_node(std::map<std::string, node>& root,
76 std::string name) {
77 root.insert(std::make_pair(name, node(name)));
78 return root.at(name);
79 }
80
85 std::function<void(node& n)> selection;
86 };
87
91 return _tree_events;
92 }
93
98 bool operator==(const tree_view& param);
99
104 bool operator!=(const tree_view& param);
105
110
113 tree_view(const tree_view& param);
114
115 // generic widget
116
120 std::string& text() override;
121
126 tree_view& text(const std::string& text);
127
131 std::string& tooltip() override;
132
137 tree_view& tooltip(const std::string& tooltip);
138
142 lecui::rect& rect() override;
143
148
152
157
160 cursor_type& cursor() override;
161
166
169 std::string& font() override;
170
174 tree_view& font(const std::string& font);
175
178 float& font_size() override;
179
183 tree_view& font_size(const float& font_size);
184
187 color& color_text() override;
188
192 tree_view& color_text(const color& color_text);
193
196 color& color_fill() override;
197
201 tree_view& color_fill(const color& color_fill);
202
205 color& color_hot() override;
206
210 tree_view& color_hot(const color& color_hot);
211
215
219 tree_view& color_selected(const color& color_selected);
220
224
228 tree_view& color_disabled(const color& color_disabled);
229
230 // widget specific widget
231
234 float& border();
235
239 tree_view& border(const float& border);
240
244
248 tree_view& color_border(const color& color_border);
249
253
257 tree_view& corner_radius_x(const float& corner_radius_x);
258
262
266 tree_view& corner_radius_y(const float& corner_radius_y);
267
271 std::map<std::string, node>& root();
272
276 tree_view& root(const std::map<std::string, node>& root);
277
278 public:
285 [[nodiscard]]
286 static tree_view& add(containers::page& page, const std::string& alias = std::string());
287
294 [[nodiscard]]
295 static tree_view& get(form& fm, const std::string& path);
296
297 private:
299 tree_view_events _tree_events;
300
301#if defined(LECUI_EXPORTS)
302 friend class form;
303#endif
304 };
305 }
306 }
307}
308
309#if defined(lecui_helper)
311#define get_tree_view(path) liblec::lecui::widgets::tree_view::get(*this, path)
312#endif
RGBA color on a standard 0 to 255 scale. For the alpha channel 0 is transparent and 255 is opaque.
Definition: lecui.h:583
Page container.
Definition: page.h:32
Form base class. The user must inherit from this class and call one of the two constructors from its ...
Definition: form.h:122
Rectangle class.
Definition: lecui.h:158
Resize parameters.
Definition: lecui.h:363
Tree node.
Definition: tree_view.h:27
std::map< std::string, node > children
The node's children.
Definition: tree_view.h:36
node(std::string name)
Node constructor.
Definition: tree_view.h:40
std::string name
The name of the node.
Definition: tree_view.h:30
Tree view widget. To create an instance use the add static method.
Definition: tree_view.h:24
cursor_type & cursor() override
Get or set the mouse cursor to use then over the widget.
tree_view & color_fill(const color &color_fill)
Set the fill color of the widget.
tree_view & text(const std::string &text)
Set the widget's text.
static node & insert_node(std::map< std::string, node > &root, std::string name)
Helper for inserting a node.
Definition: tree_view.h:75
float & corner_radius_x()
Get or set the horizontal radius of the corners.
tree_view & color_hot(const color &color_hot)
Set the widget's color when the mouse is hovered over it.
color & color_border()
Get or set the color of the border.
color & color_selected() override
Get or set the widget's color when selected.
resize_params & on_resize() override
Get or set the behaviour of the widget when its container is resized.
color & color_disabled() override
Get or set the widget's color when it is disabled.
tree_view_events & events()
Get or set tree view widget events.
Definition: tree_view.h:90
tree_view & corner_radius_x(const float &corner_radius_x)
Set the horizontal radius of the corners.
tree_view & color_border(const color &color_border)
Set the color of the border.
color & color_hot() override
Get or set the widget's color when the mouse is hovered over it.
float & font_size() override
Get or set the default widget font size in points, e.g. 9.0f.
std::map< std::string, node > & root()
Get or set the root of the tree.
lecui::rect & rect() override
Get or set the position and dimensions of the widget.
tree_view & font_size(const float &font_size)
Set the widget's font size.
std::string & text() override
Get or set the widget text.
std::string & font() override
Get or set the default widget font, e.g. "Georgia".
color & color_fill() override
Get or set the fill color of the widget.
color & color_text() override
Get or set the color of the widget's text.
float & corner_radius_y()
Get or set the vertical radius of the corners.
tree_view & on_resize(const resize_params &on_resize)
Set the behaviour of the widget when its container is resized.
tree_view & border(const float &border)
Set the thickness of the border.
tree_view & cursor(const cursor_type cursor)
Set the mouse cursor to use when over the widget.
std::string & tooltip() override
Get or set the widget's tooltip text.
tree_view & rect(const lecui::rect &rect)
Set the position and dimensions of the widget.
tree_view & tooltip(const std::string &tooltip)
Set the tooltip text.
static tree_view & add(containers::page &page, const std::string &alias=std::string())
Add a tree view to a container.
static tree_view & get(form &fm, const std::string &path)
Get the specifications of a tree view.
tree_view & color_text(const color &color_text)
Set the color of the widget's text.
float & border()
Get or set the thickness of the border.
bool operator==(const tree_view &param)
Check whether widget specs are equal. Only those properties that require the widget resources to be r...
tree_view & root(const std::map< std::string, node > &root)
Set the root of the tree.
tree_view & corner_radius_y(const float &corner_radius_y)
Set the vertical radius of the corners.
tree_view & operator=(const tree_view &param)
Copy tree view specs. Only essential properties are copied.
bool operator!=(const tree_view &param)
Check whether widget specs are NOT equal. Only those properties that require the widget resources to ...
tree_view & color_selected(const color &color_selected)
Set the widget's color when selected.
tree_view(const tree_view &param)
Copy constructor.
tree_view()
Constructor.
Definition: tree_view.h:66
tree_view & color_disabled(const color &color_disabled)
Set the widget's color when it is disabled.
tree_view & font(const std::string &font)
Set the default widget font.
Base class for all widgets.
Definition: widget.h:24
cursor_type
Mouse cursor type.
Definition: widget.h:27
Top level namespace for the liblec libraries.
Definition: appearance.h:19
Tree view widget events.
Definition: tree_view.h:82
std::function< void(node &n)> selection
Selection event. Happens when the selection changes. The parameter will contain a reference to the ne...
Definition: tree_view.h:85
Events common to all widgets.
Definition: widget.h:72