HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
menu_button_widget.hpp
1// Copyright Take Vos 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 "abstract_button_widget.hpp"
8#include "default_button_delegate.hpp"
9
10namespace tt {
11
32public:
34 using delegate_type = typename super::delegate_type;
35 using callback_ptr_type = typename delegate_type::callback_ptr_type;
36
44 template<typename Label>
46 menu_button_widget(window, parent, std::forward<Label>(label), weak_or_unique_ptr{std::move(delegate)})
47 {
48 }
49
61 template<typename Label, typename Value, typename... Args>
62 menu_button_widget(gui_window &window, widget *parent, Label &&label, Value &&value, Args &&...args) noexcept
63 requires(not std::is_convertible_v<Value, weak_or_unique_ptr<delegate_type>>) :
65 window,
66 parent,
67 std::forward<Label>(label),
68 make_unique_default_button_delegate<button_type::radio>(std::forward<Value>(value), std::forward<Args>(args)...))
69 {
70 }
71
73 [[nodiscard]] float margin() const noexcept override;
74 [[nodiscard]] bool constrain(utc_nanoseconds display_time_point, bool need_reconstrain) noexcept override;
75 [[nodiscard]] void layout(utc_nanoseconds displayTimePoint, bool need_layout) noexcept override;
76 void draw(draw_context context, utc_nanoseconds display_time_point) noexcept override;
77 [[nodiscard]] bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept override;
78 [[nodiscard]] bool handle_event(command command) noexcept override;
80private:
81 font_glyph_ids _check_glyph;
82 extent2 _check_size;
83 aarectangle _check_rectangle;
84 aarectangle _check_glyph_rectangle;
85 extent2 _short_cut_size;
86 aarectangle _short_cut_rectangle;
87
88 template<typename Label>
89 menu_button_widget(gui_window &window, widget *parent, Label &&label, weak_or_unique_ptr<delegate_type> delegate) noexcept :
90 super(window, parent, std::move(delegate))
91 {
92 label_alignment = alignment::middle_left;
93 set_label(std::forward<Label>(label));
94 }
95
96 void draw_menu_button(draw_context const &context) noexcept;
97 void draw_check_mark(draw_context const &context) noexcept;
98};
99
100} // namespace tt
button_type
The type of button.
Definition button_type.hpp:13
@ radio
A radio button.
STL namespace.
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:28
Definition gui_window.hpp:39
A label consisting of localizable text and an icon.
Definition label.hpp:27
Definition font_glyph_ids.hpp:80
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
Definition abstract_button_widget.hpp:23
void set_label(Label const &rhs) noexcept
Set on/off/other labels of the button to the same value.
Definition abstract_button_widget.hpp:48
observable< alignment > label_alignment
The alignment of the on/off/other label.
Definition abstract_button_widget.hpp:43
Definition button_delegate.hpp:14
A button that is part of a menu.
Definition menu_button_widget.hpp:31
menu_button_widget(gui_window &window, widget *parent, Label &&label, std::weak_ptr< delegate_type > delegate) noexcept
Construct a menu button widget.
Definition menu_button_widget.hpp:45
menu_button_widget(gui_window &window, widget *parent, Label &&label, Value &&value, Args &&...args) noexcept
Construct a menu button widget with a default button delegate.
Definition menu_button_widget.hpp:62
An interactive graphical object as part of the user-interface.
Definition widget.hpp:37
widget *const parent
Pointer to the parent widget.
Definition widget.hpp:46
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:41
T move(T... args)