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 void init(abstract_button_widget &sender) noexcept {}
19
20 virtual void deinit(abstract_button_widget &sender) noexcept {}
21
24 virtual callback_ptr_type subscribe(abstract_button_widget &sender, callback_ptr_type const &callback) noexcept
25 {
26 return callback;
27 }
28
31 template<typename Callback>
32 requires(std::is_invocable_v<Callback>) [[nodiscard]] callback_ptr_type
33 subscribe(abstract_button_widget &sender, Callback &&callback) noexcept
34 {
35 return subscribe(sender, std::make_shared<std::function<void()>>(std::forward<Callback>(callback)));
36 }
37
40 virtual void unsubscribe(abstract_button_widget &sender, callback_ptr_type const &callback) noexcept {}
41
44 virtual void activate(abstract_button_widget &sender) noexcept {};
45
48 [[nodiscard]] virtual button_state state(abstract_button_widget const &sender) const noexcept
49 {
50 return button_state::off;
51 }
52};
53
54} // 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:33
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:48
virtual void unsubscribe(abstract_button_widget &sender, callback_ptr_type const &callback) noexcept
Unsubscribe a callback.
Definition button_delegate.hpp:40
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:24
virtual void activate(abstract_button_widget &sender) noexcept
Called when the button is pressed by the user.
Definition button_delegate.hpp:44
T make_shared(T... args)