mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 18:04:48 +00:00
Merge branch 'red/f3' into fw/mac1
This commit is contained in:
@@ -651,6 +651,17 @@ impl ContentAwareFillWorkspace {
|
||||
self.apply_reset(FillReset::FillArea);
|
||||
}
|
||||
|
||||
{
|
||||
let test = std::thread::current().name().unwrap_or("?").rsplit("::").next().unwrap_or("?").to_owned();
|
||||
if test.starts_with("an_erased_sampling") || test.starts_with("brush_strokes_change") {
|
||||
eprintln!(
|
||||
"DIAG {test}: fill body max_rect {:?} available {:?} measuring {}",
|
||||
ui.max_rect(),
|
||||
ui.available_size(),
|
||||
craft_ui::runtime::measure::active(ui.ctx())
|
||||
);
|
||||
}
|
||||
}
|
||||
Row::new().fill().show(ui, |ui, _| {
|
||||
let rail = ToolRail::new(words.tools.clone(), slots, &self.tool, &self.last_used).show_rail(ui, |_, _| {});
|
||||
if let Some(next) = rail.last_used {
|
||||
|
||||
@@ -401,10 +401,12 @@ impl CanvasTool for SelectToolPass<'_, LassoTool> {
|
||||
outline_access(self.tool.draft.points(), cx)
|
||||
}
|
||||
|
||||
/// A selection drag takes every move from the press, so a drag of a pixel or two moves the selection;
|
||||
/// [`MoveGesture::left_press`](craft_behavior::geometry::MoveGesture::left_press) alone decides its click.
|
||||
/// A selection drag and an outline with the button down take every move from the press: a drag of a pixel or two
|
||||
/// moves the selection, and the outline follows the pointer from where it went down, so a lasso drawn inside the
|
||||
/// click distance still selects. [`MoveGesture::left_press`](craft_behavior::geometry::MoveGesture::left_press)
|
||||
/// decides a selection drag's click, and the draft an outline's (fewer than 3 points, [`OutlineDraft::close`]).
|
||||
fn takes_every_move(&self) -> bool {
|
||||
self.tool.inside.is_some()
|
||||
self.tool.inside.is_some() || self.tool.draft.is_down()
|
||||
}
|
||||
|
||||
fn command_form(&self) -> ToolPath {
|
||||
|
||||
@@ -9,7 +9,7 @@ use egui::{CornerRadius, Pos2, Rect as ScreenRect, Vec2};
|
||||
use kurbo::Point;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::lasso::{DraftKey, draft_command, outline_access, reach};
|
||||
use super::lasso::{DraftKey, draft_command, outline_access};
|
||||
use super::{Place, Report, SelectEvent, SelectPhase, SelectToolPass, SelectionProbe, SelectionShape};
|
||||
|
||||
/// Where the magnetic lasso cursor's icon touches the document: the icon's own origin.
|
||||
@@ -521,7 +521,7 @@ impl<T: EdgeTracer> CanvasTool for SelectToolPass<'_, MagneticLassoTool<T>> {
|
||||
});
|
||||
return ToolAction::Claimed;
|
||||
};
|
||||
if pointer.clicks >= 2 || o.near_start(p, close_radius(cx, &place)) {
|
||||
if pointer.clicks >= 2 || o.near_start(p, close_radius(&place)) {
|
||||
tool.close(pointer.mods.alt);
|
||||
return ToolAction::Claimed;
|
||||
}
|
||||
@@ -635,7 +635,7 @@ impl<T: EdgeTracer> CanvasTool for SelectToolPass<'_, MagneticLassoTool<T>> {
|
||||
draw.stroke(&square, StrokeWidth::Thin, style.color(overlay.handle_stroke));
|
||||
}
|
||||
if let Some(pointer) = cx.pointer
|
||||
&& o.near_start(place.doc(pointer.pos), close_radius(cx, &place))
|
||||
&& o.near_start(place.doc(pointer.pos), close_radius(&place))
|
||||
{
|
||||
// The closing cursor: a small circle beside the pointer.
|
||||
let ring = PaintShape::Circle(pointer.pos + side, tokens.shape.radius.sm);
|
||||
@@ -656,7 +656,11 @@ impl<T: EdgeTracer> CanvasTool for SelectToolPass<'_, MagneticLassoTool<T>> {
|
||||
}
|
||||
}
|
||||
|
||||
/// How near the first point a press closes the outline, in document units.
|
||||
fn close_radius(cx: &ToolContext<'_>, place: &Place) -> f64 {
|
||||
reach(cx).close / place.zoom().max(0.01)
|
||||
/// How near the first point a press closes the outline, in screen points. Wider than the slop: the first point snaps
|
||||
/// to the edge, a few points from the press that placed it, and a press back where the outline began closes it.
|
||||
const CLOSE_REACH: f64 = 8.0;
|
||||
|
||||
/// [`CLOSE_REACH`] in document units.
|
||||
fn close_radius(place: &Place) -> f64 {
|
||||
CLOSE_REACH / place.zoom().max(0.01)
|
||||
}
|
||||
|
||||
@@ -614,6 +614,22 @@ fn a_lasso_click_deselects_only_in_new_mode() {
|
||||
);
|
||||
}
|
||||
|
||||
// A freehand outline drawn inside the click distance still closes into a selection: the lasso follows the pointer from
|
||||
// the press, and only an outline of fewer than three points is a click.
|
||||
#[trial]
|
||||
fn a_lasso_drawn_inside_the_click_distance_selects() {
|
||||
let mut rig = rig("Lasso", LassoTool::new(), Fake::empty());
|
||||
down(&mut rig, (100.0, 100.0), NONE);
|
||||
for point in [(101.0, 100.0), (100.0, 100.75)] {
|
||||
drag_to(&mut rig, point, NONE);
|
||||
}
|
||||
up(&mut rig, (100.0, 100.75), NONE);
|
||||
assert!(
|
||||
matches!(rig.tool_mut().events().as_slice(), [SelectEvent::Commit { operation: SelectionOperation::New, .. }]),
|
||||
"a lasso a pixel across selects"
|
||||
);
|
||||
}
|
||||
|
||||
// The outline keeps the operation its first press latched: Alt at the press over a selection subtracts, and letting go
|
||||
// of Alt during the drag changes neither the operation the tool reports nor the commit's. No outline, no operation.
|
||||
#[trial]
|
||||
@@ -891,6 +907,20 @@ fn magnetic_closes_by_start_click_double_click_or_enter_and_retracts_to_the_firs
|
||||
assert!(rig.tool_mut().events().is_empty(), "retracting commits nothing");
|
||||
}
|
||||
|
||||
// The first point snaps to the edge a few points from the press that placed it, farther than the slop: a click back
|
||||
// where the outline began closes it, as a click on the start itself does.
|
||||
#[trial]
|
||||
fn a_click_where_the_magnetic_outline_began_closes_it() {
|
||||
let (mut rig, _) = magnetic();
|
||||
let began = CENTRE + circle_offset(0.0) * ((RADIUS + 5.0) / RADIUS);
|
||||
click(&mut rig, pt(began), NONE);
|
||||
glide_along(&mut rig, 0.0, std::f64::consts::TAU);
|
||||
rig.fixture().advance(1.0);
|
||||
click(&mut rig, pt(began), NONE);
|
||||
let points = committed_polygon(&rig.tool_mut().events());
|
||||
assert!(points.len() >= 3 && points.iter().all(|&p| on_circle(p)), "a click where the outline began closes: {points:?}");
|
||||
}
|
||||
|
||||
// `[` and `]` change the width by 1 within 1..=256 while an outline is open.
|
||||
|
||||
// With `pressure_width` on, a pen sample at pressure 0.5 halves the searched width (minus one); a mouse sample never
|
||||
|
||||
@@ -534,8 +534,10 @@ impl Component for RasterDisplay<'_> {
|
||||
[areas.next(), areas.next()]
|
||||
}
|
||||
};
|
||||
// A light cell sits at the picture's top-left corner on screen, wherever the view puts the picture.
|
||||
let origin = corners.map_or(shown.view.rect.min, |corners| corners[0]);
|
||||
for area in areas.into_iter().flatten() {
|
||||
painter.painter.add(checker.shape(painter.painter.ctx(), &ui.env.tokens, CheckerArea::Quad(area), shown.view.rect.min));
|
||||
painter.painter.add(checker.shape(painter.painter.ctx(), &ui.env.tokens, CheckerArea::Quad(area), origin));
|
||||
}
|
||||
}
|
||||
match (&mut self.picture, &shown.textures, &self.mapping) {
|
||||
|
||||
@@ -129,6 +129,24 @@ fn the_checkerboard_paints_the_same_shapes_at_any_area() {
|
||||
assert_eq!(small, large, "a checkerboard over the whole canvas paints as many shapes as one over a corner of it");
|
||||
}
|
||||
|
||||
// The checkerboard's light cell sits at the document's top-left corner on screen, wherever the view puts the document,
|
||||
// not at a corner of the canvas.
|
||||
#[trial]
|
||||
fn the_checkerboard_starts_with_a_light_cell_at_the_document_corner() {
|
||||
for (width, height, zoom) in [(100, 70, 1.0), (64, 64, 0.5), (80, 40, 1.5)] {
|
||||
let document = Document::new(width, height);
|
||||
let center = Point::new(f64::from(width) / 2.0, f64::from(height) / 2.0);
|
||||
let corner = CanvasView::new(Rect::from_min_size(Pos2::ZERO, CANVAS), center, zoom).to_screen(Point::ZERO);
|
||||
let mut rig = rig(document, zoom);
|
||||
let shapes = rig.fixture.frame_shapes();
|
||||
let checker = *textured(&shapes).first().expect("the checkerboard");
|
||||
let at_corner = checker.vertices.iter().find(|vertex| vertex.pos.distance(corner) < 0.5).expect("a checkerboard corner at the document's");
|
||||
let whole = |v: f32| (v - v.round()).abs() < 1e-3;
|
||||
// The texture repeats every two cells, light first: a whole texture coordinate is a light cell's top-left.
|
||||
assert!(whole(at_corner.uv.x) && whole(at_corner.uv.y), "{width} x {height} at {zoom}: a light cell starts at the document's corner: {:?}", at_corner.uv);
|
||||
}
|
||||
}
|
||||
|
||||
/// A canvas at 800 percent whose body shows, as a document canvas does, the pasteboard with the document's page and
|
||||
/// its shadow, a display of `document` with the checkerboard and the edge, and the pixel grid over it. While `painted`
|
||||
/// is set the display is a painted one: the app's paint adds a GPU paint callback, as an app with its own compositor
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::contract::InBar;
|
||||
use crate::contract::{Component, Props};
|
||||
use crate::contract::{Cx, MeasureCx, PaintUi, PartsCx, Styled as _};
|
||||
use crate::primitives::{IconSpec, TextRun, Wrap};
|
||||
use crate::runtime::access::{Access, Name};
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::runtime::words::CommonWords;
|
||||
use crate::style::{ComponentStyle, ResetMarkLook, Stateful, StyleColor, StyleCx, TextLook, TypeRole};
|
||||
@@ -92,6 +93,8 @@ pub(super) struct LabelLeaf {
|
||||
pub(super) trailing: Vec2,
|
||||
/// The name shows; false for a label that shows only its content (`SideLabel::content_only`).
|
||||
pub(super) named: bool,
|
||||
/// The words a short label stands for: its accessible name; `None` names it by the text it shows.
|
||||
pub(super) words: Option<String>,
|
||||
double_click: bool,
|
||||
dot_click: bool,
|
||||
activated: bool,
|
||||
@@ -129,6 +132,7 @@ impl LabelLeaf {
|
||||
claimed: false,
|
||||
trailing: Vec2::ZERO,
|
||||
named: true,
|
||||
words: None,
|
||||
double_click: false,
|
||||
dot_click: false,
|
||||
activated: false,
|
||||
@@ -252,6 +256,12 @@ impl Component for LabelLeaf {
|
||||
Vec2::new(width + self.slot, height)
|
||||
}
|
||||
|
||||
fn access(&self, access: &mut Access, _: &Cx<'_, Self>) {
|
||||
if let Some(words) = &self.words {
|
||||
access.name(Name::Text(words.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
/// A click on the label focuses its control (the scope's `FieldLabel::activated`), so a label takes clicks; a
|
||||
/// claimed label is its control's to sense.
|
||||
fn sense(&self) -> Sense {
|
||||
|
||||
@@ -165,6 +165,9 @@ pub(crate) fn run(ui: &mut Ui, env: &Env, input: &LabelIn<'_>, trailing: Option<
|
||||
leaf.differs = reset.as_ref().is_some_and(|fact| fact.differs);
|
||||
leaf.default = reset.as_ref().and_then(|fact| fact.default.clone());
|
||||
leaf.named = !input.side.content_only(content);
|
||||
if matches!(input.side.kind, LabelKind::Short(_)) {
|
||||
leaf.words = Some(input.text.as_str().to_owned());
|
||||
}
|
||||
leaf.colon = colon(env, input).filter(|_| leaf.named);
|
||||
leaf.after = input.side.layout == FieldLayout::After;
|
||||
leaf.claimed = input.claims;
|
||||
|
||||
@@ -451,8 +451,8 @@ pub(crate) struct Merged {
|
||||
/// One change a label scope makes to a node, decided here and written by `runtime::egui::access`.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub(crate) enum LabelPatch {
|
||||
/// The label's own node: the role `Label` and the label's text, each only where the node has none yet, and
|
||||
/// disabled when every control it labels is.
|
||||
/// The label's own node: made with the role `Label` and the label's text where no component wrote it (a hidden
|
||||
/// label), and disabled when every control it labels is.
|
||||
Label { id: Id, text: String, disabled: bool },
|
||||
/// `node` keeps its name and is described by `label`.
|
||||
DescribedBy { node: Id, label: Id },
|
||||
|
||||
@@ -163,6 +163,15 @@ fn write_numeric(node: &mut accesskit::Node, numeric: &Numeric) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Names `node` `text`, after its role is set. A `Label` also reads its words by value, as AccessKit expects of static
|
||||
/// text and egui names its own labels; a value written later (`NodeSpec::value`) replaces it.
|
||||
pub(crate) fn write_name(node: &mut accesskit::Node, text: &str) {
|
||||
node.set_label(text.to_owned());
|
||||
if node.role() == accesskit::Role::Label {
|
||||
node.set_value(text.to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
fn write_identity(node: &mut accesskit::Node, spec: &NodeSpec) {
|
||||
node.set_role(spec.role);
|
||||
if let Some(rect) = spec.rect {
|
||||
@@ -172,7 +181,7 @@ fn write_identity(node: &mut accesskit::Node, spec: &NodeSpec) {
|
||||
node.set_hidden();
|
||||
}
|
||||
if let Some(text) = &spec.label {
|
||||
node.set_label(text.clone());
|
||||
write_name(node, text);
|
||||
}
|
||||
if let Some(text) = &spec.description {
|
||||
node.set_description(text.clone());
|
||||
|
||||
@@ -9,16 +9,11 @@ pub(crate) fn write_label_patch(ctx: &Context, patch: &LabelPatch) {
|
||||
match patch {
|
||||
LabelPatch::Label { id, text, disabled } => {
|
||||
ctx.accesskit_node_builder(*id, |node| {
|
||||
// A shown label's leaf wrote its node, named, in this pass; a hidden label has no component, and its
|
||||
// node is made here, named by the same rule.
|
||||
if node.role() == accesskit::Role::Unknown {
|
||||
node.set_role(accesskit::Role::Label);
|
||||
}
|
||||
// A `Label` is named by its value, as egui names its own labels; other roles by their label.
|
||||
if node.role() == accesskit::Role::Label {
|
||||
if node.value().is_none() {
|
||||
node.set_value(text.clone());
|
||||
}
|
||||
} else if node.label().is_none() {
|
||||
node.set_label(text.clone());
|
||||
super::node::write_name(node, text);
|
||||
}
|
||||
if *disabled {
|
||||
node.set_disabled();
|
||||
|
||||
@@ -40,7 +40,7 @@ pub use intents::settle;
|
||||
pub use intents::take_submit;
|
||||
pub use intents::with_window_intents;
|
||||
pub(crate) use intents::{
|
||||
Lent, context_part, context_request, give_back, lend, request_context, route_whole_reset, scope_escape, take_cancel, take_window_cancel,
|
||||
Lent, context_part, context_request, give_back, lend, request_context, route_whole_reset, scope_escape, take_cancel, take_every_escape, take_window_cancel,
|
||||
};
|
||||
pub(crate) use nodes::{redirect_node, register_expanded, register_node};
|
||||
pub use route::focus_holds;
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::{Stage, current};
|
||||
use crate::runtime::focus::{self};
|
||||
use craft_behavior::focus::{EscapeFacts, EscapeStep, escape_step};
|
||||
use craft_behavior::{AccessRequest, CancelRule, EditCommand, EditorInput, Intent, MoveMods, NavMove, PartRef};
|
||||
use craft_keymap::{Chord, Mods};
|
||||
use craft_keymap::{Chord, Key, Mods};
|
||||
use egui::{Context, Id, Vec2};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -454,6 +454,27 @@ fn take_untaken(ctx: &Context, intent: &Intent) -> bool {
|
||||
current(ctx, |stage| take_from(stage, focused, intent))
|
||||
}
|
||||
|
||||
/// Takes every Escape of this pass that no component has taken, wherever the runtime routed it: the untaken `Cancel`
|
||||
/// of every stop and of the window, and every Escape chord held for a claim or a capture. For a dialog opened in this
|
||||
/// pass, the top layer from then on: the stop the keys were routed to need not hold focus any more, since the press
|
||||
/// that opened the dialog may have moved it.
|
||||
pub(crate) fn take_every_escape(ctx: &Context) -> bool {
|
||||
if crate::runtime::measure::active(ctx) {
|
||||
return false;
|
||||
}
|
||||
current(ctx, |stage| {
|
||||
let mut taken = false;
|
||||
for routed in stage.routed.values_mut() {
|
||||
let before = routed.items.len();
|
||||
routed.items.retain(|item| !item.intent.same_kind(&Intent::Cancel));
|
||||
taken |= routed.items.len() != before;
|
||||
}
|
||||
let before = stage.claimed.len();
|
||||
stage.claimed.retain(|(_, chord)| chord.key != Key::Escape);
|
||||
taken || stage.claimed.len() != before
|
||||
})
|
||||
}
|
||||
|
||||
/// What an untaken Escape does in a scope: `None` when no Escape arrived or a component took it. One scope
|
||||
/// takes each Escape.
|
||||
pub(crate) fn scope_escape(ctx: &Context, rule: CancelRule, press_captured: bool, scope_clearable: bool) -> Option<EscapeStep> {
|
||||
|
||||
@@ -634,10 +634,10 @@ pub fn stack_place<R>(ctx: &Context, place: usize, dialog: Id, show: impl FnOnce
|
||||
}
|
||||
|
||||
/// A dialog host opened a dialog in this pass: it is the top layer from now on, so the Escape that arrived in this
|
||||
/// pass is its, and the focused stop beneath it gets no Cancel.
|
||||
/// pass is its, and nothing beneath it gets a Cancel or a claimed Escape, wherever focus is now.
|
||||
#[doc(hidden)]
|
||||
pub fn take_keys_for_new_dialog(ctx: &Context) {
|
||||
crate::runtime::keys::take_cancel(ctx);
|
||||
crate::runtime::keys::take_every_escape(ctx);
|
||||
}
|
||||
|
||||
/// A dialog host removed `dialog`: the layers it showed for it (`stack_place`) in the running or the last pass end
|
||||
|
||||
@@ -148,7 +148,10 @@ pub(crate) fn replay(ctx: &Context, record: &Record) {
|
||||
}
|
||||
|
||||
fn with_open(ctx: &Context, f: impl FnOnce(&mut Facts)) {
|
||||
if OPEN.load(Ordering::Acquire) > 0 {
|
||||
// Records are open only around runs of a pass on its own thread. A job's thread (a finished job's wake, a progress
|
||||
// report) runs no pass of `ctx`: it has no record to note into and must not take the pass state that the pass's
|
||||
// thread holds.
|
||||
if OPEN.load(Ordering::Acquire) > 0 && frame::running(ctx).is_some() {
|
||||
pass_state::with::<Recorder, _>(ctx, |recorder| {
|
||||
if let Some(open) = recorder.open.last_mut() {
|
||||
f(&mut open.facts);
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::runtime::keys::{intents_of, take_shortcuts};
|
||||
use crate::testing::focus::{Stop, egui_focused, named_id, register_stop, widget};
|
||||
use crate::testing::input::{key_press, key_repeat};
|
||||
use crate::testing::{Frames, trial};
|
||||
use craft_behavior::Input;
|
||||
use craft_behavior::{Input, Intent};
|
||||
use craft_keymap::Overrides;
|
||||
use egui::{Id, Key, Modifiers, Ui, ViewportId};
|
||||
use std::sync::Arc;
|
||||
@@ -169,3 +169,32 @@ fn a_recorder_holds_its_presses_from_the_app() {
|
||||
frames.frame(vec![key_press(Key::K, Modifiers::COMMAND | Modifiers::SHIFT)], &mut show);
|
||||
assert!(!saw.get(), "the app reads no press the recorder holds");
|
||||
}
|
||||
|
||||
// A dialog opened in a pass takes that pass's Escape, also when the press that opened it moved focus off the stop the
|
||||
// Escape was routed to: the stop it left gets no Cancel.
|
||||
#[trial]
|
||||
fn a_dialog_opened_in_a_pass_takes_its_escape_after_focus_moved() {
|
||||
let opens = std::rc::Rc::new(std::cell::Cell::new(false));
|
||||
let cancels = std::rc::Rc::new(std::cell::Cell::new(0));
|
||||
let (open, seen) = (std::rc::Rc::clone(&opens), std::rc::Rc::clone(&cancels));
|
||||
let mut show = move |ui: &mut Ui| {
|
||||
stop(ui, "button", KeyUse::of(Input::Pointer));
|
||||
stop(ui, "canvas", KeyUse::CANVAS);
|
||||
if open.get() {
|
||||
// The press on the button that opens the dialog takes focus first.
|
||||
request(ui.ctx(), FocusTarget::Id(id("button")));
|
||||
crate::runtime::overlay::take_keys_for_new_dialog(ui.ctx());
|
||||
}
|
||||
if intents_of(ui.ctx(), Some(id("canvas")), false).untaken(&Intent::Cancel) {
|
||||
seen.set(seen.get() + 1);
|
||||
}
|
||||
};
|
||||
let mut frames = shown(false, &mut show);
|
||||
focus_on(&mut frames, &mut show, "canvas");
|
||||
press(&mut frames, &mut show, Key::Escape, Modifiers::NONE);
|
||||
assert_eq!(cancels.get(), 1, "with no dialog opening, the focused canvas gets the Escape");
|
||||
focus_on(&mut frames, &mut show, "canvas");
|
||||
opens.set(true);
|
||||
press(&mut frames, &mut show, Key::Escape, Modifiers::NONE);
|
||||
assert_eq!(cancels.get(), 1, "the dialog opened in the pass takes it");
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ pub mod memory;
|
||||
pub mod pictures;
|
||||
pub mod pointer;
|
||||
pub mod relations;
|
||||
mod replay_trials;
|
||||
pub mod sensing;
|
||||
#[cfg(all(feature = "snapshot", not(target_arch = "wasm32")))]
|
||||
pub mod snapshot;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
//! Trials of the replay records' notes.
|
||||
|
||||
use crate::runtime::egui::{fixture, repaint};
|
||||
use crate::runtime::replay;
|
||||
use crate::testing::{Frames, trial};
|
||||
|
||||
// A job's thread asks for a pass (a finished job's wake, a progress report) while a pass of the same context records a
|
||||
// region on the UI thread: the request notes nothing in that pass's records and leaves its pass state alone.
|
||||
#[trial]
|
||||
fn a_repaint_from_a_job_thread_leaves_the_running_pass_s_records_alone() {
|
||||
let mut frames = Frames::new();
|
||||
let mut joined = None;
|
||||
frames.frame(Vec::new(), |ui| {
|
||||
let ctx = ui.ctx().clone();
|
||||
replay::open(&ctx);
|
||||
let worker = ctx.clone();
|
||||
joined = Some(std::thread::spawn(move || repaint::request(&worker)).join().is_ok());
|
||||
let _record = replay::close(&ctx, fixture::layer_of(ui));
|
||||
});
|
||||
assert_eq!(joined, Some(true), "the job thread's repaint request returns");
|
||||
}
|
||||
@@ -5,5 +5,6 @@ mod face_record;
|
||||
mod face_state;
|
||||
mod nodes;
|
||||
mod scope;
|
||||
mod static_text;
|
||||
mod sub_node_keys;
|
||||
mod viewports;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
//! Static text reads its words by value, as AccessKit expects of a `Label`.
|
||||
|
||||
use craft_ui::contract::{Common, Component, Cx, PaintUi, Props as _, Role, Show as _};
|
||||
use craft_ui::primitives::TextRun;
|
||||
use craft_ui::style::StyleCx;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use craft_ui_test_kit::contract::PlainStyle;
|
||||
use egui::{Pos2, Rect, Response};
|
||||
|
||||
const AT: Rect = Rect { min: Pos2::new(10.0, 10.0), max: Pos2::new(310.0, 40.0) };
|
||||
|
||||
/// A line of static text, named by its label, as a display text is.
|
||||
#[derive(craft_ui::contract::Component)]
|
||||
struct Words {
|
||||
#[common]
|
||||
common: Common,
|
||||
}
|
||||
|
||||
impl Component for Words {
|
||||
const ROLE: Role = Role::LABEL;
|
||||
type Style = PlainStyle;
|
||||
type Output = Response;
|
||||
|
||||
fn style(_: &StyleCx<'_>, _: WordsStyleKey) -> PlainStyle {
|
||||
PlainStyle::default()
|
||||
}
|
||||
|
||||
fn paint(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
|
||||
ui.draw().text(cx.content_rect, &TextRun::new(cx.resolved.label));
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> Response {
|
||||
cx.response.clone()
|
||||
}
|
||||
}
|
||||
|
||||
// A plain text's node carries its words as its value, where assistive technology and kittest read a `Label`'s words,
|
||||
// as well as its name.
|
||||
#[trial]
|
||||
fn a_plain_text_reads_its_words_by_value() {
|
||||
let mut fixture = Fixture::new(|ui| {
|
||||
Words { common: Common::new() }.label("Esc to cancel").show_at(ui, AT);
|
||||
});
|
||||
fixture.settle();
|
||||
let tree = fixture.tree();
|
||||
let labels = tree.with_role(Role::LABEL);
|
||||
let node = labels.iter().copied().find(|key| tree.name_of(*key) == Some("Esc to cancel")).expect("the text's node");
|
||||
assert_eq!(tree.value_of(node), Some("Esc to cancel"), "the words are the node's value");
|
||||
}
|
||||
@@ -8,7 +8,7 @@ use super::words::DockWords;
|
||||
use super::{PanelDrag, PanelKey, PanelTitle};
|
||||
use crate::buttons::IconButton;
|
||||
use crate::contract::{
|
||||
Access, BodyCx, Common, Component, Container, ContainerProps, ContextMenuRequest, Cx, HeaderEdge, HeaderParts, HeaderRegion, ListDrag, MeasureCx,
|
||||
Access, Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, ContextMenuRequest, Cx, HeaderEdge, HeaderParts, HeaderRegion, ListDrag, MeasureCx,
|
||||
Name, Outcome, OverlayUi, Overlays as _, PaintUi, PartsCx, Pointer as _, PopupKind, Props as _, Role, ShowCollection as _, ShowContainer as _,
|
||||
Sizing, WordSetCx as _,
|
||||
};
|
||||
@@ -220,6 +220,8 @@ pub struct DockGroup<'a, P: Clone + Hash + Send + Sync + 'static> {
|
||||
/// Only the header shows; the body and its drop spots are left out.
|
||||
#[prop(flag)]
|
||||
minimized: bool,
|
||||
/// The open state the body step reads: closed while minimized, so no body runs.
|
||||
open: Bind<'a, bool>,
|
||||
/// The grip drags the group.
|
||||
#[prop]
|
||||
movable: bool,
|
||||
@@ -266,6 +268,7 @@ impl<'a, P: Clone + Hash + Send + Sync + 'static> DockGroup<'a, P> {
|
||||
panels,
|
||||
active,
|
||||
minimized: false,
|
||||
open: Bind::given(true),
|
||||
movable: true,
|
||||
closable: false,
|
||||
wheel_selects_tabs: false,
|
||||
@@ -409,6 +412,12 @@ impl<P: Clone + Hash + Send + Sync + 'static> Component for DockGroup<'_, P> {
|
||||
}
|
||||
|
||||
impl<P: Clone + Hash + Send + Sync + 'static> Container for DockGroup<'_, P> {
|
||||
/// Closed while minimized: the body step runs the header alone, and the body leaves no node, shape or stop.
|
||||
fn open(&mut self) -> Option<BindMut<'_, bool>> {
|
||||
self.open = Bind::given(!self.minimized);
|
||||
Some(self.open.reborrow())
|
||||
}
|
||||
|
||||
/// The drag band, then the panel menu button when it shows, at the header's end edge.
|
||||
fn header_parts(&self, cx: &MeasureCx<'_, Self>) -> HeaderParts {
|
||||
let band = grip_width(cx.tokens);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
//! A docked panel group.
|
||||
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{Show as _, ShowContainer as _};
|
||||
use craft_ui::docking::{DockGroup, PanelKey, PanelTitle};
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Pos2, Rect, Vec2};
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
// A minimized group shows its header alone: its body does not run, so it leaves no node and nothing a press could
|
||||
// reach under the groups below it. Expanded, the same body shows.
|
||||
#[trial]
|
||||
fn a_minimized_group_runs_no_body() {
|
||||
let body = |minimized: bool| {
|
||||
let runs = Rc::new(Cell::new(0));
|
||||
let counted = Rc::clone(&runs);
|
||||
let panels = vec![PanelTitle::new(PanelKey::new(1), "Color")];
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let group = DockGroup::new(1usize, &panels, panels[0].key);
|
||||
let group = if minimized { group.minimized() } else { group };
|
||||
let counted = Rc::clone(&counted);
|
||||
group.show_at(ui, Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(240.0, 200.0)), move |ui, _| {
|
||||
counted.set(counted.get() + 1);
|
||||
Button::new("Body button").show(ui);
|
||||
});
|
||||
});
|
||||
fixture.idle(4);
|
||||
let found = fixture.by_label("Body button").is_some();
|
||||
(runs.get(), found)
|
||||
};
|
||||
let (runs, found) = body(false);
|
||||
assert!(runs > 0 && found, "an expanded group shows its body: {runs} runs, node {found}");
|
||||
assert_eq!(body(true), (0, false), "a minimized group runs no body and leaves no node");
|
||||
}
|
||||
@@ -6,6 +6,7 @@ extern crate craft_ui_panels as craft_ui;
|
||||
mod access;
|
||||
pub(crate) mod body;
|
||||
mod dialogs;
|
||||
mod dock_group;
|
||||
// outer edit
|
||||
mod edit;
|
||||
// end of outer edit
|
||||
|
||||
@@ -558,9 +558,15 @@ impl Component for Notice<'_> {
|
||||
room.map_or(width, |room| width.min(room))
|
||||
}
|
||||
(NoticeLayout::Centred, None) => natural.min(cx.style.reading_width),
|
||||
(_, Some(room)) => room,
|
||||
(_, None) => natural,
|
||||
// A row notice takes the room it is given; an unbounded room (a column sized by its content) leaves it at
|
||||
// its natural width.
|
||||
(_, Some(room)) if room.is_finite() => room,
|
||||
(_, _) => natural,
|
||||
};
|
||||
if !width.is_finite() || cx.room.is_some_and(|room| !room.is_finite()) {
|
||||
let test = std::thread::current().name().unwrap_or("?").rsplit("::").next().unwrap_or("?").to_owned();
|
||||
eprintln!("DIAG {test}: notice measure room {:?} natural {natural} width {width}", cx.room);
|
||||
}
|
||||
Vec2::new(width, self.plan(cx, &texts, self.wrap_width(cx, width)).height)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user