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"
20hi_export_module(hikogui.widgets.async_delegate);
22hi_export
namespace hi {
51 return widget_value::off;
56 template<forward_of<
void()> Func>
59 return _notifier.subscribe(std::forward<Func>(
func), flags);
63 notifier<
void()> _notifier;
74template<
typename ResultType =
void>
88 template<
typename Func,
typename...
Args>
90 _task_controller(std::forward<Func>(
func), std::forward<Args>(
args)...)
92 _task_controller_cbt = _task_controller.
subscribe([
this] {
101 return widget_value::other;
103 }
else if (_task_controller.
running()) {
104 return widget_value::on;
107 return widget_value::off;
116 void activate(widget_intf
const&
sender)
noexcept override
122 _task_controller.
run();
132 task_controller<result_type> _task_controller;
137using default_async_delegate_result_type =
140template<
typename F,
typename...
Args>
141default_async_delegate(F&&
func,
Args&&...
args) -> default_async_delegate<default_async_delegate_result_type<F,
Args...>>;
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
cancel_features_type
Features of an invocable.
Definition async_task.hpp:71
@ none
This invocable does not have extra arguments.
@ stop_and_progress
The extra arguments are a std::stop_token, followed by a hi::progress_token.
@ stop
The extra argument is a std::stop_token.
auto cancelable_async_task(Func func, std::stop_token stop_token, ::hi::progress_token progress_token, Args... args)
Run a function asynchronously as a co-routine task.
Definition async_task.hpp:197
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
Definition callback.hpp:77
void run()
Run the assigned coroutine or function with the previous given arguments.
Definition task_controller.hpp:200
hi::notifier ::callback_type subscribe(Callback &&callback, callback_flags flags=callback_flags::synchronous)
Register a callback to be called when a coroutine or function reports progress.
Definition task_controller.hpp:239
bool request_stop() noexcept
Request stop.
Definition task_controller.hpp:211
bool runnable() const noexcept
Check if a function is assigned.
Definition task_controller.hpp:148
bool running() const noexcept
Check if the function is currently running.
Definition task_controller.hpp:165
cancel_features_type features() const noexcept
The features of the coroutine or function that was assigned.
Definition task_controller.hpp:137
Definition widget_intf.hpp:24
A button delegate controls the state of a button widget.
Definition async_delegate.hpp:28
virtual cancel_features_type features() const noexcept
Used by the widget to determine if it can stop.
Definition async_delegate.hpp:42
virtual widget_value state(widget_intf const &sender) const noexcept
Used by the widget to check the state of the button.
Definition async_delegate.hpp:49
callback< void()> subscribe(Func &&func, callback_flags flags=callback_flags::synchronous) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition async_delegate.hpp:57
virtual void activate(widget_intf const &sender) noexcept
Called when the button is pressed by the user.
Definition async_delegate.hpp:38
A default async button delegate.
Definition async_delegate.hpp:75
default_async_delegate(Func &&func, Args &&... args) noexcept
Construct a delegate.
Definition async_delegate.hpp:89