mirror of
https://github.com/hannobraun/Fornjot
synced 2025-07-18 07:56:06 +00:00
Prepare to support nested operations
This commit is contained in:
parent
ccf6d9a1d1
commit
529068cec5
@ -2,14 +2,14 @@ use crate::geometry::Operation;
|
||||
|
||||
pub struct OperationView {
|
||||
operation: Box<dyn Operation>,
|
||||
selected: usize,
|
||||
selected: Option<usize>,
|
||||
}
|
||||
|
||||
impl OperationView {
|
||||
pub fn new(operation: impl Operation + 'static) -> Self {
|
||||
Self {
|
||||
operation: Box::new(operation),
|
||||
selected: 0,
|
||||
selected: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,29 +18,35 @@ impl OperationView {
|
||||
.children()
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(i, op)| (op, i == self.selected))
|
||||
.map(|(i, op)| (op, Some(i) == self.selected))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn select_last(&mut self) {
|
||||
let last_index = self.operations().len().saturating_sub(1);
|
||||
self.selected = last_index;
|
||||
self.selected = Some(last_index);
|
||||
}
|
||||
|
||||
pub fn select_next(&mut self) {
|
||||
if self.selected + 1 < self.operations().len() {
|
||||
self.selected += 1;
|
||||
if let Some(selected) = self.selected {
|
||||
if selected + 1 < self.operations().len() {
|
||||
self.selected = Some(selected + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn select_previous(&mut self) {
|
||||
self.selected = self.selected.saturating_sub(1);
|
||||
if let Some(selected) = self.selected {
|
||||
self.selected = Some(selected.saturating_sub(1));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn selected(&self) -> Option<Box<dyn Operation>> {
|
||||
let selected = self.selected?;
|
||||
|
||||
self.operations()
|
||||
.into_iter()
|
||||
.nth(self.selected)
|
||||
.nth(selected)
|
||||
.map(|(op, _)| op)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user