HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
selection_widget.hpp
1// Copyright Take Vos 2020-2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "widget.hpp"
8#include "label_widget.hpp"
9#include "overlay_widget.hpp"
10#include "scroll_widget.hpp"
11#include "row_column_widget.hpp"
12#include "menu_button_widget.hpp"
13#include "selection_delegate.hpp"
14#include "default_selection_delegate.hpp"
15#include "../observable.hpp"
16#include "../weak_or_unique_ptr.hpp"
17#include <memory>
18#include <string>
19#include <array>
20#include <optional>
21#include <future>
22
23namespace tt {
24
37class selection_widget final : public widget {
38public:
39 using super = widget;
41
42 observable<label> unknown_label;
43
51
63 template<typename OptionList, typename Value, typename... Args>
64 selection_widget(gui_window &window, widget *parent, OptionList &&option_list, Value &&value, Args &&...args) noexcept
65 requires(not std::is_convertible_v<Value, weak_or_unique_ptr<delegate_type>>) :
67 window,
68 parent,
69 make_unique_default_selection_delegate(
70 std::forward<OptionList>(option_list),
71 std::forward<Value>(value),
72 std::forward<Args>(args)...))
73 {
74 }
75
77 void init() noexcept override;
78 void deinit() noexcept override;
79 [[nodiscard]] bool constrain(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept override;
80 [[nodiscard]] void layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept override;
81 void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept override;
82 bool handle_event(mouse_event const &event) noexcept override;
83 bool handle_event(command command) noexcept override;
84 [[nodiscard]] hitbox hitbox_test(point2 position) const noexcept override;
85 [[nodiscard]] bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept override;
86 [[nodiscard]] color focus_color() const noexcept override;
88private:
89 weak_or_unique_ptr<delegate_type> _delegate;
90
91 typename delegate_type::callback_ptr_type _delegate_callback;
92 typename decltype(unknown_label)::callback_ptr_type _unknown_label_callback;
93
94 label_widget *_current_label_widget = nullptr;
95 label_widget *_unknown_label_widget = nullptr;
96
97 aarectangle _option_rectangle;
98 aarectangle _left_box_rectangle;
99
100 font_glyph_ids _chevrons_glyph;
101 aarectangle _chevrons_rectangle;
102
103 bool _selecting = false;
104 bool _has_options = false;
105
106 overlay_widget *_overlay_widget = nullptr;
107 vertical_scroll_widget<> *_scroll_widget = nullptr;
108 column_widget *_column_widget = nullptr;
109
110 std::vector<menu_button_widget *> _menu_button_widgets;
111 std::vector<typename menu_button_widget::callback_ptr_type> _menu_button_callbacks;
112
113 selection_widget(gui_window &window, widget *parent, weak_or_unique_ptr<delegate_type> delegate) noexcept;
114 [[nodiscard]] menu_button_widget const *get_first_menu_button() const noexcept;
115 [[nodiscard]] menu_button_widget const *get_selected_menu_button() const noexcept;
116 void start_selecting() noexcept;
117 void stop_selecting() noexcept;
118 void repopulate_options() noexcept;
119 void draw_outline(draw_context context) noexcept;
120 void draw_left_box(draw_context context) noexcept;
121 void draw_chevrons(draw_context context) noexcept;
122};
123
124} // namespace tt
STL namespace.
This is a RGBA floating point color.
Definition color.hpp:36
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:29
Definition gui_window.hpp:36
Definition hitbox.hpp:14
Definition mouse_event.hpp:15
Timestamp.
Definition hires_utc_clock.hpp:19
An observable value.
Definition observable.hpp:280
Definition font_glyph_ids.hpp:78
Class that hold either a weak_ptr or a unique_ptr This class is to hold a weak_ptr,...
Definition weak_or_unique_ptr.hpp:25
The GUI widget displays and lays out text together with an icon.
Definition label_widget.hpp:32
A button that is part of a menu.
Definition menu_button_widget.hpp:31
A GUI widget which may exist anywhere on a window overlaid above any other widget.
Definition overlay_widget.hpp:34
A row/column widget lays out child widgets along a row or column.
Definition row_column_widget.hpp:37
The scroll widget allows a content widget to be shown in less space than is required.
Definition scroll_widget.hpp:43
Definition selection_delegate.hpp:15
A graphical control element that allows the user to choose only one of a predefined set of mutually e...
Definition selection_widget.hpp:37
selection_widget(gui_window &window, widget *parent, std::weak_ptr< delegate_type > delegate) noexcept
Construct a selection widget with a delegate.
selection_widget(gui_window &window, widget *parent, OptionList &&option_list, Value &&value, Args &&...args) noexcept
Construct a selection widget which will monitor an option list and a value.
Definition selection_widget.hpp:64
An interactive graphical object as part of the user-interface.
Definition widget.hpp:39
widget *const parent
Pointer to the parent widget.
Definition widget.hpp:48
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:43
widget(gui_window &window, widget *parent) noexcept