HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
button_delegate.hpp
Go to the documentation of this file.
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
9#pragma once
10
11#include "../notifier.hpp"
12#include "../observer.hpp"
13#include "../GUI/module.hpp"
14#include <type_traits>
15#include <memory>
16
17namespace hi { inline namespace v1 {
18class widget;
19
24public:
25 using notifier_type = notifier<>;
26 using callback_token = notifier_type::callback_token;
27 using callback_proto = notifier_type::callback_proto;
28
29 virtual ~button_delegate() = default;
30
31 virtual void init(widget& sender) noexcept {}
32
33 virtual void deinit(widget& sender) noexcept {}
34
37 virtual void activate(widget& sender) noexcept {};
38
41 [[nodiscard]] virtual widget_state state(widget const& sender) const noexcept
42 {
43 return widget_state::off;
44 }
45
48 [[nodiscard]] callback_token
49 subscribe(forward_of<callback_proto> auto&& callback, callback_flags flags = callback_flags::synchronous) noexcept
50 {
51 return _notifier.subscribe(hi_forward(callback), flags);
52 }
53
54protected:
55 notifier_type _notifier;
56};
57
58
59}} // namespace hi::v1
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
widget_state
Definition widget_state.hpp:14
@ off
The widget in the off-state.
Definition widget.hpp:26
A button delegate controls the state of a button widget.
Definition button_delegate.hpp:23
callback_token subscribe(forward_of< callback_proto > auto &&callback, callback_flags flags=callback_flags::synchronous) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition button_delegate.hpp:49
virtual widget_state state(widget const &sender) const noexcept
Used by the widget to check the state of the button.
Definition button_delegate.hpp:41
virtual void activate(widget &sender) noexcept
Called when the button is pressed by the user.
Definition button_delegate.hpp:37