mirror of
https://github.com/hannobraun/Fornjot
synced 2025-10-29 19:28:32 +00:00
Remove redundant code
This commit is contained in:
parent
3dd03182c6
commit
e260017612
@ -52,7 +52,7 @@ impl ApplicationHandler for App {
|
||||
_: WindowId,
|
||||
event: WindowEvent,
|
||||
) {
|
||||
let (Some(window), Some(renderer)) =
|
||||
let (Some(_), Some(renderer)) =
|
||||
(self.window.as_ref(), self.renderer.as_mut())
|
||||
else {
|
||||
return;
|
||||
@ -72,28 +72,6 @@ impl ApplicationHandler for App {
|
||||
} => {
|
||||
event_loop.exit();
|
||||
}
|
||||
WindowEvent::KeyboardInput {
|
||||
event: KeyEvent { logical_key, .. },
|
||||
..
|
||||
} => {
|
||||
match logical_key {
|
||||
Key::Named(NamedKey::ArrowRight) => {
|
||||
self.view.selected_mut().select_last();
|
||||
}
|
||||
Key::Named(NamedKey::ArrowLeft) => {
|
||||
self.view.parent_of_selected_mut().select_none();
|
||||
}
|
||||
Key::Named(NamedKey::ArrowDown) => {
|
||||
self.view.parent_of_selected_mut().select_next();
|
||||
}
|
||||
Key::Named(NamedKey::ArrowUp) => {
|
||||
self.view.parent_of_selected_mut().select_previous();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
window.request_redraw();
|
||||
}
|
||||
WindowEvent::RedrawRequested => {
|
||||
if let Err(err) = renderer.render(&self.view) {
|
||||
eprintln!("Render error: {err}");
|
||||
|
||||
@ -22,78 +22,12 @@ impl OperationView {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn select_last(&mut self) {
|
||||
self.selected = Some(self.last_index());
|
||||
}
|
||||
|
||||
pub fn select_next(&mut self) {
|
||||
if let Some(selected) = self.selected {
|
||||
self.selected = Some(usize::min(selected + 1, self.last_index()));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn select_previous(&mut self) {
|
||||
if let Some(selected) = self.selected {
|
||||
self.selected = Some(selected.saturating_sub(1));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn select_none(&mut self) {
|
||||
self.selected = None;
|
||||
}
|
||||
|
||||
pub fn selected(&self) -> &Self {
|
||||
self.selected
|
||||
.and_then(|selected| self.children.get(selected))
|
||||
.map(|child| child.selected())
|
||||
.unwrap_or(self)
|
||||
}
|
||||
|
||||
pub fn selected_mut(&mut self) -> &mut Self {
|
||||
let Some(selected) = self.selected else {
|
||||
return self;
|
||||
};
|
||||
|
||||
// The way this is done, first checking for `is_none` and then
|
||||
// `unwrap`ing below, is really ugly. But the borrow checker is forcing
|
||||
// my hand.
|
||||
//
|
||||
// I've tried several variations of matching, and it can't see that in
|
||||
// the `None` case, `self` no longer needs to be borrowed, preventing me
|
||||
// from returning it.
|
||||
|
||||
if self.children.get_mut(selected).is_none() {
|
||||
return self;
|
||||
};
|
||||
|
||||
self.children.get_mut(selected).unwrap().selected_mut()
|
||||
}
|
||||
|
||||
pub fn parent_of_selected_mut(&mut self) -> &mut Self {
|
||||
let Some(selected) = self.selected else {
|
||||
return self;
|
||||
};
|
||||
|
||||
// The same comment in `selected_mut` applies here too. Plus, some ugly
|
||||
// duplication.
|
||||
|
||||
if self.children.get_mut(selected).is_none() {
|
||||
return self;
|
||||
};
|
||||
|
||||
if self.children.get_mut(selected).unwrap().selected.is_none() {
|
||||
self
|
||||
} else {
|
||||
self.children
|
||||
.get_mut(selected)
|
||||
.unwrap()
|
||||
.parent_of_selected_mut()
|
||||
}
|
||||
}
|
||||
|
||||
fn last_index(&self) -> usize {
|
||||
self.children.len().saturating_sub(1)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for OperationView {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user