Merge pull request #8613 from dotCooCoo/fix/followup-7310

Artboard tool: add button tooltips show only where a click adds an artboard
This commit is contained in:
BFlat
2026-11-19 15:04:25 +07:00
committed by GitHub
3 changed files with 137 additions and 6 deletions
+5 -1
View File
@@ -427,7 +427,11 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
draw_overlays(&painter, &xf, &overlays, &t, HandleLook::of(&app.session.prefs), &mut shared_paths);
app.canvas.shared_paths = shared_paths;
crate::panels::tabs::paint_stop_guide(app, &painter, &xf);
overlay_hover_text(ui, &xf, &overlays, ui.data(|d| d.get_temp::<Drag>(drag_id())).is_some());
// The tooltips say what a click does, so none shows where the click does something else:
// while Space lends a view tool, or over an artboard's name.
let space = ui.input(|i| drag::space_lends_view_tools(app, i.modifiers, i.key_down(egui::Key::Space)));
let quiet = space || ui.data(|d| d.get_temp::<Drag>(drag_id())).is_some();
overlay_hover_text(ui, &xf, &overlays, quiet, |p| artboards::artboard_name_at(app, ui, &xf, p).is_some());
if !revolve_edit {
shaper_widget_overlay(app, &painter, &xf);
crate::panels::three_d::paint_graphic_handles(app, &painter, &xf);
+11 -5
View File
@@ -617,9 +617,11 @@ pub(super) fn draw_overlays(p: &egui::Painter, xf: &Xf, overlays: &[Overlay], t:
/// The tooltips of the tool's [`Overlay::HoverText`] regions. Each region is a hover-only widget
/// over the canvas, which keeps the clicks and drags; while the pointer rests inside a region's
/// disc, egui shows its text, translated, after its usual tooltip delay. No tooltip shows during a
/// canvas drag (`dragging`) or while a pointer button is down.
pub(super) fn overlay_hover_text(ui: &egui::Ui, xf: &Xf, overlays: &[Overlay], dragging: bool) {
/// disc, egui shows its text, translated, after its usual tooltip delay. Only the part of a disc
/// inside the canvas (`xf.rect`) has a tooltip, not the part under the rulers or scroll bars. No
/// tooltip shows while `quiet` (a canvas drag, or Space lending a view tool), while a pointer
/// button is down, or where `taken` says a press goes elsewhere (an artboard's name).
pub(super) fn overlay_hover_text(ui: &egui::Ui, xf: &Xf, overlays: &[Overlay], quiet: bool, taken: impl Fn(Pos2) -> bool) {
let pressed = ui.input(|i| i.pointer.any_down());
for (i, o) in overlays.iter().enumerate() {
let Overlay::HoverText { center, radius, text } = o else { continue };
@@ -628,9 +630,13 @@ pub(super) fn overlay_hover_text(ui: &egui::Ui, xf: &Xf, overlays: &[Overlay], d
if !(r.is_finite() && r > 0.0 && c.is_finite()) {
continue;
}
let area = egui::Rect::from_center_size(c, vec2(2.0 * r, 2.0 * r)).intersect(xf.rect);
if !area.is_positive() {
continue;
}
let id = egui::Id::unique("canvas-hover-text").with(i);
let resp = ui.interact(egui::Rect::from_center_size(c, vec2(2.0 * r, 2.0 * r)), id, egui::Sense::hover());
if !dragging && !pressed && resp.hover_pos().is_some_and(|p| p.distance(c) <= r) {
let resp = ui.interact(area, id, egui::Sense::hover());
if !quiet && !pressed && resp.hover_pos().is_some_and(|p| p.distance(c) <= r && xf.rect.contains(p) && !taken(p)) {
resp.on_hover_text(crate::i18n::t(text));
}
}
+121
View File
@@ -1249,6 +1249,127 @@ fn an_artboard_add_button_shows_its_tooltip_while_the_pointer_rests_on_it() {
}
}
/// The screen centers and radii of the Artboard tool's add-button tooltips (`tip`) in the view `xf`.
fn add_button_tips(app: &mut VectorcraftApp, xf: &Xf, tip: &str) -> Vec<(Pos2, f32)> {
let view = app.view_info();
app.session
.overlays(view)
.into_iter()
.filter_map(|o| match o {
Overlay::HoverText { center, radius, text } if text == tip => Some((xf.to_screen(center), (radius * xf.zoom) as f32)),
_ => None,
})
.collect()
}
/// Whether `tip` shows while the pointer rests at `at` for two seconds from `*t`, which moves on.
fn rests_with_tooltip(app: &mut VectorcraftApp, ctx: &egui::Context, t: &mut f64, at: Pos2, tip: &str) -> bool {
texts_at(app, ctx, *t, vec![egui::Event::PointerMoved(at)]);
let mut seen = false;
for _ in 0..20 {
*t += 0.1;
seen |= texts_at(app, ctx, *t, vec![]).iter().any(|s| s == tip);
}
seen
}
/// While Space lends a view tool, a press on an add button pans the view instead of adding an
/// artboard: the button shows no tooltip until Space is up.
#[test]
fn an_artboard_add_button_has_no_tooltip_while_space_is_held() {
use egui::{Event, Modifiers};
let tip = vectorcraft_tools::xform::EDGE_BUTTON_TIP;
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.session.execute("file.new", &json!({"width": 200, "height": 100})).unwrap();
app.select_tool("artboard");
let ctx = egui::Context::default();
texts_at(&mut app, &ctx, 0.0, vec![]);
let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap());
let (at, _) = add_button_tips(&mut app, &xf, tip).into_iter().max_by(|a, b| a.0.y.total_cmp(&b.0.y)).unwrap();
let space = |pressed| Event::Key { key: egui::Key::Space, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE };
let mut t = 1.0;
texts_at(&mut app, &ctx, t, vec![Event::PointerMoved(at), space(true)]);
for _ in 0..20 {
t += 0.1;
assert!(!texts_at(&mut app, &ctx, t, vec![]).iter().any(|s| s == tip), "no tooltip while Space is held");
}
t += 0.1;
texts_at(&mut app, &ctx, t, vec![space(false)]);
assert!(rests_with_tooltip(&mut app, &ctx, &mut t, at, tip), "the tooltip shows again once Space is up");
}
/// On a narrow artboard with a long name, the name can cover part of the top add button, and a
/// press there selects the named artboard: that part shows no tooltip, and the rest of the button
/// keeps it.
#[test]
fn an_artboard_add_button_has_no_tooltip_where_the_artboard_name_covers_it() {
let tip = vectorcraft_tools::xform::EDGE_BUTTON_TIP;
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.session.execute("file.new", &json!({"width": 20, "height": 100})).unwrap();
let name = "An artboard name long enough to run past the middle of its top edge";
app.session.execute("artboard.setProps", &json!({"artboards": [{"index": 0, "name": name}]})).unwrap();
app.select_tool("artboard");
let ctx = egui::Context::default();
texts_at(&mut app, &ctx, 0.0, vec![]);
let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap());
let (at, r) = add_button_tips(&mut app, &xf, tip).into_iter().min_by(|a, b| a.0.y.total_cmp(&b.0.y)).unwrap();
// The points of the button's disc, split by whether the canvas's name hit test takes them.
let probe = egui::Context::default();
let named = |p: Pos2| {
let mut hit = false;
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))), ..Default::default() };
let mut out = probe.run_ui(raw, |ui| hit = super::artboards::artboard_name_at(&app, ui, &xf, p).is_some());
out.textures_delta.clear();
hit
};
let steps = || (-6i8..=6).map(f32::from);
let disc: Vec<Pos2> = steps().flat_map(|dx| steps().map(move |dy| at + vec2(dx, dy))).filter(|p| p.distance(at) <= r - 0.5).collect();
let covered = disc.iter().copied().find(|p| named(*p)).expect("the name covers part of the button");
let clear = disc.iter().copied().rev().find(|p| !named(*p)).expect("part of the button is clear of the name");
let mut t = 1.0;
assert!(!rests_with_tooltip(&mut app, &ctx, &mut t, covered, tip), "no tooltip where the name takes the press");
assert!(rests_with_tooltip(&mut app, &ctx, &mut t, clear, tip), "the tooltip shows on the rest of the button");
}
/// An add button panned under the scroll bars is not drawn and takes no press: none of it shows a
/// tooltip, in the square where the scroll bars meet or over a scroll bar, while the part of a
/// button still on the canvas keeps its tooltip.
#[test]
fn an_artboard_add_button_has_no_tooltip_outside_the_canvas() {
let tip = vectorcraft_tools::xform::EDGE_BUTTON_TIP;
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.session.execute("file.new", &json!({"width": 200, "height": 100})).unwrap();
app.select_tool("artboard");
let ctx = egui::Context::default();
texts_at(&mut app, &ctx, 0.0, vec![]);
let rect = app.canvas_rect.unwrap();
// Pan the view so the right button's center lands on `to`, and return the button.
let pan_right_button_to = |app: &mut VectorcraftApp, t: f64, to: Pos2| {
let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap());
let (at, _) = add_button_tips(app, &xf, tip).into_iter().max_by(|a, b| a.0.x.total_cmp(&b.0.x)).unwrap();
let d = to - at;
if let Some(v) = app.view_mut() {
v.center = Point::new(v.center.x - f64::from(d.x) / v.zoom, v.center.y - f64::from(d.y) / v.zoom);
v.fitted = true;
}
texts_at(app, &ctx, t, vec![]);
let xf = Xf::new(app.canvas_rect.unwrap(), app.view().unwrap());
let (at, r) = add_button_tips(app, &xf, tip).into_iter().max_by(|a, b| a.0.x.total_cmp(&b.0.x)).unwrap();
assert!(at.distance(to) < 0.5, "the button moved to {to:?}: {at:?}");
(at, r)
};
// The middle of the square where the scroll bars meet, right of and below the canvas.
let corner = rect.max + vec2(SCROLL_BAR / 2.0, SCROLL_BAR / 2.0);
let mut t = 1.0;
let (at, _) = pan_right_button_to(&mut app, t, corner);
assert!(!rect.contains(at));
assert!(!rests_with_tooltip(&mut app, &ctx, &mut t, at, tip), "no tooltip in the corner between the scroll bars");
// Half on the canvas, half over the vertical scroll bar.
let (at, r) = pan_right_button_to(&mut app, t, pos2(rect.max.x, rect.center().y));
assert!(!rests_with_tooltip(&mut app, &ctx, &mut t, at + vec2(r - 2.0, 0.0), tip), "no tooltip over the scroll bar");
assert!(rests_with_tooltip(&mut app, &ctx, &mut t, at - vec2(r - 2.0, 0.0), tip), "the tooltip shows on the part on the canvas");
}
#[test]
fn shift_clicking_canvas_artboard_label_toggles_multi_selection() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());