lecui 1.0.0-alpha.20
lecui C++ user interface library
combobox.h
1//
2// combobox.h - combobox 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 combobox : public widget {
25 public:
28 std::string label;
29 std::string font = "Segoe UI";
30 float font_size = 9.f;
31 };
32
33 private:
34 bool _editable = false;
35 color _color_fill_editable;
36 color _color_caret;
37 color _color_border;
38 color _color_dropdown;
39 color _color_dropdown_hot;
40 color _color_dropdown_arrow;
41 color _color_dropdown_arrow_hot;
42 float _border = .5f;
43 float _corner_radius_x = 2.f;
44 float _corner_radius_y = 2.f;
45 std::vector<combobox_item> _items;
48 bool _force_numerical_sort = false;
49 std::string _selected;
50
51 public:
54 _rect.size({ 200.f, 25.f });
55 }
56
61 std::function<void(const std::string&)> selection = nullptr;
62 };
63
67 return _combobox_events;
68 }
69
74 bool operator==(const combobox& param);
75
80 bool operator!=(const combobox& param);
81
82 // generic widget
83
86 std::string& text() override;
87
91 combobox& text(const std::string& text);
92
95 std::string& tooltip() override;
96
100 combobox& tooltip(const std::string& tooltip);
101
105 lecui::rect& rect() override;
106
111
115
119 combobox& on_resize(const resize_params& on_resize);
120
123 cursor_type& cursor() override;
124
129
132 std::string& font() override;
133
137 combobox& font(const std::string& font);
138
141 float& font_size() override;
142
146 combobox& font_size(const float& font_size);
147
150 color& color_text() override;
151
155 combobox& color_text(const color& color_text);
156
159 color& color_fill() override;
160
164 combobox& color_fill(const color& color_fill);
165
168 color& color_hot() override;
169
173 combobox& color_hot(const color& color_hot);
174
178
182 combobox& color_selected(const color& color_selected);
183
187
191 combobox& color_disabled(const color& color_disabled);
192
193 // widget specific widget
194
197 float& border();
198
202 combobox& border(const float& border);
203
207
211 combobox& color_border(const color& color_border);
212
216
220 combobox& corner_radius_x(const float& corner_radius_x);
221
225
229 combobox& corner_radius_y(const float& corner_radius_y);
230
233 bool& editable();
234
238 combobox& editable(const bool& editable);
239
243
246 combobox& color_fill_editable(const color& color_fill_editable);
247
251
255 combobox& color_caret(const color& color_caret);
256
260
264 combobox& color_dropdown(const color& color_dropdown);
265
269
273 combobox& color_dropdown_hot(const color& color_dropdown_hot);
274
278
282 combobox& color_dropdown_arrow(const color& color_dropdown_arrow);
283
287
291 combobox& color_dropdown_arrow_hot(const color& color_dropdown_arrow_hot);
292
295 std::vector<combobox_item>& items();
296
300 combobox& items(const std::vector<combobox_item>& items);
301
305
310
313 sort_options& sort() { return _sort; }
314
319
328
337 combobox& force_numerical_sort(const bool& force_numerical_sort);
338
345 std::string& selected();
346
350 combobox& selected(const std::string& selected);
351
352 public:
359 [[nodiscard]]
360 static combobox& add(containers::page& page, const std::string& alias = std::string());
361
368 [[nodiscard]]
369 static combobox& get(form& fm, const std::string& path);
370
371 private:
373 combobox_events _combobox_events;
374 };
375 }
376 }
377}
378
379#if defined(lecui_helper)
381#define get_combobox(path) liblec::lecui::widgets::combobox::get(*this, path)
382#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
Combobox widget. To instantiate and add to a container use the add static method.
Definition: combobox.h:24
combobox & color_disabled(const color &color_disabled)
Set the widget's color when it is disabled.
bool & editable()
Get or set the combobox editable property.
float & border()
Get or set the thickness of the border.
combobox & rect(const lecui::rect &rect)
Set the position and dimensions of the widget.
combobox & color_text(const color &color_text)
Set the color of the widget's text.
color & color_fill_editable()
Get or set the fill color of an editable combobox.
lecui::rect & rect() override
Get or set the position and dimensions of the widget.
combobox & corner_radius_x(const float &corner_radius_x)
Set the horizontal radius of the corners.
combobox & color_border(const color &color_border)
Set the color of the border.
color & color_dropdown_arrow()
Get or set the color of the dropdown arrow.
combobox()
Constructor.
Definition: combobox.h:53
combobox & editable(const bool &editable)
Set the combobox editable property.
color & color_hot() override
Get or set the widget's color when the mouse is hovered over it.
combobox & color_hot(const color &color_hot)
Set the widget's color when the mouse is hovered over it.
combobox & color_selected(const color &color_selected)
Set the widget's color when selected.
combobox & color_dropdown_arrow_hot(const color &color_dropdown_arrow_hot)
Set the color of the dropdown arrow when the mouse is hovered over it.
combobox & color_caret(const color &color_caret)
Set the color of the caret.
combobox & tooltip(const std::string &tooltip)
Set the tooltip text.
color & color_border()
Get or set the color of the border.
combobox & corner_radius_y(const float &corner_radius_y)
Set the vertical radius of the corners.
color & color_dropdown_arrow_hot()
Get or set the color of the dropdown arrow when the mouse is hovered over it.
resize_params & on_resize() override
Get or set the behaviour of the widget when its container is resized.
color & color_text() override
Get or set the color of the widget's text.
combobox & font(const std::string &font)
Set the default widget font.
combobox & quality(const image_quality &quality)
Set the quality of the images.
std::string & selected()
Get or set the selected item.
float & font_size() override
Get or set the default widget font size in points, e.g. 9.0f.
combobox_events & events()
Get or set combobox events.
Definition: combobox.h:66
combobox & color_dropdown(const color &color_dropdown)
Set the color of the dropdown.
combobox & items(const std::vector< combobox_item > &items)
Set the list of combobox items.
combobox & on_resize(const resize_params &on_resize)
Set the behaviour of the widget when its container is resized.
combobox & border(const float &border)
Set the thickness of the border.
color & color_caret()
Get or set the color of the caret.
combobox & text(const std::string &text)
Set the widget's text.
static combobox & add(containers::page &page, const std::string &alias=std::string())
Add a combobox to a container.
combobox & font_size(const float &font_size)
Set the widget's font size.
bool operator==(const combobox &param)
Check whether widget specs are equal. Only those properties that require the widget resources to be r...
color & color_selected() override
Get or set the widget's color when selected.
cursor_type & cursor() override
Get or set the mouse cursor to use then over the widget.
combobox & color_dropdown_arrow(const color &color_dropdown_arrow)
Set the color of the dropdown arrow.
combobox & color_fill(const color &color_fill)
Set the fill color of the widget.
combobox & color_dropdown_hot(const color &color_dropdown_hot)
Set the color of the dropdown when the mouse is hovered over it.
combobox & force_numerical_sort(const bool &force_numerical_sort)
Set whether numerical sorting is forced.
sort_options & sort()
Get or set the sort options.
Definition: combobox.h:313
combobox & sort(const sort_options &sort)
Set the sort options.
color & color_disabled() override
Get or set the widget's color when it is disabled.
color & color_dropdown_hot()
Get or set the color of the dropdown when the mouse is hovered over it.
bool operator!=(const combobox &param)
Check whether widget specs are NOT equal. Only those properties that require the widget resources to ...
color & color_fill() override
Get or set the fill color of the widget.
image_quality & quality()
Get or set the quality of the images.
float & corner_radius_x()
Get or set the horizontal radius of the corners.
static combobox & get(form &fm, const std::string &path)
Get the specifications of a combobox.
bool & force_numerical_sort()
Get or set whether numerical sorting is forced.
std::string & tooltip() override
Get or set the widget's tooltip text.
float & corner_radius_y()
Get or set the vertical radius of the corners.
combobox & cursor(const cursor_type cursor)
Set the mouse cursor to use when over the widget.
std::string & text() override
Get or set the widget text.
std::string & font() override
Get or set the default widget font, e.g. "Georgia".
std::vector< combobox_item > & items()
Get or set the list of combobox items.
combobox & color_fill_editable(const color &color_fill_editable)
Set the fill color of an editable combobox.
color & color_dropdown()
Get or set the color of the dropdown.
combobox & selected(const std::string &selected)
Set the selected item.
Base class for all widgets.
Definition: widget.h:24
cursor_type
Mouse cursor type.
Definition: widget.h:27
image_quality
Image render quality. Used when resampling images.
Definition: lecui.h:916
@ high
High image quality, for best image quality possibly at the cost of rendering speed.
sort_options
Sort options.
Definition: lecui.h:679
@ ascending
Sort in ascending order.
Top level namespace for the liblec libraries.
Definition: appearance.h:19
Events specific to this widget.
Definition: combobox.h:58
A combobox item.
Definition: combobox.h:27
std::string label
The label of the item.
Definition: combobox.h:28
Events common to all widgets.
Definition: widget.h:72