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 "../observer/observer.hpp"
12#include "../utility/utility.hpp"
13#include "../concurrency/concurrency.hpp"
14#include "../dispatch/dispatch.hpp"
15#include "../GUI/GUI.hpp"
16#include "../macros.hpp"
17#include <type_traits>
18#include <memory>
19
20hi_export_module(hikogui.widgets.button_delegate);
21
22hi_export namespace hi {
23inline namespace v1 {
24
29public:
30 virtual ~button_delegate() = default;
31
32 virtual void init(widget_intf const& sender) noexcept {}
33
34 virtual void deinit(widget_intf const& sender) noexcept {}
35
38 virtual void activate(widget_intf const& sender) noexcept {}
39
42 [[nodiscard]] virtual widget_value state(widget_intf const& sender) const noexcept
43 {
44 return widget_value::off;
45 }
46
49 template<forward_of<void()> Func>
50 [[nodiscard]] callback<void()> subscribe(Func&& func, callback_flags flags = callback_flags::synchronous) noexcept
51 {
52 return _notifier.subscribe(std::forward<Func>(func), flags);
53 }
54
55protected:
56 notifier<void()> _notifier;
57};
58
59
60
61
62} // namespace v1
63} // namespace hi::v1
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition callback.hpp:77
Definition widget_intf.hpp:24
A button delegate controls the state of a button widget.
Definition button_delegate.hpp:28
virtual void activate(widget_intf const &sender) noexcept
Called when the button is pressed by the user.
Definition button_delegate.hpp:38
virtual widget_value state(widget_intf const &sender) const noexcept
Used by the widget to check the state of the button.
Definition button_delegate.hpp:42
callback< void()> subscribe(Func &&func, callback_flags flags=callback_flags::synchronous) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition button_delegate.hpp:50