HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
radio_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 hi::inline v1 {
11
39public:
41 using delegate_type = typename super::delegate_type;
42
50 template<typename Label>
51 radio_button_widget(gui_window &window, widget *parent, Label &&label, std::weak_ptr<delegate_type> delegate) noexcept :
52 radio_button_widget(window, parent, std::forward<Label>(label), weak_or_unique_ptr{std::move(delegate)})
53 {
54 }
55
67 template<typename Label, typename Value, typename... Args>
68 radio_button_widget(gui_window &window, widget *parent, Label &&label, Value &&value, Args &&...args) noexcept
69 requires(not std::is_convertible_v<Value, weak_or_unique_ptr<delegate_type>>) :
71 window,
72 parent,
73 std::forward<Label>(label),
74 make_unique_default_button_delegate<button_type::radio>(std::forward<Value>(value), std::forward<Args>(args)...))
75 {
76 }
77
79 widget_constraints const &set_constraints() noexcept override;
80 void set_layout(widget_layout const &layout) noexcept override;
81 void draw(draw_context const &context) noexcept override;
83private:
84 static constexpr std::chrono::nanoseconds _animation_duration = std::chrono::milliseconds(150);
85
86 extent2 _button_size;
87 aarectangle _button_rectangle;
88 animator<float> _animated_value = _animation_duration;
89 aarectangle _pip_rectangle;
90
91 template<typename Label>
92 radio_button_widget(gui_window &window, widget *parent, Label &&label, weak_or_unique_ptr<delegate_type> delegate) noexcept :
93 super(window, parent, std::move(delegate))
94 {
95 alignment = alignment::top_left();
96 set_label(std::forward<Label>(label));
97 }
98
99 void draw_radio_button(draw_context const &context) noexcept;
100 void draw_radio_pip(draw_context const &context) noexcept;
101};
102
103} // namespace hi::inline v1
button_type
The type of button.
Definition button_type.hpp:13
@ radio
A radio button.
STL namespace.
Definition alignment.hpp:64
A type that gets animated between two values.
Definition animator.hpp:17
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:52
Definition gui_window.hpp:39
A label consisting of localizable text and an icon.
Definition label.hpp:27
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
Definition button_delegate.hpp:14
A graphical control element that allows the user to choose only one of a predefined set of mutually e...
Definition radio_button_widget.hpp:38
radio_button_widget(gui_window &window, widget *parent, Label &&label, Value &&value, Args &&...args) noexcept
Construct a radio button widget with a default button delegate.
Definition radio_button_widget.hpp:68
radio_button_widget(gui_window &window, widget *parent, Label &&label, std::weak_ptr< delegate_type > delegate) noexcept
Construct a radio button widget.
Definition radio_button_widget.hpp:51
An interactive graphical object as part of the user-interface.
Definition widget.hpp:39
Definition widget_constraints.hpp:13
Definition widget_layout.hpp:18
T move(T... args)