forked from 1b-agent/opencadstudio-upstream
style: apply cargo fmt across workspace
This commit is contained in:
1 parent
85710e5454
commit
9cf9ff2c5c
531 files changed
+57740
-33906
No files matched your search
+128
-41
@@ -71,7 +71,8 @@ impl OpenCADStudio {
|
||||
.scene
|
||||
.selection
|
||||
.borrow()
|
||||
.menu.ui
|
||||
.menu
|
||||
.ui
|
||||
.open_submenu;
|
||||
build_context_menu(&self.context_menu_context(), open)
|
||||
}
|
||||
@@ -88,18 +89,22 @@ impl OpenCADStudio {
|
||||
self.focus_cmd_input()
|
||||
}
|
||||
|
||||
pub(in crate::app) fn on_context_menu_submenu_toggle(&mut self, id: SubmenuId) -> Task<Message> {
|
||||
pub(in crate::app) fn on_context_menu_submenu_toggle(
|
||||
&mut self,
|
||||
id: SubmenuId,
|
||||
) -> Task<Message> {
|
||||
let i = self.active_tab;
|
||||
let mut sel = self.tabs[i].scene.selection.borrow_mut();
|
||||
let ui = &mut sel.menu.ui;
|
||||
ui.open_submenu = if ui.open_submenu == Some(id) { None } else { Some(id) };
|
||||
ui.open_submenu = if ui.open_submenu == Some(id) {
|
||||
None
|
||||
} else {
|
||||
Some(id)
|
||||
};
|
||||
drop(sel);
|
||||
// Keep the keyboard highlight on the header that was toggled.
|
||||
let menu = self.current_context_menu();
|
||||
let header = menu
|
||||
.selectable()
|
||||
.iter()
|
||||
.position(|s| s.header == Some(id));
|
||||
let header = menu.selectable().iter().position(|s| s.header == Some(id));
|
||||
let mut sel = self.tabs[i].scene.selection.borrow_mut();
|
||||
if sel.menu.ui.highlighted.is_some() {
|
||||
sel.menu.ui.highlighted = header;
|
||||
@@ -164,7 +169,10 @@ impl OpenCADStudio {
|
||||
}
|
||||
|
||||
/// Keyboard navigation while the menu is open.
|
||||
pub(in crate::app) fn on_context_menu_navigate(&mut self, nav: ContextMenuNav) -> Task<Message> {
|
||||
pub(in crate::app) fn on_context_menu_navigate(
|
||||
&mut self,
|
||||
nav: ContextMenuNav,
|
||||
) -> Task<Message> {
|
||||
if !self.context_menu_open() {
|
||||
return Task::none();
|
||||
}
|
||||
@@ -193,7 +201,13 @@ impl OpenCADStudio {
|
||||
None => menu.default_index(),
|
||||
Some(cur) => next_enabled(cur, 1),
|
||||
};
|
||||
self.tabs[i].scene.selection.borrow_mut().menu.ui.highlighted = Some(idx);
|
||||
self.tabs[i]
|
||||
.scene
|
||||
.selection
|
||||
.borrow_mut()
|
||||
.menu
|
||||
.ui
|
||||
.highlighted = Some(idx);
|
||||
Task::none()
|
||||
}
|
||||
ContextMenuNav::Up => {
|
||||
@@ -201,7 +215,13 @@ impl OpenCADStudio {
|
||||
None => menu.default_index(),
|
||||
Some(cur) => next_enabled(cur, -1),
|
||||
};
|
||||
self.tabs[i].scene.selection.borrow_mut().menu.ui.highlighted = Some(idx);
|
||||
self.tabs[i]
|
||||
.scene
|
||||
.selection
|
||||
.borrow_mut()
|
||||
.menu
|
||||
.ui
|
||||
.highlighted = Some(idx);
|
||||
Task::none()
|
||||
}
|
||||
ContextMenuNav::Enter => {
|
||||
@@ -220,8 +240,13 @@ impl OpenCADStudio {
|
||||
if unique {
|
||||
self.on_context_menu_pick(rows[idx].action.clone())
|
||||
} else {
|
||||
self.tabs[i].scene.selection.borrow_mut().menu.ui.highlighted =
|
||||
Some(idx);
|
||||
self.tabs[i]
|
||||
.scene
|
||||
.selection
|
||||
.borrow_mut()
|
||||
.menu
|
||||
.ui
|
||||
.highlighted = Some(idx);
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
@@ -235,7 +260,10 @@ impl OpenCADStudio {
|
||||
/// normal handlers (after closing the menu when the key is not a menu key,
|
||||
/// so typing a command name or a coordinate just works — the menu gets
|
||||
/// out of the way exactly as it does in commercial solutions).
|
||||
pub(in crate::app) fn intercept_context_menu_key(&mut self, msg: &Message) -> Option<Task<Message>> {
|
||||
pub(in crate::app) fn intercept_context_menu_key(
|
||||
&mut self,
|
||||
msg: &Message,
|
||||
) -> Option<Task<Message>> {
|
||||
match msg {
|
||||
Message::ArrowKeyPressed { direction, .. }
|
||||
| Message::CommandLineArrowProbe { direction, .. } => match direction {
|
||||
@@ -247,7 +275,10 @@ impl OpenCADStudio {
|
||||
let ui = self.tabs[i].scene.selection.borrow().menu.ui.clone();
|
||||
let menu = self.current_context_menu();
|
||||
let rows = menu.selectable();
|
||||
let header = ui.highlighted.and_then(|c| rows.get(c)).and_then(|r| r.header);
|
||||
let header = ui
|
||||
.highlighted
|
||||
.and_then(|c| rows.get(c))
|
||||
.and_then(|r| r.header);
|
||||
let want_open = matches!(direction, ArrowKey::Right);
|
||||
match header {
|
||||
Some(id) if (ui.open_submenu == Some(id)) != want_open => {
|
||||
@@ -477,7 +508,11 @@ mod tests {
|
||||
right_click(&mut app);
|
||||
assert!(menu_open(&app));
|
||||
let acts = menu_actions(&app);
|
||||
assert_eq!(acts[0], MenuAction::Command("LINE".into()), "Repeat LINE first");
|
||||
assert_eq!(
|
||||
acts[0],
|
||||
MenuAction::Command("LINE".into()),
|
||||
"Repeat LINE first"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -492,8 +527,8 @@ mod tests {
|
||||
let _ = app.update(Message::ViewportRightPress);
|
||||
{
|
||||
let mut sel = app.tabs[0].scene.selection.borrow_mut();
|
||||
sel.input.right_press_time = iced::time::Instant::now()
|
||||
.checked_sub(std::time::Duration::from_millis(400));
|
||||
sel.input.right_press_time =
|
||||
iced::time::Instant::now().checked_sub(std::time::Duration::from_millis(400));
|
||||
}
|
||||
let _ = app.update(Message::ViewportRightRelease);
|
||||
assert!(menu_open(&app));
|
||||
@@ -559,7 +594,14 @@ mod tests {
|
||||
let _ = app.update(Message::ContextMenuPick(MenuAction::Command("LINE".into())));
|
||||
assert!(!menu_open(&app));
|
||||
assert_eq!(active(&app), Some("LINE"));
|
||||
assert!(!app.tabs[0].scene.selection.borrow().input.right_click_entered);
|
||||
assert!(
|
||||
!app.tabs[0]
|
||||
.scene
|
||||
.selection
|
||||
.borrow()
|
||||
.input
|
||||
.right_click_entered
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -602,9 +644,11 @@ mod tests {
|
||||
let _ = app.update(Message::CommandAppendChar("c".into()));
|
||||
assert!(!menu_open(&app));
|
||||
assert_eq!(active(&app), None);
|
||||
let closed = app.tabs[0].scene.document.entities().any(
|
||||
|e| matches!(e, codec::EntityType::LwPolyline(p) if p.is_closed),
|
||||
);
|
||||
let closed = app.tabs[0]
|
||||
.scene
|
||||
.document
|
||||
.entities()
|
||||
.any(|e| matches!(e, codec::EntityType::LwPolyline(p) if p.is_closed));
|
||||
assert!(closed);
|
||||
});
|
||||
}
|
||||
@@ -620,7 +664,11 @@ mod tests {
|
||||
let _ = app.update(Message::CommandAppendChar("7".into()));
|
||||
assert!(!menu_open(&app));
|
||||
assert_eq!(active(&app), Some("LINE"));
|
||||
assert!(app.command_line.input.contains('7'), "{:?}", app.command_line.input);
|
||||
assert!(
|
||||
app.command_line.input.contains('7'),
|
||||
"{:?}",
|
||||
app.command_line.input
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -636,7 +684,9 @@ mod tests {
|
||||
let _ = app.update(Message::ContextMenuSubmenuToggle(SubmenuId::RecentInput));
|
||||
let acts = menu_actions(&app);
|
||||
assert!(acts.contains(&MenuAction::FeedInput("10,10".into())));
|
||||
let _ = app.update(Message::ContextMenuPick(MenuAction::FeedInput("10,10".into())));
|
||||
let _ = app.update(Message::ContextMenuPick(MenuAction::FeedInput(
|
||||
"10,10".into(),
|
||||
)));
|
||||
assert!(!menu_open(&app));
|
||||
let lines = app.tabs[0]
|
||||
.scene
|
||||
@@ -691,10 +741,12 @@ mod tests {
|
||||
app.snapper.otrack_enabled = false;
|
||||
app.ortho_mode = false;
|
||||
app.polar_mode = false;
|
||||
let handle = app.tabs[0].scene.add_entity(EntityType::Line(Line::from_points(
|
||||
Vector3::new(0.0, 0.0, 0.0),
|
||||
Vector3::new(10.0, 0.0, 0.0),
|
||||
)));
|
||||
let handle = app.tabs[0]
|
||||
.scene
|
||||
.add_entity(EntityType::Line(Line::from_points(
|
||||
Vector3::new(0.0, 0.0, 0.0),
|
||||
Vector3::new(10.0, 0.0, 0.0),
|
||||
)));
|
||||
app.tabs[0].scene.selected.insert(handle);
|
||||
app.refresh_selected_grips();
|
||||
app.tabs[0].active_grip = Some(crate::scene::pick::grip::GripEdit::single(
|
||||
@@ -711,7 +763,10 @@ mod tests {
|
||||
.scene
|
||||
.camera
|
||||
.borrow()
|
||||
.project(world, iced::Rectangle::with_size(iced::Size::new(800.0, 600.0)))
|
||||
.project(
|
||||
world,
|
||||
iced::Rectangle::with_size(iced::Size::new(800.0, 600.0)),
|
||||
)
|
||||
.unwrap();
|
||||
let _ = app.on_viewport_move(Point::new(cursor.x, cursor.y));
|
||||
}
|
||||
@@ -733,7 +788,10 @@ mod tests {
|
||||
assert_eq!(acts[0], MenuAction::Enter);
|
||||
assert!(acts.contains(&MenuAction::Grip(GripMenuCmd::Move)));
|
||||
assert!(acts.contains(&MenuAction::Grip(GripMenuCmd::Exit)));
|
||||
assert!(app.tabs[0].active_grip.is_some(), "the grip stays hot under the menu");
|
||||
assert!(
|
||||
app.tabs[0].active_grip.is_some(),
|
||||
"the grip stays hot under the menu"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -742,11 +800,17 @@ mod tests {
|
||||
with_stack(|| {
|
||||
let (mut app, _) = grip_app();
|
||||
right_click(&mut app);
|
||||
let _ = app.update(Message::ContextMenuPick(MenuAction::Grip(GripMenuCmd::Move)));
|
||||
let _ = app.update(Message::ContextMenuPick(MenuAction::Grip(
|
||||
GripMenuCmd::Move,
|
||||
)));
|
||||
assert!(!menu_open(&app));
|
||||
assert!(app.tabs[0].active_grip.is_none());
|
||||
assert_eq!(active(&app), Some("MOVE"));
|
||||
let prompt = app.tabs[0].active_cmd.as_ref().map(|c| c.prompt()).unwrap_or_default();
|
||||
let prompt = app.tabs[0]
|
||||
.active_cmd
|
||||
.as_ref()
|
||||
.map(|c| c.prompt())
|
||||
.unwrap_or_default();
|
||||
let base_prompt = crate::tr!("command-move", "base", count = 1i64);
|
||||
assert_ne!(prompt, base_prompt, "base already consumed");
|
||||
assert_eq!(app.last_point, Some(DVec3::ZERO));
|
||||
@@ -759,12 +823,20 @@ mod tests {
|
||||
let (mut app, handle) = grip_app();
|
||||
move_cursor_to(&mut app, DVec3::new(3.0, 4.0, 0.0));
|
||||
let (x, y) = line_start(&app, handle);
|
||||
assert!((x - 3.0).abs() < 1e-3 && (y - 4.0).abs() < 1e-3, "drag applied");
|
||||
assert!(
|
||||
(x - 3.0).abs() < 1e-3 && (y - 4.0).abs() < 1e-3,
|
||||
"drag applied"
|
||||
);
|
||||
right_click(&mut app);
|
||||
let _ = app.update(Message::ContextMenuPick(MenuAction::Grip(GripMenuCmd::Exit)));
|
||||
let _ = app.update(Message::ContextMenuPick(MenuAction::Grip(
|
||||
GripMenuCmd::Exit,
|
||||
)));
|
||||
assert!(app.tabs[0].active_grip.is_none());
|
||||
let (x, y) = line_start(&app, handle);
|
||||
assert!(x.abs() < 1e-9 && y.abs() < 1e-9, "Exit restores the original");
|
||||
assert!(
|
||||
x.abs() < 1e-9 && y.abs() < 1e-9,
|
||||
"Exit restores the original"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -774,7 +846,9 @@ mod tests {
|
||||
let (mut app, handle) = grip_app();
|
||||
move_cursor_to(&mut app, DVec3::new(3.0, 4.0, 0.0));
|
||||
right_click(&mut app);
|
||||
let _ = app.update(Message::ContextMenuPick(MenuAction::Grip(GripMenuCmd::Undo)));
|
||||
let _ = app.update(Message::ContextMenuPick(MenuAction::Grip(
|
||||
GripMenuCmd::Undo,
|
||||
)));
|
||||
let (x, y) = line_start(&app, handle);
|
||||
assert!(x.abs() < 1e-9 && y.abs() < 1e-9);
|
||||
let grip = app.tabs[0].active_grip.as_ref().expect("grip still hot");
|
||||
@@ -787,7 +861,9 @@ mod tests {
|
||||
with_stack(|| {
|
||||
let (mut app, handle) = grip_app();
|
||||
right_click(&mut app);
|
||||
let _ = app.update(Message::ContextMenuPick(MenuAction::Grip(GripMenuCmd::CopyToggle)));
|
||||
let _ = app.update(Message::ContextMenuPick(MenuAction::Grip(
|
||||
GripMenuCmd::CopyToggle,
|
||||
)));
|
||||
assert!(app.tabs[0].grip_copy);
|
||||
move_cursor_to(&mut app, DVec3::new(3.0, 4.0, 0.0));
|
||||
let _ = app.update(Message::CommandFinalize);
|
||||
@@ -803,8 +879,13 @@ mod tests {
|
||||
assert_eq!(lines.len(), 2, "{lines:?}");
|
||||
let (x, y) = line_start(&app, handle);
|
||||
assert!(x.abs() < 1e-9 && y.abs() < 1e-9, "original untouched");
|
||||
assert!(lines.iter().any(|&(x, y)| (x - 3.0).abs() < 1e-3 && (y - 4.0).abs() < 1e-3));
|
||||
assert!(app.tabs[0].active_grip.is_some(), "grip re-armed for the next copy");
|
||||
assert!(lines
|
||||
.iter()
|
||||
.any(|&(x, y)| (x - 3.0).abs() < 1e-3 && (y - 4.0).abs() < 1e-3));
|
||||
assert!(
|
||||
app.tabs[0].active_grip.is_some(),
|
||||
"grip re-armed for the next copy"
|
||||
);
|
||||
// One undo step removes the copy again.
|
||||
app.undo_steps(1);
|
||||
let count = app.tabs[0]
|
||||
@@ -822,7 +903,9 @@ mod tests {
|
||||
with_stack(|| {
|
||||
let (mut app, handle) = grip_app();
|
||||
right_click(&mut app);
|
||||
let _ = app.update(Message::ContextMenuPick(MenuAction::Grip(GripMenuCmd::BasePoint)));
|
||||
let _ = app.update(Message::ContextMenuPick(MenuAction::Grip(
|
||||
GripMenuCmd::BasePoint,
|
||||
)));
|
||||
assert!(app.tabs[0].grip_base_pending);
|
||||
move_cursor_to(&mut app, DVec3::new(1.0, 1.0, 0.0));
|
||||
let _ = app.update(Message::ViewportLeftPress);
|
||||
@@ -990,7 +1073,9 @@ mod transparent_tests {
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(lines.len(), 2);
|
||||
assert!((lines[1].start.x - 50.0).abs() < 1e-6 && (lines[1].start.y - 0.0).abs() < 1e-6);
|
||||
assert!(
|
||||
(lines[1].start.x - 50.0).abs() < 1e-6 && (lines[1].start.y - 0.0).abs() < 1e-6
|
||||
);
|
||||
assert!((lines[1].end.x - 50.0).abs() < 1e-6 && (lines[1].end.y - 25.0).abs() < 1e-6);
|
||||
|
||||
// Point cursor in -X direction from (50, 25) using feed_active_cmd
|
||||
@@ -1006,7 +1091,9 @@ mod transparent_tests {
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(lines.len(), 3);
|
||||
assert!((lines[2].start.x - 50.0).abs() < 1e-6 && (lines[2].start.y - 25.0).abs() < 1e-6);
|
||||
assert!(
|
||||
(lines[2].start.x - 50.0).abs() < 1e-6 && (lines[2].start.y - 25.0).abs() < 1e-6
|
||||
);
|
||||
assert!((lines[2].end.x - 0.0).abs() < 1e-6 && (lines[2].end.y - 25.0).abs() < 1e-6);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user