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 tt {
12class abstract_button_widget;
13
15public:
17
18 virtual ~button_delegate() = default;
19
20 virtual void init(abstract_button_widget &sender) noexcept {}
21
22 virtual void deinit(abstract_button_widget &sender) noexcept {}
23
26 virtual callback_ptr_type subscribe(abstract_button_widget &sender, callback_ptr_type const &callback) noexcept
27 {
28 return callback;
29 }
30
33 template<typename Callback>
34 requires(std::is_invocable_v<Callback>) [[nodiscard]] callback_ptr_type
35 subscribe(abstract_button_widget &sender, Callback &&callback) noexcept
36 {
37 return subscribe(sender, std::make_shared<std::function<void()>>(std::forward<Callback>(callback)));
38 }
39
42 virtual void unsubscribe(abstract_button_widget &sender, callback_ptr_type const &callback) noexcept {}
43
46 virtual void activate(abstract_button_widget &sender) noexcept {};
47
50 [[nodiscard]] virtual button_state state(abstract_button_widget const &sender) const noexcept
51 {
52 return button_state::off;
53 }
54};
55
56} // namespace tt
button_state
The state of a button.
Definition button_state.hpp:13
Definition abstract_button_widget.hpp:23
Definition button_delegate.hpp:14
callback_ptr_type subscribe(abstract_button_widget &sender, Callback &&callback) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition button_delegate.hpp:35
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:50
virtual void unsubscribe(abstract_button_widget &sender, callback_ptr_type const &callback) noexcept
Unsubscribe a callback.
Definition button_delegate.hpp:42
virtual callback_ptr_type subscribe(abstract_button_widget &sender, callback_ptr_type const &callback) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition button_delegate.hpp:26
virtual void activate(abstract_button_widget &sender) noexcept
Called when the button is pressed by the user.
Definition button_delegate.hpp:46
T make_shared(T... args)