HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
button_delegate.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 "button_state.hpp"
8#include <memory>
9#include <functional>
10
11namespace hi::inline v1 {
12class abstract_button_widget;
13
15public:
16 virtual ~button_delegate() = default;
17
18 virtual void init(abstract_button_widget &sender) noexcept {}
19
20 virtual void deinit(abstract_button_widget &sender) noexcept {}
21
24 [[nodiscard]] auto subscribe(abstract_button_widget &sender, callback_flags flags, std::invocable<> auto &&callback) noexcept
25 {
26 return _notifier.subscribe(flags, hi_forward(callback));
27 }
28
31 [[nodiscard]] auto subscribe(abstract_button_widget& sender, std::invocable<> auto&& callback) noexcept
32 {
33 return subscribe(sender, callback_flags::synchronous, hi_forward(callback));
34 }
35
38 virtual void activate(abstract_button_widget &sender) noexcept {};
39
42 [[nodiscard]] virtual button_state state(abstract_button_widget const &sender) const noexcept
43 {
44 return button_state::off;
45 }
46
47protected:
48 notifier<> _notifier;
49};
50
51} // namespace hi::inline v1
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition required.hpp:29
button_state
The state of a button.
Definition button_state.hpp:13
A notifier which can be used to call a set of registered callbacks.
Definition notifier.hpp:24
Definition abstract_button_widget.hpp:23
Definition button_delegate.hpp:14
virtual button_state state(abstract_button_widget const &sender) const noexcept
Used by the widget to check the state of the button.
Definition button_delegate.hpp:42
virtual void activate(abstract_button_widget &sender) noexcept
Called when the button is pressed by the user.
Definition button_delegate.hpp:38
auto subscribe(abstract_button_widget &sender, std::invocable<> auto &&callback) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition button_delegate.hpp:31
auto subscribe(abstract_button_widget &sender, callback_flags flags, std::invocable<> auto &&callback) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition button_delegate.hpp:24