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 tt {
13class selection_widget;
14
16public:
18
19 virtual ~selection_delegate() = default;
20
21 virtual void init(selection_widget &sender) noexcept {}
22
23 virtual void deinit(selection_widget &sender) noexcept {}
24
27 virtual callback_ptr_type subscribe(selection_widget &sender, callback_ptr_type const &callback) noexcept
28 {
29 return callback;
30 }
31
34 template<typename Callback>
35 requires(std::is_invocable_v<Callback>) [[nodiscard]] callback_ptr_type
36 subscribe(selection_widget &sender, Callback &&callback) noexcept
37 {
38 return subscribe(sender, std::make_shared<std::function<void()>>(std::forward<Callback>(callback)));
39 }
40
43 virtual void unsubscribe(selection_widget &sender, callback_ptr_type const &callback) noexcept {}
44
48 virtual void set_selected(selection_widget &sender, ssize_t index) noexcept {};
49
53 {
54 return {{}, -1};
55 }
56};
57
58} // namespace tt
Definition selection_delegate.hpp:15
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:52
callback_ptr_type subscribe(selection_widget &sender, Callback &&callback) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition selection_delegate.hpp:36
virtual callback_ptr_type subscribe(selection_widget &sender, callback_ptr_type const &callback) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition selection_delegate.hpp:27
virtual void set_selected(selection_widget &sender, ssize_t index) noexcept
Called when an option is selected by the user.
Definition selection_delegate.hpp:48
virtual void unsubscribe(selection_widget &sender, callback_ptr_type const &callback) noexcept
Unsubscribe a callback.
Definition selection_delegate.hpp:43
A graphical control element that allows the user to choose only one of a predefined set of mutually e...
Definition selection_widget.hpp:37
T make_shared(T... args)