HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
audio_device_widget.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2022.
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
8
9#pragma once
10
11#include "selection_widget.hpp"
12#include "grid_widget.hpp"
13#include "../audio/audio.hpp"
14#include "../l10n/l10n.hpp"
15#include "../macros.hpp"
16#include <memory>
17#include <string>
18#include <array>
19#include <optional>
20#include <future>
21#include <coroutine>
22
23hi_export_module(hikogui.widgets.audio_device_widget);
24
25hi_export namespace hi { inline namespace v1 {
26
31public:
32 using super = widget;
33
37
40 observer<audio_direction> direction = audio_direction::bidirectional;
41
42 virtual ~audio_device_widget() {}
43
44 audio_device_widget() noexcept : super()
45 {
46 _grid_widget = std::make_unique<grid_widget>();
47 _grid_widget->set_parent(this);
48
49 _device_selection_widget = &_grid_widget->emplace<selection_widget>("A1", device_id, _device_list);
50
51 _sync_device_list_task = sync_device_list();
52 }
53
55 [[nodiscard]] generator<widget_intf&> children(bool include_invisible) noexcept override
56 {
57 co_yield *_grid_widget;
58 }
59
60 [[nodiscard]] box_constraints update_constraints() noexcept override
61 {
62 _layout = {};
63 _grid_constraints = _grid_widget->update_constraints();
64 return _grid_constraints;
65 }
66
67 void set_layout(widget_layout const& context) noexcept override
68 {
69 if (compare_store(_layout, context)) {
70 auto const grid_rectangle = context.rectangle();
71 _grid_shape = {_grid_constraints, grid_rectangle, theme().baseline_adjustment()};
72 }
73
74 _grid_widget->set_layout(context.transform(_grid_shape, transform_command::level));
75 }
76
77 void draw(draw_context const& context) noexcept override
78 {
79 if (mode() > widget_mode::invisible) {
80 _grid_widget->draw(context);
81 }
82 }
83
84 hitbox hitbox_test(point2 position) const noexcept override
85 {
86 if (mode() >= widget_mode::partial) {
87 auto r = hitbox{};
88 r = _grid_widget->hitbox_test_from_parent(position, r);
89 return r;
90 } else {
91 return hitbox{};
92 }
93 }
94
95 [[nodiscard]] bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept override
96 {
97 if (mode() >= widget_mode::partial) {
98 return _grid_widget->accepts_keyboard_focus(group);
99 } else {
100 return false;
101 }
102 }
104private:
107 std::unique_ptr<grid_widget> _grid_widget;
108 box_constraints _grid_constraints;
109 box_shape _grid_shape;
110
113 selection_widget *_device_selection_widget = nullptr;
114
115 observer<std::vector<std::pair<std::string, label>>> _device_list;
116
117 hi::scoped_task<> _sync_device_list_task;
118
119 [[nodiscard]] hi::scoped_task<> sync_device_list() noexcept
120 {
121 while (true) {
122 {
123 auto proxy = _device_list.get();
124 proxy->clear();
125 for (auto& device : audio_devices(hi::audio_device_state::active, *direction)) {
126 proxy->emplace_back(device.id(), device.label());
127 }
128 }
129
131 }
132 }
133};
134
135}} // namespace hi::v1
Defines selection_widget.
Defines grid_widget.
@ partial
A widget is partially enabled.
Definition widget_state.hpp:73
@ invisible
The widget is invisible.
Definition widget_state.hpp:41
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22
bool compare_store(T &lhs, U &&rhs) noexcept
Compare then store if there was a change.
Definition misc.hpp:53
generator< audio_device & > audio_devices(Filters &&...filters) noexcept
Get audio devices matching the filter arguments.
Definition audio_system.hpp:101
@ level
The child widget stays at the same elevation and layer.
Definition widget_layout.hpp:26
auto when_any(Args const &...args)
await on a set of objects which can be converted to an awaitable.
Definition when_any.hpp:173
static audio_system & global() noexcept
Create an audio system object specific for the current operating system.
Definition audio_system_win32.hpp:230
A observer pointing to the whole or part of a observed_base.
Definition observer_intf.hpp:32
Audio device configuration widget.
Definition audio_device_widget.hpp:30
observer< audio_direction > direction
The audio direction (input or output) of devices is should show.
Definition audio_device_widget.hpp:40
observer< std::string > device_id
The audio device this widget has selected and is configuring.
Definition audio_device_widget.hpp:36
A graphical control element that allows the user to choose only one of a predefined set of mutually e...
Definition selection_widget.hpp:48
widget() noexcept
Constructor for creating sub views.
Definition widget.hpp:50
box_constraints update_constraints() noexcept override
Update the constraints of the widget.
Definition widget.hpp:110