pub struct MagnetismConfig { /* private fields */ }Expand description
Per-view magnetism configuration, installed via
SceneView::magnetism.
Holds the consumer’s policy — the accept/reject predicate and the
on_connect handler — plus presentation knobs. The scene supplies
the mechanism (snap math, broad-phase, feedback rendering, the
connection event); this config is where the consumer plugs its
policy in.
Implementations§
Source§impl MagnetismConfig
impl MagnetismConfig
Sourcepub fn new(
predicate: impl Fn(&MagnetRef, &MagnetRef) -> MagnetVerdict + 'static,
) -> Self
pub fn new( predicate: impl Fn(&MagnetRef, &MagnetRef) -> MagnetVerdict + 'static, ) -> Self
A config with the given accept/reject predicate and defaults:
14 px capture radius, markers during interaction, the built-in
feedback renderer, m to toggle keyboard connect mode, enabled.
Install an on_connect handler to actually do something on
connect.
Sourcepub fn on_connect(
self,
f: impl Fn(&MagnetConnection, &mut EventContext<'_>) + 'static,
) -> Self
pub fn on_connect( self, f: impl Fn(&MagnetConnection, &mut EventContext<'_>) + 'static, ) -> Self
The handler invoked when a connection is formed (mouse release or
keyboard confirm). Runs with a live EventContext and no scene
borrow held, so it may mutate the model (add an edge item,
reparent), call scene.add_a11y_relation, or fire an intent.
Sourcepub fn capture_px(self, px: f32) -> Self
pub fn capture_px(self, px: f32) -> Self
Capture and grab radius in screen pixels (converted to scene units by dividing by the live zoom, so snapping feels consistent at any zoom). Default 14.
Sourcepub fn markers(self, markers: MarkerVisibility) -> Self
pub fn markers(self, markers: MarkerVisibility) -> Self
When magnet markers are painted. Default
MarkerVisibility::DuringInteraction.
Sourcepub fn feedback(
self,
f: impl Fn(&mut Canvas, &PaintContext<'_>, &MagnetFeedback) + 'static,
) -> Self
pub fn feedback( self, f: impl Fn(&mut Canvas, &PaintContext<'_>, &MagnetFeedback) + 'static, ) -> Self
Replace the built-in feedback renderer with a custom one. The closure paints in scene coordinates (the canvas already has the view transform pushed).
Sourcepub fn connect_key(self, key: Key) -> Self
pub fn connect_key(self, key: Key) -> Self
The key that toggles keyboard connect mode while the SceneView is
focused. Default m.
Sourcepub fn enabled(self, on: impl Into<Prop<bool>>) -> Self
pub fn enabled(self, on: impl Into<Prop<bool>>) -> Self
Set the enabled state, statically or reactively (an app-owned signal drives enabled/disabled from e.g. a toolbar toggle).
Sourcepub fn enabled_signal(&self) -> Signal<bool>
pub fn enabled_signal(&self) -> Signal<bool>
The reactive enabled signal, for a toolbar to read or bind.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether magnetism is currently enabled.
Trait Implementations§
Source§impl Clone for MagnetismConfig
impl Clone for MagnetismConfig
Source§fn clone(&self) -> MagnetismConfig
fn clone(&self) -> MagnetismConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for MagnetismConfig
impl !Send for MagnetismConfig
impl !Sync for MagnetismConfig
impl !UnwindSafe for MagnetismConfig
impl Freeze for MagnetismConfig
impl Unpin for MagnetismConfig
impl UnsafeUnpin for MagnetismConfig
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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more