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, std::invocable<> auto &&callback) noexcept
25 {
26 return _notifier.subscribe(hi_forward(callback));
27 }
28
31 virtual void activate(abstract_button_widget &sender) noexcept {};
32
35 [[nodiscard]] virtual button_state state(abstract_button_widget const &sender) const noexcept
36 {
37 return button_state::off;
38 }
39
40protected:
41 notifier<> _notifier;
42};
43
44} // 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:23
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:35
virtual void activate(abstract_button_widget &sender) noexcept
Called when the button is pressed by the user.
Definition button_delegate.hpp:31
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:24