1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
use crate::{
app::svg::Svg,
pipeline::extract_output::ExtractOutput,
storage::asset::Asset,
ui::{viewport_builder::default_viewport_builder, ChangeButton},
};
use egui::{ComboBox, Context, Id, Layout, RichText, Vec2, ViewportId};
#[derive(Default)]
pub struct OutputRoutingsWindow {
open: bool,
}
impl OutputRoutingsWindow {
pub fn update(&mut self, ctx: &Context) {
if !self.open {
return;
}
ctx.show_viewport_immediate(
ViewportId(Id::new("output routings window")),
default_viewport_builder()
.with_title("Gled: Output Routings")
.with_inner_size(Vec2::new(300.0, 500.0))
.with_min_inner_size(Vec2::new(300.0, 500.0)),
|ctx, _viewport_class| {
ctx.input(|input| {
if input.viewport().close_requested() {
self.open = false;
}
});
egui::CentralPanel::default().show(ctx, |ui| {
egui::ScrollArea::vertical()
.id_salt("output_scroll")
.show(ui, |ui| {
let extract_output = ExtractOutput::get();
let mut routings = extract_output.routings.lock();
ui.with_layout(Layout::top_down_justified(egui::Align::Min), |ui| {
let universes = Svg::universes();
extract_output
.universes
.lock()
.retain(|universe| universes.contains(universe));
if universes.is_empty() {
ui.label(RichText::new(
"No universes available. You need to load a svg file first!",
));
}
let mut set_routing = None;
let mut set_device = None;
for universe in universes.clone() {
ui.label(
RichText::new(format!("Universe: {universe}")).heading(),
);
ui.horizontal(|ui| {
let output_routing =
routings.universe_output_routing(universe);
if output_routing.device.change_button(ui) {
set_device = Some((universe, output_routing.device));
}
if let Some(device) =
output_routing.device.and_then(Asset::get)
{
let device_universes = device.data.universes();
if !device_universes.is_empty() {
ComboBox::new(format!("{universe}_universe"), "")
.selected_text(match output_routing.universe {
None => "No universe selected".to_string(),
Some(universe) => universe.to_string(),
})
.width(150.0)
.show_ui(ui, |ui| {
for device_universe in device_universes {
if ui
.selectable_value(
&mut output_routing
.universe
.unwrap_or_default(),
*device_universe,
device_universe.to_string(),
)
.changed()
{
set_routing = Some((
universe,
*device_universe,
));
}
}
});
}
}
});
ui.separator();
}
if let Some((mut universe, device)) = set_device {
let mut first = true;
loop {
let output_routing =
routings.universe_output_routing(universe);
if first || output_routing.device.is_none() {
output_routing.device = device;
if let Some(device) = device.and_then(Asset::get) {
let device_universes = device.data.universes();
if device_universes.len() == 1 {
output_routing.universe =
Some(device_universes[0]);
break;
}
};
} else {
break;
}
first = false;
universe += 1;
if !universes.contains(&universe) {
break;
}
}
}
if let Some((mut universe, mut device_universe)) = set_routing {
let mut first = true;
loop {
let output_routing =
routings.universe_output_routing(universe);
let Some(device) =
output_routing.device.and_then(Asset::get)
else {
break;
};
if !device.data.universes().contains(&device_universe) {
break;
}
if first || output_routing.universe.is_none() {
output_routing.universe = Some(device_universe);
} else {
break;
}
first = false;
universe += 1;
device_universe += 1;
if !universes.contains(&universe) {
break;
}
}
}
});
});
});
},
);
}
pub fn open(&mut self) {
self.open = true;
}
pub fn close(&mut self) {
self.open = false;
}
}