spinners and fmt
This commit is contained in:
+34
-13
@@ -1,7 +1,7 @@
|
||||
use kiln_core::{Archetype, Direction};
|
||||
use crate::editor::EditorState;
|
||||
use crate::menu::{MenuItem, MenuKey};
|
||||
use crate::mode::PendingMode;
|
||||
use kiln_core::{Archetype, Direction, SpinDirection};
|
||||
|
||||
/// One level in the editor's sidebar menu tree.
|
||||
///
|
||||
@@ -72,16 +72,29 @@ impl MenuLevel {
|
||||
MenuEntry::item('c', "■ Crate", |ed| ed.set_current(Archetype::Crate)),
|
||||
MenuEntry::item('v', "↕ Crate", |ed| ed.set_current(Archetype::VCrate)),
|
||||
MenuEntry::item('h', "↔ Crate", |ed| ed.set_current(Archetype::HCrate)),
|
||||
|
||||
],
|
||||
MenuLevel::Machines => vec![
|
||||
MenuEntry::item('p', "Pushers...", |ed| ed.menu.push(MenuLevel::Pushers)),
|
||||
MenuEntry::item('s', "/ CW spinner", |ed| {
|
||||
ed.set_current(Archetype::Spinner(SpinDirection::Clockwise))
|
||||
}),
|
||||
MenuEntry::item('c', "\\ CCW spinner", |ed| {
|
||||
ed.set_current(Archetype::Spinner(SpinDirection::CounterClockwise))
|
||||
}),
|
||||
],
|
||||
MenuLevel::Pushers => vec![
|
||||
MenuEntry::item('n', "▲ Pusher", |ed| ed.set_current(Archetype::Pusher(Direction::North))),
|
||||
MenuEntry::item('s', "▼ Pusher", |ed| ed.set_current(Archetype::Pusher(Direction::South))),
|
||||
MenuEntry::item('e', "► Pusher", |ed| ed.set_current(Archetype::Pusher(Direction::East))),
|
||||
MenuEntry::item('w', "◄ Pusher", |ed| ed.set_current(Archetype::Pusher(Direction::West))),
|
||||
MenuEntry::item('n', "▲ Pusher", |ed| {
|
||||
ed.set_current(Archetype::Pusher(Direction::North))
|
||||
}),
|
||||
MenuEntry::item('s', "▼ Pusher", |ed| {
|
||||
ed.set_current(Archetype::Pusher(Direction::South))
|
||||
}),
|
||||
MenuEntry::item('e', "► Pusher", |ed| {
|
||||
ed.set_current(Archetype::Pusher(Direction::East))
|
||||
}),
|
||||
MenuEntry::item('w', "◄ Pusher", |ed| {
|
||||
ed.set_current(Archetype::Pusher(Direction::West))
|
||||
}),
|
||||
],
|
||||
}
|
||||
}
|
||||
@@ -91,7 +104,7 @@ impl MenuLevel {
|
||||
/// access to the editor session. Unmatched keys are ignored.
|
||||
pub(crate) fn perform_key(self, ch: char, editor: &mut EditorState) {
|
||||
let action = self.entries().into_iter().find_map(|entry| match entry {
|
||||
MenuEntry::Item{ key, action, .. } if key == ch => Some(action),
|
||||
MenuEntry::Item { key, action, .. } if key == ch => Some(action),
|
||||
_ => None,
|
||||
});
|
||||
if let Some(action) = action {
|
||||
@@ -105,7 +118,7 @@ impl MenuLevel {
|
||||
/// [`Blank`](MenuEntry::Blank)/[`Separator`](MenuEntry::Separator) spacer.
|
||||
pub(crate) enum MenuEntry {
|
||||
/// A selectable, key-activated item.
|
||||
Item{
|
||||
Item {
|
||||
/// The letter the user presses to activate this item.
|
||||
key: char,
|
||||
/// Display label shown after the `[key]` in the sidebar.
|
||||
@@ -119,15 +132,23 @@ pub(crate) enum MenuEntry {
|
||||
/// A horizontal rule spanning the sidebar width.
|
||||
Separator,
|
||||
/// The current value of some field
|
||||
CurrentValue(Box<dyn FnOnce(& EditorState) -> String>)
|
||||
CurrentValue(Box<dyn FnOnce(&EditorState) -> String>),
|
||||
}
|
||||
|
||||
impl MenuEntry {
|
||||
pub(crate) fn item<F: FnOnce(&mut EditorState) + 'static>(key: char, label: impl Into<String>, action: F) -> Self {
|
||||
MenuEntry::Item { key, label: label.into(), action: Box::new(action) }
|
||||
pub(crate) fn item<F: FnOnce(&mut EditorState) + 'static>(
|
||||
key: char,
|
||||
label: impl Into<String>,
|
||||
action: F,
|
||||
) -> Self {
|
||||
MenuEntry::Item {
|
||||
key,
|
||||
label: label.into(),
|
||||
action: Box::new(action),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn value<F: FnOnce(& EditorState) -> String + 'static>(action: F) -> Self {
|
||||
pub(crate) fn value<F: FnOnce(&EditorState) -> String + 'static>(action: F) -> Self {
|
||||
MenuEntry::CurrentValue(Box::new(action))
|
||||
}
|
||||
}
|
||||
@@ -151,4 +172,4 @@ pub(crate) fn editor_menu_items() -> Vec<MenuItem> {
|
||||
ui.begin_close_menu();
|
||||
}),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user