HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
selection_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 "../label.hpp"
8#include <memory>
9#include <functional>
10#include <vector>
11
12namespace hi::inline v1 {
13class selection_widget;
14
16public:
17 virtual ~selection_delegate() = default;
18
19 virtual void init(selection_widget &sender) noexcept {}
20
21 virtual void deinit(selection_widget &sender) noexcept {}
22
25 auto subscribe(selection_widget& sender, callback_flags flags, std::invocable<> auto&& callback) noexcept
26 {
27 return _notifier.subscribe(flags, hi_forward(callback));
28 }
29
32 auto subscribe(selection_widget& sender, std::invocable<> auto&& callback) noexcept
33 {
34 return subscribe(sender, callback_flags::synchronous, hi_forward(callback));
35 }
36
40 virtual void set_selected(selection_widget &sender, ssize_t index) noexcept {};
41
45 {
46 return {{}, -1};
47 }
48
49protected:
50 notifier<> _notifier;
51};
52
53} // namespace hi::inline v1
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition required.hpp:29
A notifier which can be used to call a set of registered callbacks.
Definition notifier.hpp:24
Definition selection_delegate.hpp:15
virtual void set_selected(selection_widget &sender, ssize_t index) noexcept
Called when an option is selected by the user.
Definition selection_delegate.hpp:40
auto subscribe(selection_widget &sender, std::invocable<> auto &&callback) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition selection_delegate.hpp:32
virtual std::pair< std::vector< label >, ssize_t > options_and_selected(selection_widget const &sender) const noexcept
Retrieve the label of an option.
Definition selection_delegate.hpp:44
auto subscribe(selection_widget &sender, callback_flags flags, std::invocable<> auto &&callback) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition selection_delegate.hpp:25
A graphical control element that allows the user to choose only one of a predefined set of mutually e...
Definition selection_widget.hpp:37