Skip to content

Commit

Permalink
Added DockState::iter_nodes_mut and DockState::iter_main_surface_node…
Browse files Browse the repository at this point in the history
…s_mut (#195)

* added iter_nodes_mut

* finished adding iter_nodes_mut

* added iter_main_surface_nodes_mut

* ran cargo fmt
  • Loading branch information
eupraxia05 authored Oct 26, 2023
1 parent ea88127 commit 8afa2c8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/dock_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,26 @@ impl<Tab> DockState<Tab> {
self[SurfaceIndex::main()].iter()
}

/// Returns a mutable `Iterator` of the underlying collection of nodes on the main surface.
pub fn iter_main_surface_nodes_mut(&mut self) -> std::slice::IterMut<'_, Node<Tab>> {
self[SurfaceIndex::main()].iter_mut()
}

/// Returns an `Iterator` of **all** underlying nodes in the dock state and all subsequent trees.
pub fn iter_nodes(&self) -> impl Iterator<Item = &Node<Tab>> {
self.surfaces
.iter()
.filter_map(|tree| tree.node_tree())
.flat_map(|nodes| nodes.iter())
}

/// Returns a mutable `Iterator` of **all** underlying nodes in the dock state and all subsequent trees.
pub fn iter_nodes_mut(&mut self) -> impl Iterator<Item = &mut Node<Tab>> {
self.surfaces
.iter_mut()
.filter_map(|tree| tree.node_tree_mut())
.flat_map(|nodes| nodes.iter_mut())
}
}

impl<Tab> DockState<Tab>
Expand Down

0 comments on commit 8afa2c8

Please sign in to comment.