mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 05:14:24 +00:00
merge-fwf: F3 pointer slop: Sense::FOLLOWS_IN_SLOP (Sense widens to u32) declares a drag part that begins at the first move inside slop; TransformBox's following parts declare it; the suite's pointer-slop case expects one gesture ending in a Commit within slop for it, reading the part's sense by owner
This commit is contained in:
@@ -5,7 +5,7 @@ use bitflags::bitflags;
|
||||
bitflags! {
|
||||
/// What a root or a part senses. The egui adapter maps the root's sense to egui's.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
pub struct Sense: u16 {
|
||||
pub struct Sense: u32 {
|
||||
/// Hover only.
|
||||
const HOVER = 1;
|
||||
/// A press released within slop activates.
|
||||
@@ -45,6 +45,11 @@ bitflags! {
|
||||
/// A zoom zone: a vertical wheel over the shape zooms the view of the innermost enclosing taker of the zoom
|
||||
/// share (a ruler over its time area). The shape takes no wheel share itself.
|
||||
const WHEEL_ZOOMS_VIEW = 32768;
|
||||
/// The gesture begins at the first move after the press, inside slop, and the value follows the pointer from
|
||||
/// there, so it does not jump when the press passes slop. A press released with no move is a click. Declared
|
||||
/// with `DRAG` by a part whose click does nothing a drag could be mistaken for (a transform box's handles).
|
||||
/// The component begins the gesture from `PressPhase::Held`.
|
||||
const FOLLOWS_IN_SLOP = 65536;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -791,7 +791,7 @@ impl Component for TransformBox<'_> {
|
||||
)
|
||||
}
|
||||
};
|
||||
cx.part(BOX.at(part.index()), shape).sense(sense).priority(priority).focus_shape(focus).focusable();
|
||||
cx.part(BOX.at(part.index()), shape).sense(sense | Sense::FOLLOWS_IN_SLOP).priority(priority).focus_shape(focus).focusable();
|
||||
any = true;
|
||||
}
|
||||
if self.line.is_some() {
|
||||
@@ -803,14 +803,14 @@ impl Component for TransformBox<'_> {
|
||||
for k in (0..4u8).filter(|&k| self.rules.allows(BoxPart::Edge(k))) {
|
||||
let side = usize::from(k);
|
||||
cx.part(EDGE.at(u64::from(k)), HitShape::segment(quad[side], quad[(side + 1) % 4]))
|
||||
.sense(Sense::DRAG)
|
||||
.sense(Sense::DRAG | Sense::FOLLOWS_IN_SLOP)
|
||||
.priority(HitPriority::new(HitLevel::Handle, EDGE_SUB))
|
||||
.pointer_only(EDGE_BY_KEY);
|
||||
}
|
||||
if self.declares_centre() {
|
||||
let centre = quad.iter().fold(Vec2::ZERO, |sum, corner| sum + corner.to_vec2()) / 4.0;
|
||||
cx.part(CENTRE.at(0), HitShape::circle(centre.to_pos2(), style.hit))
|
||||
.sense(Sense::DRAG | Sense::CLICK)
|
||||
.sense(Sense::DRAG | Sense::CLICK | Sense::FOLLOWS_IN_SLOP)
|
||||
.priority(HitPriority::new(HitLevel::Handle, HANDLE_SUB))
|
||||
.pointer_only(MOVE_BY_KEY);
|
||||
}
|
||||
@@ -819,7 +819,7 @@ impl Component for TransformBox<'_> {
|
||||
for side in 0..4usize {
|
||||
let next = (side + 1) % 4;
|
||||
cx.part(MOVE_RING.at(side as u64), HitShape::Polygon(vec![quad[side], quad[next], outer[next], outer[side]]))
|
||||
.sense(Sense::DRAG | Sense::CLICK)
|
||||
.sense(Sense::DRAG | Sense::CLICK | Sense::FOLLOWS_IN_SLOP)
|
||||
.priority(HitPriority::new(HitLevel::Body, RING_SUB))
|
||||
.pointer_only(MOVE_BY_KEY);
|
||||
}
|
||||
|
||||
@@ -413,6 +413,20 @@ pub(crate) fn part_bounds(ctx: &Context, owner: Id, part: craft_behavior::PartRe
|
||||
owned_part_bounds(ctx, |shape_owner| shape_owner == owner, part)
|
||||
}
|
||||
|
||||
/// Whether the part `part` of `owner` (the arena root or a member) senses all of `sense` in last pass's shape record.
|
||||
#[cfg(feature = "testing")]
|
||||
pub(crate) fn part_senses(ctx: &Context, owner: Id, part: craft_behavior::PartRef, sense: craft_behavior::Sense) -> bool {
|
||||
let viewport = pass::current_viewport(ctx);
|
||||
PerViewport::<Shapes>::with(ctx, viewport, |record| {
|
||||
record
|
||||
.last
|
||||
.values()
|
||||
.flat_map(|roots| roots.values())
|
||||
.flat_map(|root| root.shapes.iter())
|
||||
.any(|shape| shape.owner == owner && shape.part == Some(part) && shape.sense.contains(sense))
|
||||
})
|
||||
}
|
||||
|
||||
/// [`part_bounds`] of the owner whose AccessKit node is `node`, for a test that holds the node it found, not the id.
|
||||
#[cfg(feature = "testing")]
|
||||
pub(crate) fn node_part_bounds(ctx: &Context, node: crate::runtime::egui::access::NodeId, part: craft_behavior::PartRef) -> Option<egui::Rect> {
|
||||
|
||||
@@ -27,7 +27,8 @@ fn gesture(fixture: &mut Fixture, target: &Target, by: f32) {
|
||||
}
|
||||
|
||||
/// A release within slop of a press on a clicking component is one click. A press that moves past slop starts one
|
||||
/// drag on a component that drags and is no click on one that does not. The slop is the runtime's: it installs the
|
||||
/// drag on a component that drags and is no click on one that does not. A drag part that senses `SETS_ON_PRESS` or
|
||||
/// `FOLLOWS_IN_SLOP` begins one gesture within slop too, ended by a Commit. The slop is the runtime's: it installs the
|
||||
/// theme's `size.hit.slop` as egui's click distance.
|
||||
fn slop_separates_click_from_drag(subject: &Subject) -> Result<(), String> {
|
||||
let probe = subject.probe;
|
||||
@@ -50,11 +51,11 @@ fn slop_separates_click_from_drag(subject: &Subject) -> Result<(), String> {
|
||||
}
|
||||
}
|
||||
Plan::Drag(Grip { part, .. }) if probe.carries_value() => {
|
||||
// A part whose press sets the value begins its gesture at the press, within slop or not.
|
||||
let on_press = fixture
|
||||
.root_id()
|
||||
.is_some_and(|id| crate::runtime::pointer::sensing_parts(fixture.ctx(), id, Sense::SETS_ON_PRESS).contains(&part));
|
||||
for (by, begins) in [(0.5 * slop, usize::from(on_press)), (2.0 * slop, 1)] {
|
||||
// A part whose press sets the value begins its gesture at the press, and one that follows within slop at
|
||||
// the first move: either begins within slop.
|
||||
let senses = |sense: Sense| fixture.root_id().is_some_and(|id| crate::runtime::pointer::part_senses(fixture.ctx(), id, part, sense));
|
||||
let within = senses(Sense::SETS_ON_PRESS) || senses(Sense::FOLLOWS_IN_SLOP);
|
||||
for (by, begins) in [(0.5 * slop, usize::from(within)), (2.0 * slop, 1)] {
|
||||
let mut fixture = input_fixture(story);
|
||||
let Some(grip) = fixture.root_id().and_then(|id| fixture.part(id, part)) else { continue };
|
||||
fixture.take_outputs();
|
||||
@@ -67,8 +68,8 @@ fn slop_separates_click_from_drag(subject: &Subject) -> Result<(), String> {
|
||||
story.name
|
||||
));
|
||||
}
|
||||
if on_press && by < slop && kinds.last() != Some(&EditKind::Commit) {
|
||||
return Err(format!("{}: a press within slop that sets the value ended {kinds:?}, not with a Commit", story.name));
|
||||
if within && by < slop && kinds.last() != Some(&EditKind::Commit) {
|
||||
return Err(format!("{}: a press within slop that begins a gesture ended {kinds:?}, not with a Commit", story.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ Read-only text the user can select and copy is a selection part: `parts` declare
|
||||
|
||||
### Values
|
||||
|
||||
A value component's `Output` is `EditResponse<T>`. It binds with `Bind<T>` and reports through `cx.propose`, `cx.commit` and `cx.adopt`; each gesture ends in one `EditEvent::Commit`. A part whose press sets the value under the pointer (a colour field, a point on a well) senses `Sense::SETS_ON_PRESS` and runs its gesture with `cx.follow_press`. Components with `Input::Editor` own their caret through `ImeSurface`.
|
||||
A value component's `Output` is `EditResponse<T>`. It binds with `Bind<T>` and reports through `cx.propose`, `cx.commit` and `cx.adopt`; each gesture ends in one `EditEvent::Commit`. A part whose press sets the value under the pointer (a colour field, a point on a well) senses `Sense::SETS_ON_PRESS` and runs its gesture with `cx.follow_press`. A drag part that begins at the first move inside slop, so the value follows the pointer with no jump (a transform box's handles), senses `Sense::FOLLOWS_IN_SLOP` and begins its gesture from `PressPhase::Held`. Components with `Input::Editor` own their caret through `ImeSurface`.
|
||||
|
||||
## Looks
|
||||
|
||||
|
||||
Reference in New Issue
Block a user