fwstub-1: a canvas control's label is never its tooltip (its rect is the canvas: PageRulers' MarginHandles showed "Rulers margins" wherever the pointer rested on the page); each margin edge part carries a tooltip naming its edge, as the old app's Left Margin (divider::declare returns the part); trial

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Martin BallandClaude Opus 5.5 committed 2026-11-19 20:28:26 +00:00
1 parent 47ca129065
commit 5404f0eb8b
6 files changed
+52 -11

No files matched your search

+5 -2
View File
@@ -449,13 +449,16 @@ impl Component for MarginHandles<'_> {
Some(self.edges.reborrow())
}
/// The edges: drag parts on the strips at edge priority, each its own Tab stop that the arrow keys move.
/// The edges: drag parts on the strips at edge priority, each its own Tab stop that the arrow keys move, and each
/// with a tooltip that names its edge (Word's "Left Margin" over the edge). The handles' rect is the whole canvas,
/// so only an edge shows a tooltip: as a canvas control the handles show no label of their own over the page.
fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) {
let Some(edges) = cx.value().copied() else { return };
let rules = self.rules(edges, 0.0);
let (grab, strip) = (cx.style.grab, cx.style.strip);
let words = cx.words::<MarginHandlesWords>();
for &visible in self.edges_shown() {
divider::declare(cx, rect, EDGE, visible.index(), &self.divider(&rules, visible, rect, (grab, strip)));
divider::declare(cx, rect, EDGE, visible.index(), &self.divider(&rules, visible, rect, (grab, strip))).tooltip(visible.name(&words).clone());
}
}
+27
View File
@@ -96,6 +96,33 @@ fn a_margin_drag_is_clamped_by_the_opposite_edge_and_a_mirrored_even_page_swaps_
assert!(after.margins.right > 90.0, "it moves the stored right margin: {}", after.margins.right);
}
/// The texts that show once the pointer rests at `at` for the tooltip delay.
fn texts_added_by_rest(fixture: &mut Fixture, at: egui::Pos2) -> Vec<String> {
let before: Vec<String> = fixture.texts().iter().map(|run| run.text.clone()).collect();
fixture.frame(vec![craft_ui::testing::pointer::moved(at)]);
fixture.advance(craft_ui::contract::tooltip::DELAY);
fixture.settle();
fixture.texts().iter().map(|run| run.text.clone()).filter(|text| !before.contains(text)).collect()
}
/// The margin handles' rect is the whole canvas, but only an edge shows a tooltip, naming that edge (Word's "Left
/// Margin"); the pointer resting on the page shows none, not the handles' own label.
#[trial]
fn only_a_margin_edge_shows_a_tooltip_and_it_names_the_edge() {
let start = PageEdges::new(Margins::uniform(72.0));
let left_name = MarginHandlesWords::default().left;
let (mut fixture, _) = margin_rig(start, false);
let left = fixture.by_label(left_name.as_str()).expect("the left margin edge").rect;
// A point on the page, inside the stage (the page runs past its bottom).
let page = demo_placed(1, pos2(PAGE_AT.0, PAGE_AT.1)).remove(0).rect;
let on_page = pos2(page.center().x, fixture.shown().center().y);
assert!(page.contains(on_page), "the point is on the page");
let added = texts_added_by_rest(&mut fixture, on_page);
assert!(added.is_empty(), "the pointer on the page shows no tooltip: {added:?}");
let on_edge = texts_added_by_rest(&mut fixture, left.center());
assert_eq!(on_edge, [left_name.as_str()], "the pointer on the left edge shows its name");
}
/// A row grip drag is one gesture; Alt reports free; Escape cancels; the arrow nudges the focused grip.
#[trial]
fn a_row_grip_drag_reports_one_gesture_with_alt_free_and_the_arrow_nudges() {
+2 -1
View File
@@ -358,7 +358,8 @@ pub trait Component: Meta + Sized {
}
/// Whether the component paints its label as visible text. `false` for a face that shows only an icon or a
/// glyph: with no tooltip set, its label is then its tooltip, since the label is the only visible name the
/// pointer can reach. A component whose answer varies per instance overrides `shows_label`.
/// pointer can reach. A component whose answer varies per instance overrides `shows_label`. A canvas control's
/// label is never its tooltip, whatever this says: its rect is the canvas, and its parts name themselves.
const SHOWS_LABEL: bool = true;
/// Whether the control draws only its mark and its text is the label step's, placed after it: a check box, a
/// radio button or a switch. `Show::show` then runs the label step for an instance that carries a label and sits
+2 -1
View File
@@ -1172,7 +1172,8 @@ fn run_in_host(p: &mut Pass<'_, '_, '_>, ui: &mut Ui, host_at: Option<ShowAt>, h
},
);
let shows_label = e.shows_label();
tooltip::run(e.core_ref(), tooltip::TipIn { ui: &*ui, env, rich: p.tip.take(), parts: &parts.decls, shows_label, message });
let tip_in = tooltip::TipIn { ui: &*ui, env, rich: p.tip.take(), parts: &parts.decls, shows_label, canvas_control: facts.canvas_control, message };
tooltip::run(e.core_ref(), tip_in);
// Activations accumulate across the passes of a viewport mount; step 17 fires the bound command once, with the
// injected source when there is one.
let natural = e.activated() && resolved.enabled;
+11 -3
View File
@@ -7,7 +7,8 @@
//! A component with no tooltip shows its own label as the tooltip when its type declares `Component::SHOWS_LABEL`
//! false (or an instance does, through `Component::shows_label`): no text paints that name, inside a field or not. A
//! component with no label of its own is named by its field label, which is on screen, and shows none.
//! A component that paints its label shows it whole as the tooltip when the paint cut it.
//! A component that paints its label shows it whole as the tooltip when the paint cut it. A canvas control shows no
//! label as its tooltip: its rect is the canvas, and its parts carry their own tooltips.
use super::cx::{Decls, PartExtras};
use super::overlay::{self, Anchor, Layer, Overlay, Place};
@@ -57,6 +58,8 @@ pub(crate) struct TipIn<'a> {
pub parts: &'a Decls,
/// The instance's `shows_label` fact.
pub shows_label: bool,
/// The type is a canvas control (`Meta::CANVAS_CONTROL`): its label is never its tooltip.
pub canvas_control: bool,
/// The validity message no enclosing container shows as its status line (step 16's report).
pub message: Option<String>,
}
@@ -75,13 +78,18 @@ fn spec_text(env: &crate::runtime::env::EnvView<'_>, spec: &TooltipSpec, enabled
/// chord; else the full label when the paint cut it, or its own label when the component declares it paints no
/// label (`shows_label`), its face dropped the label (`PaintRecord::label_dropped`) or its command has a hint. A
/// bound command's hint follows on a line of its own.
fn text_of(core: &super::CxCore<'_>, shows_label: bool, message: Option<String>) -> Option<String> {
///
/// A canvas control (`canvas_control`) never shows its label: its rect is the canvas it is shown over, not a face of
/// its own, so the label would show wherever the pointer rests on the page ("Rulers margins" over a whole page). Its
/// parts name themselves with their own tooltips (a margin edge's "Left Margin").
fn text_of(core: &super::CxCore<'_>, shows_label: bool, canvas_control: bool, message: Option<String>) -> Option<String> {
if message.is_some() {
return message;
}
let hint = core.command.as_deref().and_then(|command| command.hint.as_deref()).filter(|hint| !hint.is_empty());
let base = match core.resolved.tooltip.map(|tooltip| tooltip.spec()) {
Some(spec) => spec_text(&core.env, spec, core.resolved.enabled),
None if canvas_control => return None,
None => {
let paint = core.paint.borrow();
let unpainted = !shows_label || paint.label_dropped || hint.is_some();
@@ -163,7 +171,7 @@ pub(crate) fn run(core: &super::CxCore<'_>, input: TipIn<'_>) {
part.hovered || keyboard,
Some(part.part),
),
None => (text_of(core, input.shows_label, input.message), own_spec, core.rect, core.response.hovered() || keyboard, None),
None => (text_of(core, input.shows_label, input.canvas_control, input.message), own_spec, core.rect, core.response.hovered() || keyboard, None),
};
let call = TipCall {
ctx: &core.ctx,
+5 -4
View File
@@ -4,7 +4,7 @@
//! the mirroring for right-to-left. A component that draws its own dividers (a column bar, a margin handle) calls
//! [`declare`] in its parts, `pointer` and [`keys`] in its update, and [`describe`] in its access, and declares `KeyUse::SPLITTER` for the arrow keys.
use crate::contract::{Access, Component, Cx, Focus as _, Name, Numeric, PartsCx, Pointer as _, Role};
use crate::contract::{Access, Component, Cx, Focus as _, Name, Numeric, PartBuilder, PartsCx, Pointer as _, Role};
use craft_behavior::dock::DockEdge;
use craft_behavior::nav::{StepResult, ValueAxes, ValueSteps, step_value};
use craft_behavior::{Axis, CursorIcon, Flow, HitLevel, HitPriority, NavMove, PartKey, PressPhase, Sense};
@@ -93,15 +93,16 @@ fn along_y(mv: NavMove) -> NavMove {
}
/// Declares the part `key.at(index)` for `divider`: an edge part above the panes that takes drags and is its own Tab
/// stop. `rect` is the container's rect, which the bar is mirrored across for right-to-left.
pub fn declare<C: Component>(cx: &mut PartsCx<'_, C>, rect: Rect, key: PartKey, index: u64, divider: &Divider) {
/// stop. `rect` is the container's rect, which the bar is mirrored across for right-to-left. The part is returned for
/// what a caller adds (a tooltip that names the edge).
pub fn declare<'a, C: Component>(cx: &'a mut PartsCx<'_, C>, rect: Rect, key: PartKey, index: u64, divider: &Divider) -> PartBuilder<'a> {
let bar = Flow::new(rect, cx.flow.is_rtl()).to_physical(divider.bar);
cx.part(key.at(index), bar)
.sense(Sense::DRAG | Sense::TAKE_FOCUS)
.priority(HitPriority::new(HitLevel::Edge, 0))
.cursor(divider.cursor())
.focusable()
.over();
.over()
}
/// What the pointer did to the divider `key.at(index)` this pass.