* claim: #6608 * Canvas: keep value boxes clear of the command window (#6608) * Canvas: describe how value boxes clear the command window (#6608) * Canvas: keep the value boxes clear of the gizmo handles (#6608) * ui-egui: format the value box regression test (#6608) * gpu: the startup MSAA check skips when there is no GPU adapter The check needs a real adapter to draw the multisampled view and to resolve it, so on a machine with no software Vulkan adapter it is skipped, with the reason printed, instead of failing the build. SOLIDCRAFT_REQUIRE_GPU=1 still makes a missing adapter a failure, as in the CI job that has a software adapter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+12
-1
@@ -3487,9 +3487,20 @@ mod glass_tests {
|
||||
assert!(preview[2] > preview[0] + 60, "the preview shows its own blue square: {preview:?}");
|
||||
}
|
||||
|
||||
/// The startup check that picks the viewport's anti-aliasing: it passes where the device
|
||||
/// draws the multisampled view, and a blank 1x resolve is detected. A machine with no
|
||||
/// software adapter has nothing to check, so the check is skipped there instead of failing
|
||||
/// the build (`SOLIDCRAFT_REQUIRE_GPU=1` makes a missing adapter a failure, as in CI).
|
||||
#[test]
|
||||
fn startup_msaa_check_passes_and_detects_a_blank_resolve() {
|
||||
let (adapter, device, queue) = crate::open_headless().expect("software adapter required for the startup check");
|
||||
let (adapter, device, queue) = match crate::open_headless() {
|
||||
Ok(d) => d,
|
||||
Err(e @ crate::GpuError::NoAdapter(_)) if std::env::var_os("SOLIDCRAFT_REQUIRE_GPU").is_none() => {
|
||||
eprintln!("skipping: {e}");
|
||||
return;
|
||||
}
|
||||
Err(e) => panic!("the startup check needs a GPU: {e}"),
|
||||
};
|
||||
let depth = crate::depth_format(&device, true);
|
||||
for format in [wgpu::TextureFormat::Rgba8Unorm, wgpu::TextureFormat::Bgra8Unorm, wgpu::TextureFormat::Bgra8UnormSrgb] {
|
||||
let window = GpuTarget { format, depth: None, samples: 1, tess: false };
|
||||
|
||||
+222
-10
@@ -330,6 +330,12 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj
|
||||
let triad = crate::dialogs_move::triad(app, &d);
|
||||
let rotation = draw_move_rotation(app, ui, painter, proj, &mut d);
|
||||
dragging |= rotation.is_some_and(|(_, changed)| changed);
|
||||
// The box stays clear of the triad's handles: it is a foreground area, so a box over a
|
||||
// handle takes the press and the drag never reaches the model (#6608).
|
||||
let mut place = box_place(app, proj);
|
||||
if let Some(t) = triad.as_ref() {
|
||||
place.handles = crate::gizmo::handles_region(proj, t);
|
||||
}
|
||||
let at = triad.map(|t| t.center).or_else(|| anchor(app, &d).map(|(base, _)| base));
|
||||
// Tab and Shift+Tab in the box show the next or previous value (Y after X; #4776),
|
||||
// keeping the keyboard in the box.
|
||||
@@ -350,7 +356,7 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj
|
||||
// beside the centre would cover the handles the user is reaching for.
|
||||
let off = if triad.is_some() { vec2(crate::gizmo::LEN_PX as f32 + 16.0, -12.0) } else { vec2(16.0, -30.0) };
|
||||
let box_at = rotation.map_or(bs + off, |(end, _)| end + vec2(16.0, -12.0));
|
||||
value_box_with(ui, label, value, box_at, focus || dragging, true);
|
||||
value_box_with(ui, label, value, box_at, focus || dragging, true, place);
|
||||
}
|
||||
app.dialog = Some(d);
|
||||
return;
|
||||
@@ -680,6 +686,7 @@ fn draw(app: &SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj,
|
||||
(ts + vec2(14.0, 8.0), egui::Align2::LEFT_TOP),
|
||||
*distance2 != before,
|
||||
false,
|
||||
box_place(app, proj),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -738,8 +745,13 @@ fn draw(app: &SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj,
|
||||
}
|
||||
let note = crate::drag_extrude::step_note(app);
|
||||
// Also without an arrow (the value does not evaluate yet): the box still keeps off the handles.
|
||||
// Clear of the command window first, then off the placement handles: the handles have the
|
||||
// last word, as a box over a grip takes the press meant for it (#6608).
|
||||
let place = box_place(app, proj);
|
||||
let size = box_size(ui, egui::Id::new("sc_canvas_area"), label, note.as_deref());
|
||||
let box_at = clear_of_dialog(rect_at(box_at, egui::Align2::LEFT_TOP, size), place).min;
|
||||
let box_at = crate::place_gizmo::yield_box(ui, anchor, box_at);
|
||||
value_box_noted(ui, label, value, box_at, focus || *value != before, note.as_deref());
|
||||
value_box_noted(ui, label, value, box_at, focus || *value != before, note.as_deref(), BoxPlace { dialog: None, ..place });
|
||||
if *value != before
|
||||
&& let Kind::Extrude { all, .. } = &mut d.kind
|
||||
{
|
||||
@@ -747,6 +759,24 @@ fn draw(app: &SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj,
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a value box may sit on the canvas: clear of the command window and of the
|
||||
/// manipulator's handles, inside the drawing area.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub(crate) struct BoxPlace {
|
||||
/// The command window's rectangle: a box that would cover it moves out of it (#6608).
|
||||
pub dialog: Option<egui::Rect>,
|
||||
/// The drawing area the box stays in.
|
||||
pub view: Option<egui::Rect>,
|
||||
/// The manipulator's handles: a box that would cover them moves out of them (#6608).
|
||||
pub handles: Option<egui::Rect>,
|
||||
}
|
||||
|
||||
/// The place the value boxes of a command may take: clear of the command window, inside the
|
||||
/// drawing area. The handles are added by the caller that draws a manipulator.
|
||||
pub(crate) fn box_place(app: &SolveApp, proj: &Proj) -> BoxPlace {
|
||||
BoxPlace { dialog: app.viewport.dialog_rect, view: Some(proj.rect), handles: None }
|
||||
}
|
||||
|
||||
/// The command's main value in the viewport, next to the geometry: the keyboard goes here while
|
||||
/// the window is open, so a number typed straight after a pick sets the value. `at` is its
|
||||
/// top-left corner. `select_all` re-selects the whole field, both right after a pick and on every
|
||||
@@ -756,21 +786,21 @@ fn draw(app: &SolveApp, ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj,
|
||||
/// the pointer is over it: the wheel steps its value (`value_step`), which moves the arrow tip
|
||||
/// the box follows, and a box sliding out from under the pointer would hand the next notch to
|
||||
/// the camera.
|
||||
fn value_box(ui: &mut egui::Ui, label: &str, value: &mut String, at: Pos2, select_all: bool) {
|
||||
value_box_with(ui, label, value, at, select_all, false);
|
||||
fn value_box(ui: &mut egui::Ui, label: &str, value: &mut String, at: Pos2, select_all: bool, place: BoxPlace) {
|
||||
value_box_with(ui, label, value, at, select_all, false, place);
|
||||
}
|
||||
|
||||
/// [`value_box`]; with `keep_tab` Tab stays in the box for the caller (the Move box steps
|
||||
/// through its values with it).
|
||||
fn value_box_with(ui: &mut egui::Ui, label: &str, value: &mut String, at: Pos2, select_all: bool, keep_tab: bool) {
|
||||
fn value_box_with(ui: &mut egui::Ui, label: &str, value: &mut String, at: Pos2, select_all: bool, keep_tab: bool, place: BoxPlace) {
|
||||
let ids = (egui::Id::new("sc_canvas_area"), egui::Id::new("sc_canvas_value"));
|
||||
value_box_in(ui, ids, label, value, (at, egui::Align2::LEFT_TOP), select_all, keep_tab);
|
||||
value_box_in(ui, ids, label, value, (at, egui::Align2::LEFT_TOP), select_all, keep_tab, place);
|
||||
}
|
||||
|
||||
/// [`value_box`] with a note after the field (a pull's step size).
|
||||
fn value_box_noted(ui: &mut egui::Ui, label: &str, value: &mut String, at: Pos2, select_all: bool, note: Option<&str>) {
|
||||
fn value_box_noted(ui: &mut egui::Ui, label: &str, value: &mut String, at: Pos2, select_all: bool, note: Option<&str>, place: BoxPlace) {
|
||||
let ids = (egui::Id::new("sc_canvas_area"), egui::Id::new("sc_canvas_value"));
|
||||
value_box_full(ui, ids, label, value, (at, egui::Align2::LEFT_TOP), (select_all, false), note);
|
||||
value_box_full(ui, ids, label, value, (at, egui::Align2::LEFT_TOP), (select_all, false), note, place);
|
||||
}
|
||||
|
||||
/// [`value_box_with`] under its own ids (its area's and its field's), for a value beside the main
|
||||
@@ -784,8 +814,9 @@ pub(crate) fn value_box_in(
|
||||
at: (Pos2, egui::Align2),
|
||||
select_all: bool,
|
||||
keep_tab: bool,
|
||||
place: BoxPlace,
|
||||
) -> Option<egui::Rect> {
|
||||
value_box_full(ui, ids, label, value, at, (select_all, keep_tab), None)
|
||||
value_box_full(ui, ids, label, value, at, (select_all, keep_tab), None, place)
|
||||
}
|
||||
|
||||
/// [`value_box_in`] with a short dimmed note after the field (a pull's step size).
|
||||
@@ -797,6 +828,7 @@ fn value_box_full(
|
||||
(at, pivot): (Pos2, egui::Align2),
|
||||
(select_all, keep_tab): (bool, bool),
|
||||
note: Option<&str>,
|
||||
place: BoxPlace,
|
||||
) -> Option<egui::Rect> {
|
||||
let t = Tokens::get();
|
||||
// Held in place while the pointer is over it and value stepping is on (see `value_box`): by
|
||||
@@ -807,6 +839,15 @@ fn value_box_full(
|
||||
.memory(|m| m.area_rect(area))
|
||||
.filter(|r| crate::value_step::enabled(ui.ctx()) && pointer.is_some_and(|p| r.contains(p)))
|
||||
.map_or(at, |r| pivot.pos_in_rect(&r));
|
||||
// #6608: the box moves out of the command window it would otherwise cover, and out of the
|
||||
// manipulator's handles: it keeps its place by its geometry, but a box that would cover
|
||||
// either of them moves out of it.
|
||||
let at = if place.dialog.is_some() || place.handles.is_some() {
|
||||
let kept = clear_of_dialog(rect_at(at, pivot, box_size(ui, area, label, note)), place);
|
||||
pivot.pos_in_rect(&kept)
|
||||
} else {
|
||||
at
|
||||
};
|
||||
let mut field = None;
|
||||
Container::new(ui.ctx(), Surface::Canvas).area(area).fixed_pos(at).pivot(pivot).order(egui::Order::Foreground).show(ui.ctx(), |ui| {
|
||||
Container::popup_frame(ui.style()).inner_margin(egui::Margin::symmetric(6, 3)).show(ui, |ui| {
|
||||
@@ -831,6 +872,93 @@ fn value_box_full(
|
||||
field
|
||||
}
|
||||
|
||||
/// The gap left between a value box and what it must not cover (px).
|
||||
const DIALOG_GAP: f32 = 4.0;
|
||||
|
||||
/// Where a value box goes so it does not cover the command window nor the manipulator's
|
||||
/// handles: whole, beside what it would cover (leaving a gap of `DIALOG_GAP`), and inside the
|
||||
/// drawing area (`view`), like a box kept in view (#6608). The sides of the command window
|
||||
/// are tried first, then the sides of the handles, and the first side that leaves the box
|
||||
/// clear of both wins. A box that misses them keeps its place, and one that no side clears
|
||||
/// keeps it too, unless a side leaves the handles free: a box over a handle takes the press
|
||||
/// the user meant for the handle.
|
||||
fn clear_of_dialog(rect: egui::Rect, place: BoxPlace) -> egui::Rect {
|
||||
let mut obstacles: Vec<egui::Rect> = Vec::new();
|
||||
if let Some(dialog) = place.dialog {
|
||||
obstacles.push(dialog);
|
||||
}
|
||||
if let Some(handles) = place.handles {
|
||||
obstacles.push(handles);
|
||||
}
|
||||
if obstacles.iter().all(|o| !rect.intersects(*o)) {
|
||||
return rect;
|
||||
}
|
||||
// The sides the box could go to: each moves it whole, just past the obstacle's edge. The
|
||||
// left one comes first: it slides the box back over the part that overlaps it, instead of
|
||||
// jumping it over the whole obstacle.
|
||||
let mut free = None;
|
||||
for o in &obstacles {
|
||||
let sides = [
|
||||
egui::vec2(o.left() - DIALOG_GAP - rect.right(), 0.0),
|
||||
egui::vec2(o.right() + DIALOG_GAP - rect.left(), 0.0),
|
||||
egui::vec2(0.0, o.top() - DIALOG_GAP - rect.bottom()),
|
||||
egui::vec2(0.0, o.bottom() + DIALOG_GAP - rect.top()),
|
||||
];
|
||||
for d in sides {
|
||||
let moved = keep_in_view(rect.translate(d), place.view);
|
||||
// This side leaves the box clear of everything: the next one may clear it too.
|
||||
if obstacles.iter().all(|o| !moved.intersects(*o)) {
|
||||
return moved;
|
||||
}
|
||||
// A box that still covers the command window but leaves the handles free is
|
||||
// better than one over a handle: the handle takes the press (#6608).
|
||||
if free.is_none() && place.handles.is_some_and(|h| !moved.intersects(h)) {
|
||||
free = Some(moved);
|
||||
}
|
||||
}
|
||||
}
|
||||
free.unwrap_or(rect)
|
||||
}
|
||||
|
||||
/// A rectangle kept inside the drawing area: one that would leave it moves back to its edge.
|
||||
fn keep_in_view(rect: egui::Rect, view: Option<egui::Rect>) -> egui::Rect {
|
||||
let Some(view) = view else { return rect };
|
||||
let size = rect.size();
|
||||
let min = rect.min.clamp(view.min, (view.max - size).max(view.min));
|
||||
egui::Rect::from_min_size(min, size)
|
||||
}
|
||||
|
||||
/// The rectangle a value box of `size` takes when its pivot sits at `at`.
|
||||
fn rect_at(at: Pos2, pivot: egui::Align2, size: egui::Vec2) -> egui::Rect {
|
||||
let offset = pivot.pos_in_rect(&egui::Rect::from_min_size(Pos2::ZERO, size));
|
||||
egui::Rect::from_min_size(at - egui::vec2(offset.x, offset.y), size)
|
||||
}
|
||||
|
||||
/// The size of a value box: the one it had last frame, or measured from the fonts when it is
|
||||
/// new (its label, its field, and the margin the popup frame puts around them).
|
||||
fn box_size(ui: &egui::Ui, area: egui::Id, label: &str, note: Option<&str>) -> egui::Vec2 {
|
||||
if let Some(r) = ui.ctx().memory(|m| m.area_rect(area)) {
|
||||
let size = r.size();
|
||||
if size.is_finite() && size.x > 0.0 && size.y > 0.0 {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
let t = Tokens::get();
|
||||
let font = egui::FontId::proportional(t.font_caption);
|
||||
let width = |text: String| ui.painter().layout_no_wrap(text, font.clone(), t.text_dim).size().x;
|
||||
let mut w = width(crate::i18n::tr_label(label).to_string()) + t.space_24 * 3.0;
|
||||
let mut parts = 1;
|
||||
if let Some(note) = note {
|
||||
w += width(note.to_string());
|
||||
parts += 1;
|
||||
}
|
||||
// The gap between the row's parts, and the popup frame's margin around them.
|
||||
let gap = ui.spacing().item_spacing.x;
|
||||
let height = ui.fonts_mut(|fonts| fonts.row_height(&font));
|
||||
let size = egui::vec2(w + gap * parts as f32 + 12.0, height + 6.0);
|
||||
if size.is_finite() && size.x > 0.0 && size.y > 0.0 { size } else { crate::sketch_dims::BOX }
|
||||
}
|
||||
|
||||
/// How far (logical points) from an arrow's stem a press still takes the arrow.
|
||||
const ARROW_STEM_REACH: f32 = 6.0;
|
||||
|
||||
@@ -1455,7 +1583,7 @@ fn draw_revolve(
|
||||
});
|
||||
} else if let Kind::Revolve { angle, .. } = &mut d.kind {
|
||||
let dragging = *angle != angle_before;
|
||||
value_box(ui, crate::i18n::tr_label("Angle"), angle, box_at, focus || dragging);
|
||||
value_box(ui, crate::i18n::tr_label("Angle"), angle, box_at, focus || dragging, box_place(app, proj));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1668,6 +1796,90 @@ mod tests {
|
||||
assert_eq!(format_len(&solidcraft_engine::doc::Document::default(), -2.5), "-2.5 mm");
|
||||
assert_eq!(format_len(&solidcraft_engine::doc::Document::default(), -0.0001), "-0.0001 mm");
|
||||
}
|
||||
|
||||
/// #6608: a canvas value box never covers the command window: it moves out of it.
|
||||
#[test]
|
||||
fn a_value_box_keeps_clear_of_the_command_window() {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
h.app.run("solid.box", serde_json::json!({"length": 40, "width": 30, "height": 20})).unwrap();
|
||||
h.app.session.selection = vec![Sel::Body { name: "Body1".into() }];
|
||||
h.step(&serde_json::json!({"start": "solid.move"})).unwrap();
|
||||
h.frames(6);
|
||||
let box_rect = h.ctx.memory(|m| m.area_rect(egui::Id::new("sc_canvas_area"))).expect("the value box");
|
||||
let window = h.app.viewport.dialog_rect.expect("the command window");
|
||||
// Drag the command window over the value box: the box must move out of it.
|
||||
let title = crate::scenario::handle_at("dialog:title").expect("the window's title");
|
||||
let dx = box_rect.center().x - 20.0 - window.left();
|
||||
h.call("ui.drag", serde_json::json!({"x0": title.x, "y0": title.y, "x1": title.x + dx, "y1": title.y, "steps": 8}));
|
||||
h.frames(6);
|
||||
let window = h.app.viewport.dialog_rect.unwrap();
|
||||
assert!(window.contains(box_rect.center()), "the window {window:?} did not reach the value box {box_rect:?}");
|
||||
let kept = h.ctx.memory(|m| m.area_rect(egui::Id::new("sc_canvas_area"))).expect("the value box");
|
||||
assert!(!kept.intersects(window), "the value box {kept:?} covers the command window {window:?}");
|
||||
}
|
||||
|
||||
/// #6608: a value box that has to move out of the command window does not cover the
|
||||
/// manipulator's handles: the box is a foreground area, so it took the press and the drag
|
||||
/// on a ring never reached the model.
|
||||
#[test]
|
||||
fn a_value_box_keeps_clear_of_the_handles() {
|
||||
let mut h = crate::scenario::Harness::new();
|
||||
h.run(&serde_json::json!([
|
||||
{"call": "engine.execute", "params": {"command": "solid.box", "params": {"length": 20, "width": 30, "height": 10}}},
|
||||
{"call": "ui.view", "params": {"view": "iso"}},
|
||||
{"start": "solid.move"},
|
||||
{"click": {"world": [10, 15, 10]}},
|
||||
{"key": "Enter"},
|
||||
{"start": "solid.move"},
|
||||
{"click": {"world": [10, 15, 10]}},
|
||||
{"drag": [{"gizmo": "x"}, {"gizmo": "x", "by": [20, 0, 0]}]},
|
||||
{"key": "Enter"},
|
||||
{"start": "solid.move"},
|
||||
{"click": {"world": [30, 15, 10]}}
|
||||
]))
|
||||
.unwrap();
|
||||
let box_rect = h.ctx.memory(|m| m.area_rect(egui::Id::new("sc_canvas_area"))).expect("the value box");
|
||||
let handles = crate::scenario::handles("move_");
|
||||
assert!(!handles.is_empty(), "the triad drew no handles");
|
||||
for (name, p) in &handles {
|
||||
// A press takes a handle a few px off its line (the ball's is the widest).
|
||||
assert!(!box_rect.expand(crate::gizmo::HIT_TOLERANCE).contains(*p), "the value box {box_rect:?} covers the handle {name} at {p:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A box that lands on the command window moves out of it, whole, and a box that misses it
|
||||
/// stays where it is (#6608). A box that lands on the handles moves off them too, and one
|
||||
/// that cannot clear both keeps off the handles.
|
||||
#[test]
|
||||
fn a_value_box_moves_out_of_the_command_window() {
|
||||
let dialog = egui::Rect::from_min_size(egui::pos2(700.0, 200.0), egui::vec2(280.0, 300.0));
|
||||
let view = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1000.0, 700.0));
|
||||
let on_the_window = egui::Rect::from_min_size(egui::pos2(800.0, 350.0), egui::vec2(140.0, 24.0));
|
||||
let kept = clear_of_dialog(on_the_window, BoxPlace { dialog: Some(dialog), view: Some(view), handles: None });
|
||||
assert!(!kept.intersects(dialog), "the box {kept:?} still covers the window {dialog:?}");
|
||||
assert_eq!(kept.size(), on_the_window.size(), "the box keeps its size");
|
||||
let clear = egui::Rect::from_min_size(egui::pos2(100.0, 100.0), egui::vec2(140.0, 24.0));
|
||||
let place = BoxPlace { dialog: Some(dialog), view: Some(view), handles: None };
|
||||
assert_eq!(clear_of_dialog(clear, place), clear, "a box that misses the window stays");
|
||||
}
|
||||
|
||||
/// A box that would cover a handle moves off it, and one that cannot clear both the window
|
||||
/// and the handles keeps off the handles: the handle takes the press (#6608).
|
||||
#[test]
|
||||
fn a_value_box_moves_out_of_the_handles() {
|
||||
let dialog = egui::Rect::from_min_size(egui::pos2(700.0, 200.0), egui::vec2(280.0, 300.0));
|
||||
let view = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1000.0, 700.0));
|
||||
let handles = egui::Rect::from_min_size(egui::pos2(500.0, 300.0), egui::vec2(120.0, 120.0));
|
||||
let on_the_handles = egui::Rect::from_min_size(egui::pos2(540.0, 340.0), egui::vec2(140.0, 24.0));
|
||||
let kept = clear_of_dialog(on_the_handles, BoxPlace { dialog: Some(dialog), view: Some(view), handles: Some(handles) });
|
||||
assert!(!kept.intersects(handles), "the box {kept:?} still covers the handles {handles:?}");
|
||||
assert_eq!(kept.size(), on_the_handles.size(), "the box keeps its size");
|
||||
// The window and the handles side by side: no side clears both, so the box keeps off
|
||||
// the handles and covers the window instead.
|
||||
let side_by_side = egui::Rect::from_min_size(egui::pos2(560.0, 340.0), egui::vec2(280.0, 24.0));
|
||||
let kept = clear_of_dialog(side_by_side, BoxPlace { dialog: Some(dialog), view: Some(view), handles: Some(handles) });
|
||||
assert!(!kept.intersects(handles), "the box {kept:?} still covers the handles {handles:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -70,6 +70,9 @@ const DIRS: [Vec3; 3] = [Vec3::X, Vec3::Y, Vec3::Z];
|
||||
/// Arrow length on screen (px).
|
||||
pub const LEN_PX: f64 = 110.0;
|
||||
|
||||
/// How near a handle a press still takes it (px): the widest, the centre ball.
|
||||
pub const HIT_TOLERANCE: f32 = 9.0;
|
||||
|
||||
thread_local! {
|
||||
/// The last triad drawn: centre and arrow length in mm (for scenarios and tests).
|
||||
static LAST: RefCell<Option<(Vec3, f64)>> = const { RefCell::new(None) };
|
||||
@@ -207,7 +210,7 @@ fn shapes(proj: &Proj, t: &Triad, l: f64) -> Option<Shapes> {
|
||||
}
|
||||
|
||||
fn hit(s: &Shapes, p: Pos2) -> Option<Handle> {
|
||||
if s.ball.distance(p) < 9.0 {
|
||||
if s.ball.distance(p) < HIT_TOLERANCE {
|
||||
return Some(Handle::Ball);
|
||||
}
|
||||
if let Some((i, ..)) = s.arrows.iter().find(|(_, a, b)| seg_dist(p, *a, *b) < 6.0) {
|
||||
@@ -247,6 +250,36 @@ pub(crate) fn contains_pointer(proj: &Proj, t: &Triad, p: Pos2) -> bool {
|
||||
mm_per_px(proj, t.center).and_then(|scale| shapes(proj, t, scale * LEN_PX)).is_some_and(|sh| hit(&sh, p).is_some())
|
||||
}
|
||||
|
||||
/// The region the triad's handles occupy on screen: where a press takes one of them. A value
|
||||
/// box over it takes the press before the gizmo sees it (#6608).
|
||||
pub fn handles_region(proj: &Proj, t: &Triad) -> Option<egui::Rect> {
|
||||
let l = mm_per_px(proj, t.center)? * LEN_PX;
|
||||
let sh = shapes(proj, t, l)?;
|
||||
let mut pts = vec![sh.ball];
|
||||
for (_, a, b) in &sh.arrows {
|
||||
pts.push(*a);
|
||||
pts.push(*b);
|
||||
}
|
||||
for (_, ring) in &sh.rings {
|
||||
pts.extend(ring.iter().copied());
|
||||
}
|
||||
for (_, q) in &sh.planes {
|
||||
for (&a, &b) in q.edges() {
|
||||
pts.push(a);
|
||||
pts.push(b);
|
||||
}
|
||||
}
|
||||
let mut min = sh.ball;
|
||||
let mut max = sh.ball;
|
||||
for p in pts {
|
||||
min.x = min.x.min(p.x);
|
||||
min.y = min.y.min(p.y);
|
||||
max.x = max.x.max(p.x);
|
||||
max.y = max.y.max(p.y);
|
||||
}
|
||||
Some(egui::Rect::from_min_max(min, max).expand(HIT_TOLERANCE))
|
||||
}
|
||||
|
||||
/// Draw the triad and run a drag on it. `step` is the distance snap step.
|
||||
pub fn show(ui: &mut egui::Ui, painter: &egui::Painter, proj: &Proj, id: egui::Id, t: &Triad, step: f64) -> Option<Drag> {
|
||||
let tk = Tokens::get();
|
||||
|
||||
@@ -307,6 +307,7 @@ pub(crate) fn canvas(app: &SolveApp, ui: &mut egui::Ui, painter: &egui::Painter,
|
||||
at,
|
||||
focus,
|
||||
false,
|
||||
crate::canvas::box_place(app, proj),
|
||||
);
|
||||
if let Some(r) = r {
|
||||
crate::scenario::publish_handle(&format!("canvas:{label}"), r.center());
|
||||
|
||||
@@ -534,7 +534,7 @@ fn boxes(app: &SolveApp, ui: &mut egui::Ui, proj: &Proj, t: &mut Tool) -> Option
|
||||
}
|
||||
|
||||
/// About the size of a value box, for keeping it in view.
|
||||
const BOX: egui::Vec2 = egui::vec2(76.0, 24.0);
|
||||
pub(crate) const BOX: egui::Vec2 = egui::vec2(76.0, 24.0);
|
||||
|
||||
/// Where a value box whose top left would be `pos` goes so it stays in the drawing area `view`:
|
||||
/// as it is when it fits; else mirrored through the pointer (a box set off the cursor, past the
|
||||
|
||||
Reference in New Issue
Block a user