mirror of
https://github.com/Zenithsiz/zsw.git
synced 2026-02-04 02:08:37 +00:00
Replaced Panels::for_each_mut with panels_mut.
`Panels::panels` now returns a slice of all panels state.
This commit is contained in:
parent
be4ae70578
commit
340779eec1
@ -118,12 +118,13 @@ impl Panels {
|
||||
}
|
||||
|
||||
/// Returns all panels
|
||||
pub fn panels(&self, panels_lock: &PanelsLock) -> Vec<Panel> {
|
||||
panels_lock
|
||||
.get(&self.lock_source)
|
||||
.iter()
|
||||
.map(|panel| panel.panel)
|
||||
.collect()
|
||||
pub fn panels<'a>(&self, panels_lock: &'a PanelsLock) -> &'a [PanelState] {
|
||||
panels_lock.get(&self.lock_source)
|
||||
}
|
||||
|
||||
/// Returns all panels, mutably
|
||||
pub fn panels_mut<'a>(&self, panels_lock: &'a mut PanelsLock) -> &'a mut [PanelState] {
|
||||
panels_lock.get_mut(&self.lock_source)
|
||||
}
|
||||
|
||||
/// Replaces all panels
|
||||
@ -149,21 +150,6 @@ impl Panels {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Iterates over all panels mutably.
|
||||
///
|
||||
/// # Blocking
|
||||
/// Will deadlock if `f` blocks.
|
||||
// TODO: Maybe just return a `&mut Vec<_>`
|
||||
#[side_effect(MightBlock)]
|
||||
pub fn for_each_mut<T, C: FromIterator<T>>(
|
||||
&self,
|
||||
panels_lock: &mut PanelsLock,
|
||||
f: impl FnMut(&mut PanelState) -> T,
|
||||
) -> C {
|
||||
let panels = panels_lock.get_mut(&self.lock_source);
|
||||
panels.iter_mut().map(f).collect()
|
||||
}
|
||||
|
||||
/// Renders all panels
|
||||
pub fn render(
|
||||
&self,
|
||||
|
||||
@ -373,7 +373,7 @@ fn draw_profile<'playlist, 'panels, 'profiles>(
|
||||
return;
|
||||
},
|
||||
},
|
||||
panels: panels.panels(panels_lock),
|
||||
panels: panels.panels(panels_lock).iter().map(|panel| panel.panel).collect(),
|
||||
}
|
||||
};
|
||||
|
||||
@ -446,17 +446,11 @@ fn draw_panels<'panels>(
|
||||
panels_lock: &mut zsw_panels::PanelsLock<'panels>,
|
||||
) {
|
||||
// Draw all panels in their own header
|
||||
// BLOCKING: TODO
|
||||
let mut panel_idx = 0;
|
||||
panels
|
||||
.for_each_mut::<_, ()>(panels_lock, |panel| {
|
||||
ui.collapsing(format!("Panel {panel_idx}"), |ui| {
|
||||
ui.add(PanelWidget::new(panel, surface_size));
|
||||
});
|
||||
|
||||
panel_idx += 1;
|
||||
})
|
||||
.allow::<MightBlock>();
|
||||
for (idx, panel) in panels.panels_mut(panels_lock).iter_mut().enumerate() {
|
||||
ui.collapsing(format!("Panel {idx}"), |ui| {
|
||||
ui.add(PanelWidget::new(panel, surface_size));
|
||||
});
|
||||
}
|
||||
|
||||
// Draw the panel adder
|
||||
ui.collapsing("Add", |ui| {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user