pub struct GestureState(/* private fields */);Expand description
Retain one handle per logical control. Clones share input/motion state. Mouse release outside the hitbox, lost button, Escape, blur and deactivation clear ownership. Pinch and supported native touch gestures are opt-in; raw multi-touch availability depends on the backend/platform.
Implementations§
Source§impl GestureState
impl GestureState
Sourcepub fn with_drag(self, drag: Drag) -> Self
pub fn with_drag(self, drag: Drag) -> Self
Adds bounded native pointer/arrow-key dragging. Configure once in the view.
Sourcepub fn touch_drag(self, enabled: bool) -> Self
pub fn touch_drag(self, enabled: bool) -> Self
Enables stock Kit touch-drag ownership. Claiming a touch prevents the containing scroll view from also handling that gesture. Platform delivery remains native; this does not synthesize touch input on desktop macOS.
Sourcepub fn constraints(self, container: MotionAnchor) -> Self
pub fn constraints(self, container: MotionAnchor) -> Self
Measures drag bounds against a retained native container anchor. Resize changes retarget from the current presentation rather than resetting it.
Sourcepub fn on_drag(
self,
callback: impl Fn(DragEvent, &mut Window, &mut App) + 'static,
) -> Self
pub fn on_drag( self, callback: impl Fn(DragEvent, &mut Window, &mut App) + 'static, ) -> Self
Reports structured pointer start/move/end/cancel events outside state borrows.
Also enables a host-controlled pan surface without with_drag.
Sourcepub fn on_pinch(
self,
callback: impl Fn(PinchGesture, &mut Window, &mut App) + 'static,
) -> Self
pub fn on_pinch( self, callback: impl Fn(PinchGesture, &mut Window, &mut App) + 'static, ) -> Self
Reports native pinch gestures without assuming ordinary elements can scale.
Sourcepub fn start_drag(
&self,
pointer: [f64; 2],
window: &mut Window,
cx: &mut App,
) -> bool
pub fn start_drag( &self, pointer: [f64; 2], window: &mut Window, cx: &mut App, ) -> bool
Starts from a separate handle or scrubber. Available after the target’s first layout; focus, cancellation and outside release remain target-owned.
Sourcepub fn view_root(self, root: MotionAnchor) -> Self
pub fn view_root(self, root: MotionAnchor) -> Self
Uses another measured viewport for in-view checks, intersected with normal ancestor clipping. Missing measurements preserve the previous visibility.
Sourcepub fn view_margins(self, margins: [f64; 4]) -> Self
pub fn view_margins(self, margins: [f64; 4]) -> Self
Insets top/right/bottom/left visibility edges; negative values expand them.
Sourcepub fn in_view(self, amount: f64, once: bool) -> Self
pub fn in_view(self, amount: f64, once: bool) -> Self
Enables automatically measured clipped viewport visibility. Configure once.
Sourcepub fn interaction(&self) -> Interaction
pub fn interaction(&self) -> Interaction
Current resolved interaction flags, supplied automatically by the element.
Sourcepub fn focus_handle(&self) -> Option<FocusHandle>
pub fn focus_handle(&self) -> Option<FocusHandle>
The stable focus handle, available after the first layout.
Sourcepub fn cancel(&self, cx: &mut App)
pub fn cancel(&self, cx: &mut App)
Cancels pointer/key state and bounded dragging, notifying the owning view.
Sourcepub fn bind<E: IntoElement + StatefulInteractiveElement + Styled + 'static>(
&self,
id: impl Into<ElementId>,
child: E,
motion: Motion,
targets: GestureTargets,
) -> GestureElement<E>
pub fn bind<E: IntoElement + StatefulInteractiveElement + Styled + 'static>( &self, id: impl Into<ElementId>, child: E, motion: Motion, targets: GestureTargets, ) -> GestureElement<E>
Wraps a styled native control and automatically binds hover/press/focus,
viewport and optional drag. Supply role, label and click behavior on the
child. The adapter supplies a stable tab-stop focus handle. Configure
layout styles before binding; x/y are owned by this adapter, not a second
LayoutGroup on the same control. Native activation remains Kit’s behavior.
use gpui_kit::{div, prelude::*, Role};
use gpui_motion_kit::{GestureState, core::{GestureTargets, Motion, Target}};
let state = GestureState::default(); // persistent view field
let control = state.bind("motion-button", div().id("button").role(Role::Button).child("Press"),
Motion::new(Target::default()), GestureTargets::default().while_press(Target::default().opacity(0.5)));Trait Implementations§
Source§impl Clone for GestureState
impl Clone for GestureState
Auto Trait Implementations§
impl !RefUnwindSafe for GestureState
impl !Send for GestureState
impl !Sync for GestureState
impl !UnwindSafe for GestureState
impl Freeze for GestureState
impl Unpin for GestureState
impl UnsafeUnpin for GestureState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().