Interactivity

Struct Interactivity 

Source
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

Source

pub fn new() -> Interactivity

Create an Interactivity, capturing the caller location in debug mode.

Source

pub fn source_location(&self) -> Option<&'static Location<'static>>

Gets the source location of construction. Returns None when not in debug mode.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn on_drag<T, W>( &mut self, value: T, constructor: impl Fn(&T, Point<Pixels>, &mut Window, &mut App) -> Entity<W> + 'static, )
where Self: Sized, T: 'static, W: 'static + Render,

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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

Source

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

Source

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

Source

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.

Source

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

Source

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

Source§

fn default() -> Interactivity

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more