mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-23 02:51:42 +01:00
Merge branch 'red/fwstub-1' into area/ribbon-fw
This commit is contained in:
commit
feaea98c11
8 files changed
+86
-12
No files matched your search
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -212,7 +212,11 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U
|
||||
if overlay.fit == OverlayFit::Resizable {
|
||||
ui.set_min_size(overlay.size_limits.min.min(placed.room));
|
||||
}
|
||||
access::scope::outside(ctx, || body(ui));
|
||||
// The layer's content is not part of the flow of the body it was shown from (a tooltip shown at step 16 of a
|
||||
// control inside a body's content): no enclosing transcript takes its measure calls and no enclosing body
|
||||
// checks them. Without the boundary a tooltip's text was checked against the body's kept transcript, which
|
||||
// asked for a discard pass every other frame while the tooltip showed.
|
||||
access::scope::outside(ctx, || layout_memory::boundary(ctx, true, || body(ui)));
|
||||
if real {
|
||||
focus::pop_scope(ctx);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -212,3 +212,32 @@ fn a_disabled_command_with_a_hint_is_a_tab_stop_that_shows_its_reason() {
|
||||
let (reached, _) = tab_through_disabled(None);
|
||||
assert_eq!(&reached[..2], ["Before", "After"], "without a hint Tab skips the disabled button");
|
||||
}
|
||||
|
||||
/// The tooltip of a control inside a body (a canvas control over a page body, its tip kept at the screen's bottom
|
||||
/// edge): its layer is not part of the body's flow, so the body's kept transcript does not check the tip's text. Once
|
||||
/// it shows, it keeps one rect and every frame runs one pass, none a discard pass for a tip that measured another
|
||||
/// size.
|
||||
#[trial]
|
||||
fn a_tooltip_shown_from_inside_a_body_keeps_its_rect_frame_to_frame() {
|
||||
let mut fixture = Fixture::new(|ui| {
|
||||
craft_ui::layout_components::Stack::new().show(ui, |ui, _| {
|
||||
Mark { common: Common::new() }.label("Lock").show_at(ui, Rect::from_min_size(Pos2::ZERO, Vec2::new(600.0, 380.0)));
|
||||
});
|
||||
});
|
||||
fixture.room(Vec2::new(600.0, 400.0));
|
||||
fixture.settle();
|
||||
fixture.frame(vec![moved(Pos2::new(300.0, 200.0))]);
|
||||
fixture.advance(DELAY);
|
||||
fixture.settle();
|
||||
assert!(fixture.texts().iter().any(|run| run.text == "Lock"), "the tooltip shows");
|
||||
let mut frames = Vec::new();
|
||||
for _ in 0..6 {
|
||||
fixture.frame(Vec::new());
|
||||
frames.push((fixture.passes(), fixture.texts().iter().find(|run| run.text == "Lock").map(|run| run.rect)));
|
||||
}
|
||||
let first = frames[0].1;
|
||||
assert!(
|
||||
first.is_some() && frames.iter().all(|(passes, rect)| *passes == 1 && *rect == first),
|
||||
"one pass a frame and one rect: {frames:?}"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user