mirror of
https://github.com/storytold/cadcraft.git
synced 2026-11-21 20:40:02 +00:00
Merge #1748: a quick right-click is Enter between commands too
# Conflicts: # contributors/people.toml # crates/ui-egui/src/canvas.rs # crates/ui-egui/src/context_menu.rs # crates/ui-egui/src/options.rs # docs/ui-parity.md
This commit is contained in:
@@ -128,3 +128,8 @@ sync_github_name = true
|
||||
|
||||
[people.tyrel]
|
||||
real_name = "Tyrel Haveman"
|
||||
|
||||
[people.Sladrian]
|
||||
real_name = "Sladrian Pedroso"
|
||||
display_name = "Sladrian Pedroso"
|
||||
sync_github_name = false
|
||||
|
||||
@@ -165,7 +165,7 @@ pub struct CanvasState {
|
||||
/// A GRIP edit was running last frame (its grips go cold when it ends).
|
||||
grip_editing: bool,
|
||||
/// The grip whose menu (Stretch, Add Vertex, Lengthen…) a right-click opened.
|
||||
grip_menu: Option<(Handle, usize)>,
|
||||
pub(crate) grip_menu: Option<(Handle, usize)>,
|
||||
/// Dynamic block grips of the selection (cached), the one being dragged, and the list grip
|
||||
/// whose choices are open (and whether it opened this frame).
|
||||
pub(crate) dyn_grips: crate::dyngrips::Cache,
|
||||
@@ -932,28 +932,31 @@ pub fn show(app: &mut CadApp, ui: &mut egui::Ui) {
|
||||
app.session.echo(e.to_string());
|
||||
}
|
||||
}
|
||||
// Right-click acts as Enter while a command runs (the classic CAD default; held, it opens the
|
||||
// command menu); otherwise it opens the shortcut menu (Repeat, Clipboard, …).
|
||||
// Shift/Ctrl+right-click opens the object snap menu.
|
||||
// A quick right-click is Enter (the classic CAD default): it enters what was typed, ends the
|
||||
// input of a running command, and between commands repeats the last one. Held, it opens the
|
||||
// command menu or the shortcut menu (Repeat, Clipboard, …). Shift/Ctrl+right-click opens the
|
||||
// object snap menu.
|
||||
let idle = !app.session.prompting();
|
||||
if inside && pressed_secondary {
|
||||
app.canvas.snap_menu = mods.shift || mods.ctrl;
|
||||
}
|
||||
if crate::context_menu::in_command(app, ui, inside, pressed_secondary) {
|
||||
if right_click_cancels_placing(app) {
|
||||
crate::cmdline::escape(app);
|
||||
} else {
|
||||
let _ = app.session.input(Input::Enter);
|
||||
}
|
||||
}
|
||||
// Right-click on a grip with options (polyline vertex, line end…) opens the grip menu.
|
||||
if inside && pressed_secondary && idle && !app.canvas.snap_menu {
|
||||
app.canvas.grip_menu = grip_at(app, &xf, hover_pos).filter(|g| !grip_options(app, *g).is_empty());
|
||||
}
|
||||
let enter = crate::context_menu::in_command(app, ui, inside, pressed_secondary);
|
||||
if enter {
|
||||
if right_click_cancels_placing(app) {
|
||||
crate::cmdline::escape(app);
|
||||
} else {
|
||||
// As the Enter key does: what was typed (`rec`, `@10,0`), or Enter when nothing was.
|
||||
crate::cmdline::submit(app);
|
||||
}
|
||||
}
|
||||
crate::dyngrips::menu(app, ui.ctx(), &xf);
|
||||
if idle && !app.canvas.snap_menu && app.canvas.grip_menu.is_some() {
|
||||
grip_menu(app, &resp);
|
||||
} else if idle || app.canvas.snap_menu {
|
||||
} else if (idle && !enter) || app.canvas.snap_menu {
|
||||
crate::context_menu::show(app, &resp);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! The canvas's right-click menus, after AutoCAD's shortcut menus:
|
||||
//!
|
||||
//! - **No command running** ([`entries`]): Repeat the last command, Recent Commands, the
|
||||
//! - **No command running** ([`entries`], opened by holding the button: a quick right-click is
|
||||
//! Enter, which repeats the last command): Repeat the last command, Recent Commands, the
|
||||
//! Clipboard and Isolate; with a selection the editing commands, Draw Order, Group, the edit
|
||||
//! commands of the selected object type, Select Similar and Deselect All; then Undo/Redo,
|
||||
//! Pan/Zoom, Quick Select, Find, Properties and Options.
|
||||
@@ -417,13 +418,15 @@ pub fn show(app: &mut CadApp, resp: &egui::Response) {
|
||||
#[derive(Clone, Copy, Default)]
|
||||
struct Press(f64, egui::Pos2);
|
||||
|
||||
/// The canvas's right button while a command runs (Shift/Ctrl+right-click is the snap menu's): a
|
||||
/// quick click is Enter — returns `true` when the caller should send it — and a click held for
|
||||
/// OPTIONS `rightClickDuration` opens the command menu ([`command_entries`]) at the pointer. With
|
||||
/// the time-sensitive right-click turned off, `rightClickCommand` says whether a click opens the
|
||||
/// menu or is Enter. Call it every frame
|
||||
/// with whether the pointer is on the canvas and whether a right-click ended there; it also shows
|
||||
/// the menu while it is open.
|
||||
/// The canvas's right button (Shift/Ctrl+right-click is the snap menu's). With the time-sensitive
|
||||
/// right-click on, a quick click is Enter — returns `true` when the caller should send it; between
|
||||
/// commands that runs what was typed or repeats the last command — and while a command runs a
|
||||
/// click held for OPTIONS `rightClickDuration` opens the command menu ([`command_entries`]) at the
|
||||
/// pointer (between commands a held click is left to the caller's shortcut menu). With it turned
|
||||
/// off, `rightClickCommand` says whether a click while a command runs opens the menu or is Enter,
|
||||
/// and between commands the caller follows `rightClickDefault` and `rightClickEdit`. Call it every
|
||||
/// frame with whether the pointer is on the canvas and whether a right-click ended there; it also
|
||||
/// shows the menu while it is open.
|
||||
pub fn in_command(app: &mut CadApp, ui: &egui::Ui, inside: bool, right_clicked: bool) -> bool {
|
||||
let ctx = ui.ctx().clone();
|
||||
let press_id = egui::Id::unique("cc_command_menu_press");
|
||||
@@ -448,15 +451,21 @@ pub fn in_command(app: &mut CadApp, ui: &egui::Ui, inside: bool, right_clicked:
|
||||
};
|
||||
let hold = f64::from(o.right_click_hold_ms) / 1000.0;
|
||||
let mut open = false;
|
||||
let mut quick = false;
|
||||
if released && let Some(Press(t0, p0)) = ctx.data_mut(|d| d.remove_temp::<Press>(press_id)) {
|
||||
// A drag isn't a click; a click held long enough asks for the menu.
|
||||
let still = pos.is_some_and(|p| p.distance(p0) <= 6.0);
|
||||
let held = if timed { now - t0 >= hold } else { menu };
|
||||
open = running && still && held;
|
||||
quick = !held;
|
||||
}
|
||||
let enter = running && inside && right_clicked && !open && (timed || !menu);
|
||||
if !running {
|
||||
return false;
|
||||
// Between commands a quick click is Enter too (as in AutoCAD): it runs the typed command,
|
||||
// or repeats the last one; held, it opens the shortcut menu. A grip with options keeps
|
||||
// its menu.
|
||||
let something = !app.cmd.buffer.trim().is_empty() || app.session.last_command.is_some();
|
||||
return timed && quick && inside && right_clicked && !app.canvas.snap_menu && app.canvas.grip_menu.is_none() && something;
|
||||
}
|
||||
let mut clicked = None;
|
||||
let popup = egui::Popup::new(popup_id, ctx, egui::PopupAnchor::PointerFixed, ui.layer_id())
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
//! | `SAVETIME` | minutes between automatic saves, 0–600 (0: off) |
|
||||
//! | `SAVEFILEPATH` | the folder automatic saves go to |
|
||||
//! | `ISAVEBAK` | 1: saving over a drawing keeps the previous file as `<name>.bak` (default); 0: no backup |
|
||||
//! | `timeSensitiveRightClick` | while a command runs, a quick right-click is Enter and holding the button opens the shortcut menu (default); `false`: `rightClickCommand` decides |
|
||||
//! | `timeSensitiveRightClick` | a quick right-click is Enter (between commands it runs what was typed, or repeats the last command) and holding the button opens the shortcut menu (default); `false`: `rightClickCommand` decides while a command runs, `rightClickDefault` and `rightClickEdit` between commands |
|
||||
//! | `rightClickDuration` | how long the right button is held to open the menu while a command runs, 100–2000 ms (250) |
|
||||
//! | `rightClickDefault`, `rightClickEdit` | a right-click with no command running and nothing (`Default`) or something (`Edit`) selected: `"menu"` (the shortcut menu, default) or `"repeat"` (the last command) |
|
||||
//! | `rightClickCommand` | a right-click while a command runs, with the time-sensitive right-click off: `"menu"` (default), `"enter"`, or `"menuWithOptions"` (the menu when the prompt has options, else Enter) |
|
||||
@@ -139,8 +139,11 @@ pub struct UiOptions {
|
||||
pub snap_marker_size: f32,
|
||||
/// The selection highlight colour; `None` keeps the theme's.
|
||||
pub selection_color: Option<Color32>,
|
||||
/// While a command runs: a quick right-click is Enter and a held one opens the shortcut menu
|
||||
/// (AutoCAD's time-sensitive right-click). Off: [`Self::right_click_command`] decides.
|
||||
/// A quick right-click is Enter and a held one opens the shortcut menu (AutoCAD's
|
||||
/// time-sensitive right-click). Between commands that Enter runs what was typed, or repeats
|
||||
/// the last command; with neither, the click opens the shortcut menu. Off:
|
||||
/// [`Self::right_click_command`] decides while a command runs, and [`Self::right_click_default`]
|
||||
/// and [`Self::right_click_edit`] between commands.
|
||||
pub time_sensitive_right_click: bool,
|
||||
/// How long the right button is held to open the menu while a command runs, in milliseconds.
|
||||
pub right_click_hold_ms: u32,
|
||||
|
||||
@@ -240,4 +240,42 @@ fn time_sensitive_right_click() {
|
||||
painted(&mut app, &ctx, Vec::new(), 3.1);
|
||||
assert!(app.session.running.is_none(), "a quick right-click is Enter: {}", app.session.prompt_text());
|
||||
assert_eq!(app.session.doc().unwrap().model.handles().len(), 1);
|
||||
|
||||
// Between commands a quick right-click is Enter too: it repeats LINE (it opened the shortcut
|
||||
// menu instead).
|
||||
painted(&mut app, &ctx, vec![quick(true)], 4.0);
|
||||
painted(&mut app, &ctx, vec![quick(false)], 4.05);
|
||||
let text = painted(&mut app, &ctx, Vec::new(), 4.1);
|
||||
assert!(app.session.running.is_some(), "a quick right-click repeats LINE: {}", app.session.prompt_text());
|
||||
assert!(!text.contains("Repeat LINE"), "no shortcut menu on a quick click:\n{text}");
|
||||
app.session.input(cadcraft_engine::Input::Cancel).unwrap();
|
||||
// Held, it opens the shortcut menu and repeats nothing.
|
||||
painted(&mut app, &ctx, vec![quick(true)], 5.0);
|
||||
painted(&mut app, &ctx, Vec::new(), 5.2);
|
||||
painted(&mut app, &ctx, vec![quick(false)], 5.0 + context_menu::HOLD_SECS + 0.1);
|
||||
let text = painted(&mut app, &ctx, Vec::new(), 5.5);
|
||||
assert!(text.contains("Repeat LINE"), "Repeat LINE missing from the painted menu:\n{text}");
|
||||
assert!(app.session.running.is_none(), "held, no repeat: {}", app.session.prompt_text());
|
||||
|
||||
// A quick click enters what was typed, as the Enter key does (#1387): a command name between
|
||||
// commands (not a repeat of LINE)…
|
||||
painted(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }],
|
||||
5.6,
|
||||
);
|
||||
// The menu closes on the frame after Escape.
|
||||
painted(&mut app, &ctx, Vec::new(), 5.7);
|
||||
app.cmd.buffer = "circle".into();
|
||||
painted(&mut app, &ctx, vec![quick(true)], 6.0);
|
||||
painted(&mut app, &ctx, vec![quick(false)], 6.05);
|
||||
painted(&mut app, &ctx, Vec::new(), 6.1);
|
||||
assert!(app.session.prompt_text().contains("center point"), "the typed CIRCLE starts: {}", app.session.prompt_text());
|
||||
// …and a point while a command runs.
|
||||
app.cmd.buffer = "5,5".into();
|
||||
painted(&mut app, &ctx, vec![quick(true)], 7.0);
|
||||
painted(&mut app, &ctx, vec![quick(false)], 7.05);
|
||||
painted(&mut app, &ctx, Vec::new(), 7.1);
|
||||
assert!(app.session.prompt_text().contains("radius"), "the typed center is entered: {}", app.session.prompt_text());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user