Prepare to support nested operations

This commit is contained in:
Hanno Braun 2024-12-11 21:11:48 +01:00
parent 7257090783
commit 9a2c311d18

View File

@ -5,31 +5,33 @@ use crate::geometry::{HandleAny, Operation, Triangle, Vertex};
#[derive(Clone)] #[derive(Clone)]
pub struct OperationView { pub struct OperationView {
operation: HandleAny, operation: HandleAny,
children: Vec<Self>,
selected: Option<usize>, selected: Option<usize>,
} }
impl OperationView { impl OperationView {
pub fn new(operation: HandleAny) -> Self { pub fn new(operation: HandleAny) -> Self {
let children = operation
.children()
.into_iter()
.map(|op| Self::new(HandleAny::new(op)))
.collect();
Self { Self {
operation, operation,
children,
selected: None, selected: None,
} }
} }
pub fn operations(&self) -> Vec<(Self, bool, usize)> { pub fn operations(&self) -> Vec<(Self, bool, usize)> {
iter::once((self.clone(), true, 0)) iter::once((self.clone(), true, 0))
.chain(self.operation.children().into_iter().enumerate().map( .chain(
|(i, op)| { self.children
( .iter()
OperationView { .enumerate()
operation: op, .map(|(i, op)| (op.clone(), Some(i) == self.selected, 1)),
selected: None, )
},
Some(i) == self.selected,
1,
)
},
))
.collect() .collect()
} }