pub struct Interactivity {
pub element_id: Option<ElementId>,
pub active: Option<bool>,
pub hovered: Option<bool>,
pub base_style: Box<StyleRefinement>,
/* private fields */
}Expand description
The interactivity struct. Powers all of the general-purpose
interactivity in the Div element.
Fields§
§element_id: Option<ElementId>The element ID of the element. In id is required to support a stateful subset of the interactivity such as on_click.
active: Option<bool>Whether the element was clicked. This will only be present after layout.
hovered: Option<bool>Whether the element was hovered. This will only be present after paint if an hitbox was created for the interactive element.
base_style: Box<StyleRefinement>The base style of the element, before any modifications are applied by focus, active, etc.
Implementations§
Source§impl Interactivity
impl Interactivity
Sourcepub fn new() -> Interactivity
pub fn new() -> Interactivity
Create an Interactivity, capturing the caller location in debug mode.
Sourcepub fn source_location(&self) -> Option<&'static Location<'static>>
pub fn source_location(&self) -> Option<&'static Location<'static>>
Gets the source location of construction. Returns None when not in debug mode.
Sourcepub fn on_mouse_down(
&mut self,
button: MouseButton,
listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static,
)
pub fn on_mouse_down( &mut self, button: MouseButton, listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to the mouse down event for the given mouse button, during the bubble phase.
The imperative API equivalent of InteractiveElement::on_mouse_down.
See Context::listener to get access to the view state from this callback.
Sourcepub fn capture_any_mouse_down(
&mut self,
listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static,
)
pub fn capture_any_mouse_down( &mut self, listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to the mouse down event for any button, during the capture phase.
The imperative API equivalent of InteractiveElement::capture_any_mouse_down.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_any_mouse_down(
&mut self,
listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static,
)
pub fn on_any_mouse_down( &mut self, listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to the mouse down event for any button, during the bubble phase.
The imperative API equivalent to InteractiveElement::on_any_mouse_down.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_mouse_up(
&mut self,
button: MouseButton,
listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static,
)
pub fn on_mouse_up( &mut self, button: MouseButton, listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to the mouse up event for the given button, during the bubble phase.
The imperative API equivalent to InteractiveElement::on_mouse_up.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn capture_any_mouse_up(
&mut self,
listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static,
)
pub fn capture_any_mouse_up( &mut self, listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to the mouse up event for any button, during the capture phase.
The imperative API equivalent to InteractiveElement::capture_any_mouse_up.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_any_mouse_up(
&mut self,
listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static,
)
pub fn on_any_mouse_up( &mut self, listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to the mouse up event for any button, during the bubble phase.
The imperative API equivalent to Interactivity::on_any_mouse_up.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_mouse_down_out(
&mut self,
listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static,
)
pub fn on_mouse_down_out( &mut self, listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to the mouse down event, on any button, during the capture phase,
when the mouse is outside of the bounds of this element.
The imperative API equivalent to InteractiveElement::on_mouse_down_out.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_mouse_up_out(
&mut self,
button: MouseButton,
listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static,
)
pub fn on_mouse_up_out( &mut self, button: MouseButton, listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to the mouse up event, for the given button, during the capture phase,
when the mouse is outside of the bounds of this element.
The imperative API equivalent to InteractiveElement::on_mouse_up_out.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_mouse_move(
&mut self,
listener: impl Fn(&MouseMoveEvent, &mut Window, &mut App) + 'static,
)
pub fn on_mouse_move( &mut self, listener: impl Fn(&MouseMoveEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to the mouse move event, during the bubble phase.
The imperative API equivalent to InteractiveElement::on_mouse_move.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_drag_move<T>(
&mut self,
listener: impl Fn(&DragMoveEvent<T>, &mut Window, &mut App) + 'static,
)where
T: 'static,
pub fn on_drag_move<T>(
&mut self,
listener: impl Fn(&DragMoveEvent<T>, &mut Window, &mut App) + 'static,
)where
T: 'static,
Bind the given callback to the mouse drag event of the given type. Note that this
will be called for all move events, inside or outside of this element, as long as the
drag was started with this element under the mouse. Useful for implementing draggable
UIs that don’t conform to a drag and drop style interaction, like resizing.
The imperative API equivalent to InteractiveElement::on_drag_move.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_scroll_wheel(
&mut self,
listener: impl Fn(&ScrollWheelEvent, &mut Window, &mut App) + 'static,
)
pub fn on_scroll_wheel( &mut self, listener: impl Fn(&ScrollWheelEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to scroll wheel events during the bubble phase.
The imperative API equivalent to InteractiveElement::on_scroll_wheel.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn capture_action<A: Action>(
&mut self,
listener: impl Fn(&A, &mut Window, &mut App) + 'static,
)
pub fn capture_action<A: Action>( &mut self, listener: impl Fn(&A, &mut Window, &mut App) + 'static, )
Bind the given callback to an action dispatch during the capture phase.
The imperative API equivalent to InteractiveElement::capture_action.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_action<A: Action>(
&mut self,
listener: impl Fn(&A, &mut Window, &mut App) + 'static,
)
pub fn on_action<A: Action>( &mut self, listener: impl Fn(&A, &mut Window, &mut App) + 'static, )
Bind the given callback to an action dispatch during the bubble phase.
The imperative API equivalent to InteractiveElement::on_action.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_boxed_action(
&mut self,
action: &dyn Action,
listener: impl Fn(&dyn Action, &mut Window, &mut App) + 'static,
)
pub fn on_boxed_action( &mut self, action: &dyn Action, listener: impl Fn(&dyn Action, &mut Window, &mut App) + 'static, )
Bind the given callback to an action dispatch, based on a dynamic action parameter
instead of a type parameter. Useful for component libraries that want to expose
action bindings to their users.
The imperative API equivalent to InteractiveElement::on_boxed_action.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_key_down(
&mut self,
listener: impl Fn(&KeyDownEvent, &mut Window, &mut App) + 'static,
)
pub fn on_key_down( &mut self, listener: impl Fn(&KeyDownEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to key down events during the bubble phase.
The imperative API equivalent to InteractiveElement::on_key_down.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn capture_key_down(
&mut self,
listener: impl Fn(&KeyDownEvent, &mut Window, &mut App) + 'static,
)
pub fn capture_key_down( &mut self, listener: impl Fn(&KeyDownEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to key down events during the capture phase.
The imperative API equivalent to InteractiveElement::capture_key_down.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_key_up(
&mut self,
listener: impl Fn(&KeyUpEvent, &mut Window, &mut App) + 'static,
)
pub fn on_key_up( &mut self, listener: impl Fn(&KeyUpEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to key up events during the bubble phase.
The imperative API equivalent to InteractiveElement::on_key_up.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn capture_key_up(
&mut self,
listener: impl Fn(&KeyUpEvent, &mut Window, &mut App) + 'static,
)
pub fn capture_key_up( &mut self, listener: impl Fn(&KeyUpEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to key up events during the capture phase.
The imperative API equivalent to InteractiveElement::on_key_up.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_modifiers_changed(
&mut self,
listener: impl Fn(&ModifiersChangedEvent, &mut Window, &mut App) + 'static,
)
pub fn on_modifiers_changed( &mut self, listener: impl Fn(&ModifiersChangedEvent, &mut Window, &mut App) + 'static, )
Bind the given callback to modifiers changing events.
The imperative API equivalent to InteractiveElement::on_modifiers_changed.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_drop<T: 'static>(
&mut self,
listener: impl Fn(&T, &mut Window, &mut App) + 'static,
)
pub fn on_drop<T: 'static>( &mut self, listener: impl Fn(&T, &mut Window, &mut App) + 'static, )
Bind the given callback to drop events of the given type, whether or not the drag started on this element.
The imperative API equivalent to InteractiveElement::on_drop.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn can_drop(
&mut self,
predicate: impl Fn(&dyn Any, &mut Window, &mut App) -> bool + 'static,
)
pub fn can_drop( &mut self, predicate: impl Fn(&dyn Any, &mut Window, &mut App) -> bool + 'static, )
Use the given predicate to determine whether or not a drop event should be dispatched to this element.
The imperative API equivalent to InteractiveElement::can_drop.
Sourcepub fn on_click(
&mut self,
listener: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
)where
Self: Sized,
pub fn on_click(
&mut self,
listener: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
)where
Self: Sized,
Bind the given callback to click events of this element.
The imperative API equivalent to StatefulInteractiveElement::on_click.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_drag<T, W>(
&mut self,
value: T,
constructor: impl Fn(&T, Point<Pixels>, &mut Window, &mut App) -> Entity<W> + 'static,
)
pub fn on_drag<T, W>( &mut self, value: T, constructor: impl Fn(&T, Point<Pixels>, &mut Window, &mut App) -> Entity<W> + 'static, )
On drag initiation, this callback will be used to create a new view to render the dragged value for a
drag and drop operation. This API should also be used as the equivalent of ‘on drag start’ with
the Self::on_drag_move API.
The imperative API equivalent to StatefulInteractiveElement::on_drag.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn on_hover(
&mut self,
listener: impl Fn(&bool, &mut Window, &mut App) + 'static,
)where
Self: Sized,
pub fn on_hover(
&mut self,
listener: impl Fn(&bool, &mut Window, &mut App) + 'static,
)where
Self: Sized,
Bind the given callback on the hover start and end events of this element. Note that the boolean
passed to the callback is true when the hover starts and false when it ends.
The imperative API equivalent to StatefulInteractiveElement::on_hover.
See Context::listener to get access to a view’s state from this callback.
Sourcepub fn tooltip(
&mut self,
build_tooltip: impl Fn(&mut Window, &mut App) -> AnyView + 'static,
)where
Self: Sized,
pub fn tooltip(
&mut self,
build_tooltip: impl Fn(&mut Window, &mut App) -> AnyView + 'static,
)where
Self: Sized,
Use the given callback to construct a new tooltip view when the mouse hovers over this element.
The imperative API equivalent to StatefulInteractiveElement::tooltip.
Sourcepub fn hoverable_tooltip(
&mut self,
build_tooltip: impl Fn(&mut Window, &mut App) -> AnyView + 'static,
)where
Self: Sized,
pub fn hoverable_tooltip(
&mut self,
build_tooltip: impl Fn(&mut Window, &mut App) -> AnyView + 'static,
)where
Self: Sized,
Use the given callback to construct a new tooltip view when the mouse hovers over this element.
The tooltip itself is also hoverable and won’t disappear when the user moves the mouse into
the tooltip. The imperative API equivalent to StatefulInteractiveElement::hoverable_tooltip.
Sourcepub fn occlude_mouse(&mut self)
pub fn occlude_mouse(&mut self)
Block the mouse from all interactions with elements behind this element’s hitbox. Typically
block_mouse_except_scroll should be preferred.
The imperative API equivalent to InteractiveElement::occlude
Sourcepub fn window_control_area(&mut self, area: WindowControlArea)
pub fn window_control_area(&mut self, area: WindowControlArea)
Set the bounds of this element as a window control area for the platform window.
The imperative API equivalent to InteractiveElement::window_control_area
Sourcepub fn block_mouse_except_scroll(&mut self)
pub fn block_mouse_except_scroll(&mut self)
Block non-scroll mouse interactions with elements behind this element’s hitbox.
The imperative API equivalent to InteractiveElement::block_mouse_except_scroll.
See Hitbox::is_hovered for details.
Source§impl Interactivity
impl Interactivity
Sourcepub fn request_layout(
&mut self,
global_id: Option<&GlobalElementId>,
_inspector_id: Option<&InspectorElementId>,
window: &mut Window,
cx: &mut App,
f: impl FnOnce(Style, &mut Window, &mut App) -> LayoutId,
) -> LayoutId
pub fn request_layout( &mut self, global_id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, f: impl FnOnce(Style, &mut Window, &mut App) -> LayoutId, ) -> LayoutId
Layout this element according to this interactivity state’s configured styles
Sourcepub fn prepaint<R>(
&mut self,
global_id: Option<&GlobalElementId>,
_inspector_id: Option<&InspectorElementId>,
bounds: Bounds<Pixels>,
content_size: Size<Pixels>,
window: &mut Window,
cx: &mut App,
f: impl FnOnce(&Style, Point<Pixels>, Option<Hitbox>, &mut Window, &mut App) -> R,
) -> R
pub fn prepaint<R>( &mut self, global_id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, content_size: Size<Pixels>, window: &mut Window, cx: &mut App, f: impl FnOnce(&Style, Point<Pixels>, Option<Hitbox>, &mut Window, &mut App) -> R, ) -> R
Commit the bounds of this element according to this interactivity state’s configured styles.
Sourcepub fn paint(
&mut self,
global_id: Option<&GlobalElementId>,
_inspector_id: Option<&InspectorElementId>,
bounds: Bounds<Pixels>,
hitbox: Option<&Hitbox>,
window: &mut Window,
cx: &mut App,
f: impl FnOnce(&Style, &mut Window, &mut App),
)
pub fn paint( &mut self, global_id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, hitbox: Option<&Hitbox>, window: &mut Window, cx: &mut App, f: impl FnOnce(&Style, &mut Window, &mut App), )
Paint this element according to this interactivity state’s configured styles and bind the element’s mouse and keyboard events.
content_size is the size of the content of the element, which may be larger than the element’s bounds if the element is scrollable.
the final computed style will be passed to the provided function, along with the current scroll offset
Sourcepub fn compute_style(
&self,
global_id: Option<&GlobalElementId>,
hitbox: Option<&Hitbox>,
window: &mut Window,
cx: &mut App,
) -> Style
pub fn compute_style( &self, global_id: Option<&GlobalElementId>, hitbox: Option<&Hitbox>, window: &mut Window, cx: &mut App, ) -> Style
Compute the visual style for this element, based on the current bounds and the element’s state.
Trait Implementations§
Source§impl Default for Interactivity
impl Default for Interactivity
Source§fn default() -> Interactivity
fn default() -> Interactivity
Auto Trait Implementations§
impl Freeze for Interactivity
impl !RefUnwindSafe for Interactivity
impl !Send for Interactivity
impl !Sync for Interactivity
impl Unpin for Interactivity
impl !UnwindSafe for Interactivity
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
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
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().