Tools: a tool card shows only while tool tips are on

Turning Show Tool Tips off now puts away a card that is showing. A button whose card a click put away forgets that once the pointer leaves it, with the cards off too, so the next rest on it shows the card.
This commit is contained in:
dotCooCoo committed 2026-11-16 10:17:08 -08:00
1 parent 10e1c7472f
commit 41cf112b23
3 files changed
+62 -12

No files matched your search

+3 -2
View File
@@ -332,8 +332,9 @@ fn apply(app: &mut VectorcraftApp, ctx: &egui::Context, force: bool) {
app.canvas.key = None;
ctx.data_mut(|d| d.insert_temp(id, Some(want)));
}
let cards =
crate::toolbar::card::CardPrefs { on: app.session.prefs.show_tool_cards, animated_zoom: crate::canvas::animated_zoom(&app.session.prefs) };
// Cards show only with Show Tool Tips on: an open card goes away as soon as tool tips are turned off.
let p = &app.session.prefs;
let cards = crate::toolbar::card::CardPrefs { on: p.show_tool_cards && p.show_tool_tips, animated_zoom: crate::canvas::animated_zoom(p) };
crate::toolbar::card::set_prefs(ctx, cards);
let z = app.session.prefs.ui_scaling.clamp(0.75, 2.0) as f32;
if (ctx.zoom_factor() - z).abs() > 1e-3 {
+21 -10
View File
@@ -72,11 +72,13 @@ pub(crate) fn hover(resp: Response, tool: &ToolInfo, side: Side, tip: Option<Str
let prefs = prefs(&ctx);
let allowed = side == Side::Row || !flyout_drawn(&ctx);
let description = if prefs.on && allowed { tool_description(tool.id) } else { None };
// A button the pointer is not over shows neither a card nor a tool tip: skip measuring its card,
// and let `quiet` drop the button's quiet mark.
if description.is_some() && !resp.hovered() {
quiet(&ctx, &resp);
return resp;
// A button the pointer is not on shows neither a card nor a tool tip. Its quiet mark goes, with
// the cards off too, so the next rest on it shows its card; and its card is not measured.
if !pointer_on(&ctx, &resp) {
forget_quiet(&ctx, &resp);
if description.is_some() {
return resp;
}
}
let place = description.and_then(|d| placement(&ctx, resp.rect, side, height(tool.id, prefs.animated_zoom)).map(|p| (d, p)));
let Some((description, (align, others, gap))) = place else {
@@ -143,11 +145,8 @@ fn flyout_opens_left(ctx: &Context) -> bool {
/// modifier key is held, or a press, key, modifier, scroll or pinch came since it arrived.
fn quiet(ctx: &Context, resp: &Response) -> bool {
let quiet_for: Option<Id> = ctx.data(|d| d.get_temp(quiet_id()));
let over = resp.hovered() && ctx.input(|i| i.pointer.hover_pos()).is_some_and(|p| resp.rect.contains(p));
if !over {
if quiet_for == Some(resp.id) {
ctx.data_mut(|d| d.remove::<Id>(quiet_id()));
}
if !pointer_on(ctx, resp) {
forget_quiet(ctx, resp);
return true;
}
let busy = ctx.input(|i| {
@@ -176,6 +175,18 @@ fn quiet(ctx: &Context, resp: &Response) -> bool {
quiet_for == Some(resp.id)
}
/// Whether the pointer rests on the button `resp`.
fn pointer_on(ctx: &Context, resp: &Response) -> bool {
resp.hovered() && ctx.input(|i| i.pointer.hover_pos()).is_some_and(|p| resp.rect.contains(p))
}
/// Drops the quiet mark of `resp`, once the pointer has left it.
fn forget_quiet(ctx: &Context, resp: &Response) {
if ctx.data(|d| d.get_temp::<Id>(quiet_id())) == Some(resp.id) {
ctx.data_mut(|d| d.remove::<Id>(quiet_id()));
}
}
/// The card: icon, name and shortcut; what the tool does; one line per action of its hint.
fn card(ui: &mut Ui, tool: &ToolInfo, description: &str, animated_zoom: bool) {
let t = Tokens::get(ui.ctx());
+38
View File
@@ -1127,6 +1127,44 @@ fn tool_cards_are_off_by_default_and_fall_back_to_the_tool_tip() {
assert!(!none.contains(&described("selection")) && !none.contains(&selection_tip), "tool tips off: {none:?}");
}
/// A card that is showing goes away when tool tips are turned off, while the pointer stays on its
/// button.
#[test]
fn a_shown_tool_card_goes_away_when_tool_tips_are_turned_off() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 300, "height": 300})).unwrap();
app.run("prefs.set", json!({"key": "showToolCards", "value": true})).unwrap();
let ctx = egui::Context::default();
let selection = frame(&mut app, &ctx, 0.0, vec![])[0].center();
let (time, _) = until_card(&mut app, &ctx, 1.0, selection, "selection");
app.run("prefs.set", json!({"key": "showToolTips", "value": false})).unwrap();
let after: Vec<String> = (1..5).flat_map(|i| painted_texts(&mut app, &ctx, time + f64::from(i) * 0.1, vec![])).collect();
assert!(!after.contains(&described("selection")), "{after:?}");
// A card a click put away stays away while the pointer rests on its button, and shows again on
// the next rest when the pointer left and came back while tool tips were off.
app.run("prefs.set", json!({"key": "showToolTips", "value": true})).unwrap();
let (t, _) = until_card(&mut app, &ctx, 10.0, selection, "selection");
let b = |pressed| Event::PointerButton { pos: selection, button: PointerButton::Primary, pressed, modifiers: Default::default() };
painted_texts(&mut app, &ctx, t + 0.1, vec![b(true)]);
painted_texts(&mut app, &ctx, t + 0.15, vec![b(false)]);
// Tool tips off and on again while the pointer stays: the card stays away.
app.run("prefs.set", json!({"key": "showToolTips", "value": false})).unwrap();
painted_texts(&mut app, &ctx, t + 0.2, vec![]);
app.run("prefs.set", json!({"key": "showToolTips", "value": true})).unwrap();
let stayed: Vec<String> = (3..30).flat_map(|i| painted_texts(&mut app, &ctx, t + f64::from(i) * 0.1, vec![])).collect();
assert!(!stayed.contains(&described("selection")), "{stayed:?}");
let t = t + 3.0;
app.run("prefs.set", json!({"key": "showToolTips", "value": false})).unwrap();
painted_texts(&mut app, &ctx, t + 0.2, vec![Event::PointerGone]);
// Back onto the button.
painted_texts(&mut app, &ctx, t + 0.3, vec![Event::PointerMoved(selection + vec2(2.0, 2.0))]);
painted_texts(&mut app, &ctx, t + 0.35, vec![Event::PointerMoved(selection)]);
app.run("prefs.set", json!({"key": "showToolTips", "value": true})).unwrap();
let again: Vec<String> = (4..30).flat_map(|i| painted_texts(&mut app, &ctx, t + f64::from(i) * 0.1, vec![])).collect();
assert!(again.contains(&described("selection")), "{again:?}");
}
/// A card never gets in the way: a press with it showing picks the tool and puts the card away at
/// once, it stays away until the pointer leaves, a key (one the shortcuts take first too), a
/// modifier key alone and a scroll put it away, a long press with it showing still opens a group's flyout on time, while that flyout is