1
0
Fork 0

Fix generic UIs after last commit

This commit is contained in:
Robbert van der Helm 2022-03-20 13:37:01 +01:00
parent c22e522629
commit d5d54f0c06
2 changed files with 6 additions and 14 deletions

View file

@ -41,24 +41,19 @@ pub fn create(
setter: &ParamSetter,
widget: impl ParamWidget,
) {
let param_map = params.param_map();
let param_ids = params.param_ids();
let padding = Vec2::splat(ui.text_style_height(&TextStyle::Body) * 0.2);
egui::containers::ScrollArea::vertical()
// Take up all remaining space, use a wrapper container to adjust how much space that is
.auto_shrink([false, false])
.show(ui, |ui| {
for (widget_idx, id) in param_ids.into_iter().enumerate() {
let param = param_map[&id];
for (widget_idx, (_, param_ptr, _)) in params.param_map().into_iter().enumerate() {
// This list looks weird without a little padding
if widget_idx > 0 {
ui.allocate_space(padding);
}
ui.label(unsafe { param.name() });
unsafe { widget.add_widget_raw(ui, &param, setter) };
ui.label(unsafe { param_ptr.name() });
unsafe { widget.add_widget_raw(ui, &param_ptr, setter) };
}
});
}

View file

@ -166,18 +166,15 @@ where
.padding(padding)
.align_items(Alignment::Center);
let param_map = self.params.param_map();
let param_ids = self.params.param_ids();
// Make sure we already have widget state for each widget
for param_ptr in param_map.values() {
let param_map = self.params.param_map();
for (_, param_ptr, _) in &param_map {
if !widget_state.contains_key(param_ptr) {
widget_state.insert(*param_ptr, Default::default());
}
}
for param_id in param_ids {
let param_ptr = param_map[&param_id];
for (_, param_ptr, _) in param_map {
// SAFETY: We only borrow each item once, and the plugin framework statically asserted
// that parameter indices are unique and this widget state cannot outlive this
// function