lecui 1.0.0-alpha.20
lecui C++ user interface library
table_view.h
1//
2// table_view.h - table 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 table_view : public widget {
25 float _border = .5f;
26 float _grid_line = .5f;
27 color _color_border;
28 float _corner_radius_x = 2.f;
29 float _corner_radius_y = 2.f;
30 color _color_text_selected;
31 color _color_grid;
32 color _color_text_header;
33 color _color_text_header_hot;
34 color _color_fill_header;
35 color _color_fill_alternate;
36 color _color_row_hot;
37 color _color_row_selected;
38 std::vector<table_column> _columns;
39 std::vector<table_row> _data;
40 std::vector<long> _selected;
41 bool _user_sort = false;
42 bool _fixed_number_column = false;
43 std::string _fixed_number_column_name = "#";
44 void* _p_special_pane = nullptr;
45
46 public:
49 _rect.size({ 200.f, 200.f });
50 }
51
56 std::function<void(
57 const std::vector<table_row>& rows)>
58 selection = nullptr;
59
62 std::function<void(
63 const std::vector<table_row>& rows)>
64 context_menu = nullptr;
65 };
66
70 return _table_events;
71 }
72
77 bool operator==(const table_view& param);
78
83 bool operator!=(const table_view& param);
84
89
92 table_view(const table_view& param);
93
94 // generic widget
95
99 std::string& text() override;
100
105 table_view& text(const std::string& text);
106
110 std::string& tooltip() override;
111
116 table_view& tooltip(const std::string& tooltip);
117
121 lecui::rect& rect() override;
122
127
131
136
139 cursor_type& cursor() override;
140
145
148 std::string& font() override;
149
153 table_view& font(const std::string& font);
154
157 float& font_size() override;
158
162 table_view& font_size(const float& font_size);
163
166 color& color_text() override;
167
171 table_view& color_text(const color& color_text);
172
175 color& color_fill() override;
176
180 table_view& color_fill(const color& color_fill);
181
184 color& color_hot() override;
185
189 table_view& color_hot(const color& color_hot);
190
194
198 table_view& color_selected(const color& color_selected);
199
203
207 table_view& color_disabled(const color& color_disabled);
208
209 // widget specific widget
210
213 float& border();
214
218 table_view& border(const float& border);
219
222 float& grid_line();
223
227 table_view& grid_line(const float& grid_line);
228
232
236 table_view& color_border(const color& color_border);
237
241
245 table_view& corner_radius_x(const float& corner_radius_x);
246
250
254 table_view& corner_radius_y(const float& corner_radius_y);
255
259
263 table_view& color_text_selected(const color& color_text_selected);
264
268
272 table_view& color_grid(const color& color_grid);
273
277
281 table_view& color_text_header(const color& color_text_header);
282
286
290 table_view& color_text_header_hot(const color& color_text_header_hot);
291
295
299 table_view& color_fill_header(const color& color_fill_header);
300
305
310 table_view& color_fill_alternate(const color& color_fill_alternate);
311
315
319 table_view& color_row_hot(const color& color_row_hot);
320
324
328 table_view& color_row_selected(const color& color_row_selected);
329
336 std::vector<table_column>& columns();
337
345 table_view& columns(const std::vector<table_column>& columns);
346
361 std::vector<table_row>& data();
362
378 table_view& data(const std::vector<table_row>& data);
379
382 std::vector<long>& selected();
383
387 table_view& selected(const std::vector<long>& selected);
388
391 bool& user_sort();
392
396 table_view& user_sort(const bool& user_sort);
397
403
409 table_view& fixed_number_column(const bool& fixed_number_column);
410
414
418 table_view& fixed_number_column_name(const std::string& fixed_number_column_name);
419
420 public:
427 [[nodiscard]]
428 static table_view& add(containers::page& page, const std::string& alias = std::string());
429
436 [[nodiscard]]
437 static table_view& get(form& fm, const std::string& path);
438
444 void scroll_vertically(const float& amount);
445
451 void scroll_horizontally(const float& amount);
452
453 private:
455 table_view_events _table_events;
456
457#if defined(LECUI_EXPORTS)
458 friend class form;
459#endif
460 };
461 }
462 }
463}
464
465#if defined(lecui_helper)
467#define get_table_view(path) liblec::lecui::widgets::table_view::get(*this, path)
468#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
Context menu.
Definition: context_menu.h:47
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
Table view widget. To instantiate and add to a container use the add static method.
Definition: table_view.h:24
table_view & rect(const lecui::rect &rect)
Set the position and dimensions of the widget.
table_view & color_border(const color &color_border)
Set the color of the border.
table_view & color_text_header(const color &color_text_header)
Set the color of the header text.
float & corner_radius_y()
Get or set the vertical radius of the corners.
table_view & on_resize(const resize_params &on_resize)
Set the behaviour of the widget when its container is resized.
std::string & fixed_number_column_name()
Get or set the name of the fixed number column.
table_view & fixed_number_column_name(const std::string &fixed_number_column_name)
Set the name of the fixed number column.
resize_params & on_resize() override
Get or set the behaviour of the widget when its container is resized.
bool operator!=(const table_view &param)
Check whether widget specs are NOT equal. Only those properties that require the widget resources to ...
table_view & color_selected(const color &color_selected)
Set the widget's color when selected.
color & color_border()
Get or set the color of the border.
color & color_text_header_hot()
Get or set the color of the header text when the mouse is over it (if user sorting is allowed).
color & color_grid()
Get or set the color of the grid lines.
color & color_text_selected()
Get or set the color of the text in a selected row.
std::string & font() override
Get or set the default widget font, e.g. "Georgia".
bool operator==(const table_view &param)
Check whether widget specs are equal. Only those properties that require the widget resources to be r...
table_view & operator=(const table_view &param)
Copy table view specs. Only essential properties are copied.
table_view & color_row_hot(const color &color_row_hot)
Set the background color of a row when the mouse is over it.
table_view & font_size(const float &font_size)
Set the widget's font size.
color & color_text() override
Get or set the color of the widget's text.
table_view & fixed_number_column(const bool &fixed_number_column)
Set whether to add a fixed number column.
std::string & tooltip() override
Get or set the widget's tooltip text.
table_view & tooltip(const std::string &tooltip)
Set the tooltip text.
table_view & corner_radius_y(const float &corner_radius_y)
Set the vertical radius of the corners.
bool & fixed_number_column()
Get or set whether to add a fixed number column.
table_view & cursor(const cursor_type cursor)
Set the mouse cursor to use when over the widget.
color & color_fill() override
Get or set the fill color of the widget.
float & corner_radius_x()
Get or set the horizontal radius of the corners.
color & color_disabled() override
Get or set the widget's color when it is disabled.
table_view()
Constructor.
Definition: table_view.h:48
color & color_fill_alternate()
Get or set the table's alternate row color (used for the background of even rows).
lecui::rect & rect() override
Get or set the position and dimensions of the widget.
color & color_fill_header()
Get or set the table header's fill color.
table_view & data(const std::vector< table_row > &data)
Set the table's data. Each entry of the vector (a map) is a row and should mirror the column structur...
color & color_row_selected()
Get or set the background color of a selected row.
table_view & font(const std::string &font)
Set the default widget font.
table_view & grid_line(const float &grid_line)
Set the thickness of the grid-line.
static table_view & add(containers::page &page, const std::string &alias=std::string())
Add a table_view to a container.
color & color_hot() override
Get or set the widget's color when the mouse is hovered over it.
bool & user_sort()
Get or set whether to allow sorting by clicking columns.
color & color_text_header()
Get or set the color of the header text.
table_view & color_hot(const color &color_hot)
Set the widget's color when the mouse is hovered over it.
table_view & color_fill_alternate(const color &color_fill_alternate)
Set the table's alternate row color (used for the background of even rows).
cursor_type & cursor() override
Get or set the mouse cursor to use then over the widget.
void scroll_vertically(const float &amount)
Programmatically scroll the table vertically.
table_view & corner_radius_x(const float &corner_radius_x)
Set the horizontal radius of the corners.
table_view & color_fill_header(const color &color_fill_header)
Set the table header's fill color.
table_view & color_text_selected(const color &color_text_selected)
Set the color of the text in a selected row.
void scroll_horizontally(const float &amount)
Programmatically scroll the table horizontally.
table_view & user_sort(const bool &user_sort)
Set whether to allow sorting by clicking columns.
table_view & color_text_header_hot(const color &color_text_header_hot)
Set the color of the header text when the mouse is over it (if user sorting is allowed).
table_view & color_fill(const color &color_fill)
Set the fill color of the widget.
table_view_events & events()
Get or set table view events.
Definition: table_view.h:69
table_view & selected(const std::vector< long > &selected)
Set the rows to select by default, numbered from 0.
table_view & color_disabled(const color &color_disabled)
Set the widget's color when it is disabled.
std::vector< table_column > & columns()
Get or set the table view columns.
float & font_size() override
Get or set the default widget font size in points, e.g. 9.0f.
std::string & text() override
Get or set the widget text.
static table_view & get(form &fm, const std::string &path)
Get the specifications of a table_view.
std::vector< table_row > & data()
Get or set the table's data. Each entry of the vector (a map) is a row and should mirror the column s...
float & border()
Get or set the thickness of the border.
std::vector< long > & selected()
Get or set the rows to select by default, numbered from 0.
table_view & color_row_selected(const color &color_row_selected)
Set the background color of a selected row.
table_view & columns(const std::vector< table_column > &columns)
Set the table view columns.
color & color_selected() override
Get or set the widget's color when selected.
table_view(const table_view &param)
Copy constructor.
table_view & color_grid(const color &color_grid)
Set the color of the grid lines.
table_view & text(const std::string &text)
Set the widget's text.
float & grid_line()
Get or set the thickness of the grid-lines.
table_view & border(const float &border)
Set the thickness of the border.
table_view & color_text(const color &color_text)
Set the color of the widget's text.
color & color_row_hot()
Get or set the background color of a row when the mouse is over it.
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
Events specific to this widget.
Definition: table_view.h:53
Events common to all widgets.
Definition: widget.h:72