HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
abstract_radio_button_widget.hpp
1// Copyright Take Vos 2020.
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
9namespace tt {
10
14template<typename T>
16public:
18 using value_type = T;
19
20 template<typename Value = observable<value_type>>
24 value_type true_value,
25 Value &&value = {}) noexcept :
26 super(window, parent, std::move(true_value), std::forward<Value>(value))
27 {
28 _value_callback = this->value.subscribe([this](auto...) {
29 ttlet lock = std::scoped_lock(gui_system_mutex);
30 this->window.request_redraw(this->window_clipping_rectangle());
31 });
32 _callback = this->subscribe([this]() {
33 this->select();
34 });
35 }
36
39 void select() noexcept
40 {
41 ttlet lock = std::scoped_lock(gui_system_mutex);
42
43 if (compare_then_assign(this->value, this->true_value)) {
44 this->window.request_redraw(this->window_clipping_rectangle());
45 }
46 }
47
48private:
49 typename decltype(super::value)::callback_ptr_type _value_callback;
50 typename super::callback_ptr_type _callback;
51};
52
53} // namespace tt
Definition gui_window.hpp:39
void request_redraw(aarect rectangle=aarect::infinity()) noexcept
Request a rectangle on the window to be redrawn.
Definition gui_window.hpp:115
An abstract button widget.
Definition abstract_button_widget.hpp:16
callback_ptr_type subscribe(Callback &&callback) noexcept
Subscribe a callback to call when the button is activated.
Definition abstract_button_widget.hpp:109
An abstract radio button widget.
Definition abstract_radio_button_widget.hpp:15
void select() noexcept
Select this radio-button.
Definition abstract_radio_button_widget.hpp:39
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:100
abstract_container_widget const & parent() const noexcept
Get a reference to the parent.
virtual aarect window_clipping_rectangle() const noexcept
Get the clipping-rectangle in window coordinates.
Definition widget.hpp:320
T move(T... args)