InteractiveElement

Trait InteractiveElement 

Source
pub trait InteractiveElement: Sized {
Show 39 methods // Required method fn interactivity(&mut self) -> &mut Interactivity; // Provided methods fn group(self, group: impl Into<SharedString>) -> Self { ... } fn id(self, id: impl Into<ElementId>) -> Stateful<Self> { ... } fn track_focus(self, focus_handle: &FocusHandle) -> Self { ... } fn tab_stop(self, tab_stop: bool) -> Self { ... } fn tab_index(self, index: isize) -> Self { ... } fn tab_group(self) -> Self { ... } fn key_context<C, E>(self, key_context: C) -> Self where C: TryInto<KeyContext, Error = E>, E: Debug { ... } fn hover(self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self { ... } fn group_hover( self, group_name: impl Into<SharedString>, f: impl FnOnce(StyleRefinement) -> StyleRefinement, ) -> Self { ... } fn on_mouse_down( self, button: MouseButton, listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn debug_selector(self, _: impl FnOnce() -> String) -> Self { ... } fn capture_any_mouse_down( self, listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_any_mouse_down( self, listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_mouse_up( self, button: MouseButton, listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn capture_any_mouse_up( self, listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_mouse_down_out( self, listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_mouse_up_out( self, button: MouseButton, listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_mouse_move( self, listener: impl Fn(&MouseMoveEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_drag_move<T: 'static>( self, listener: impl Fn(&DragMoveEvent<T>, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_scroll_wheel( self, listener: impl Fn(&ScrollWheelEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn capture_action<A: Action>( self, listener: impl Fn(&A, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_action<A: Action>( self, listener: impl Fn(&A, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_boxed_action( self, action: &dyn Action, listener: impl Fn(&dyn Action, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_key_down( self, listener: impl Fn(&KeyDownEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn capture_key_down( self, listener: impl Fn(&KeyDownEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_key_up( self, listener: impl Fn(&KeyUpEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn capture_key_up( self, listener: impl Fn(&KeyUpEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_modifiers_changed( self, listener: impl Fn(&ModifiersChangedEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn drag_over<S: 'static>( self, f: impl 'static + Fn(StyleRefinement, &S, &mut Window, &mut App) -> StyleRefinement, ) -> Self { ... } fn group_drag_over<S: 'static>( self, group_name: impl Into<SharedString>, f: impl FnOnce(StyleRefinement) -> StyleRefinement, ) -> Self { ... } fn on_drop<T: 'static>( self, listener: impl Fn(&T, &mut Window, &mut App) + 'static, ) -> Self { ... } fn can_drop( self, predicate: impl Fn(&dyn Any, &mut Window, &mut App) -> bool + 'static, ) -> Self { ... } fn occlude(self) -> Self { ... } fn window_control_area(self, area: WindowControlArea) -> Self { ... } fn block_mouse_except_scroll(self) -> Self { ... } fn focus(self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self where Self: Sized { ... } fn in_focus( self, f: impl FnOnce(StyleRefinement) -> StyleRefinement, ) -> Self where Self: Sized { ... } fn focus_visible( self, f: impl FnOnce(StyleRefinement) -> StyleRefinement, ) -> Self where Self: Sized { ... }
}
Expand description

A trait for elements that want to use the standard GPUI event handlers that don’t require any state.

Required Methods§

Source

fn interactivity(&mut self) -> &mut Interactivity

Retrieve the interactivity state associated with this element

Provided Methods§

Source

fn group(self, group: impl Into<SharedString>) -> Self

Assign this element to a group of elements that can be styled together

Source

fn id(self, id: impl Into<ElementId>) -> Stateful<Self>

Assign this element an ID, so that it can be used with interactivity

Source

fn track_focus(self, focus_handle: &FocusHandle) -> Self

Track the focus state of the given focus handle on this element. If the focus handle is focused by the application, this element will apply its focused styles.

Source

fn tab_stop(self, tab_stop: bool) -> Self

Set whether this element is a tab stop.

When false, the element remains in tab-index order but cannot be reached via keyboard navigation. Useful for container elements: focus the container, then call window.focus_next() to focus the first tab stop inside it while having the container element itself be unreachable via the keyboard. Should only be used with tab_index.

Source

fn tab_index(self, index: isize) -> Self

Set index of the tab stop order, and set this node as a tab stop. This will default the element to being a tab stop. See Self::tab_stop for more information. This should only be used in conjunction with tab_group in order to not interfere with the tab index of other elements.

Source

fn tab_group(self) -> Self

Designate this div as a “tab group”. Tab groups have their own location in the tab-index order, but for children of the tab group, the tab index is reset to 0. This can be useful for swapping the order of tab stops within the group, without having to renumber all the tab stops in the whole application.

Source

fn key_context<C, E>(self, key_context: C) -> Self
where C: TryInto<KeyContext, Error = E>, E: Debug,

Set the keymap context for this element. This will be used to determine which action to dispatch from the keymap.

Source

fn hover(self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self

Apply the given style to this element when the mouse hovers over it

Source

fn group_hover( self, group_name: impl Into<SharedString>, f: impl FnOnce(StyleRefinement) -> StyleRefinement, ) -> Self

Apply the given style to this element when the mouse hovers over a group member

Source

fn on_mouse_down( self, button: MouseButton, listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to the mouse down event for the given mouse button. The fluent API equivalent to Interactivity::on_mouse_down.

See Context::listener to get access to the view state from this callback.

Source

fn debug_selector(self, _: impl FnOnce() -> String) -> Self

Set a key that can be used to look up this element’s bounds in the [crate::VisualTestContext::debug_bounds] map This is a noop in release builds

Source

fn capture_any_mouse_down( self, listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to the mouse down event for any button, during the capture phase. The fluent API equivalent to Interactivity::capture_any_mouse_down.

See Context::listener to get access to a view’s state from this callback.

Source

fn on_any_mouse_down( self, listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to the mouse down event for any button, during the capture phase. The fluent API equivalent to Interactivity::on_any_mouse_down.

See Context::listener to get access to a view’s state from this callback.

Source

fn on_mouse_up( self, button: MouseButton, listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to the mouse up event for the given button, during the bubble phase. The fluent API equivalent to Interactivity::on_mouse_up.

See Context::listener to get access to a view’s state from this callback.

Source

fn capture_any_mouse_up( self, listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to the mouse up event for any button, during the capture phase. The fluent API equivalent to Interactivity::capture_any_mouse_up.

See Context::listener to get access to a view’s state from this callback.

Source

fn on_mouse_down_out( self, listener: impl Fn(&MouseDownEvent, &mut Window, &mut App) + 'static, ) -> Self

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 fluent API equivalent to Interactivity::on_mouse_down_out.

See Context::listener to get access to a view’s state from this callback.

Source

fn on_mouse_up_out( self, button: MouseButton, listener: impl Fn(&MouseUpEvent, &mut Window, &mut App) + 'static, ) -> Self

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 fluent API equivalent to Interactivity::on_mouse_up_out.

See Context::listener to get access to a view’s state from this callback.

Source

fn on_mouse_move( self, listener: impl Fn(&MouseMoveEvent, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to the mouse move event, during the bubble phase. The fluent API equivalent to Interactivity::on_mouse_move.

See Context::listener to get access to a view’s state from this callback.

Source

fn on_drag_move<T: 'static>( self, listener: impl Fn(&DragMoveEvent<T>, &mut Window, &mut App) + 'static, ) -> Self

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 fluent API equivalent to Interactivity::on_drag_move.

See Context::listener to get access to a view’s state from this callback.

Source

fn on_scroll_wheel( self, listener: impl Fn(&ScrollWheelEvent, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to scroll wheel events during the bubble phase. The fluent API equivalent to Interactivity::on_scroll_wheel.

See Context::listener to get access to a view’s state from this callback.

Source

fn capture_action<A: Action>( self, listener: impl Fn(&A, &mut Window, &mut App) + 'static, ) -> Self

Capture the given action, before normal action dispatch can fire. The fluent API equivalent to Interactivity::capture_action.

See Context::listener to get access to a view’s state from this callback.

Source

fn on_action<A: Action>( self, listener: impl Fn(&A, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to an action dispatch during the bubble phase. The fluent API equivalent to Interactivity::on_action.

See Context::listener to get access to a view’s state from this callback.

Source

fn on_boxed_action( self, action: &dyn Action, listener: impl Fn(&dyn Action, &mut Window, &mut App) + 'static, ) -> Self

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 fluent API equivalent to Interactivity::on_boxed_action.

See Context::listener to get access to a view’s state from this callback.

Source

fn on_key_down( self, listener: impl Fn(&KeyDownEvent, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to key down events during the bubble phase. The fluent API equivalent to Interactivity::on_key_down.

See Context::listener to get access to a view’s state from this callback.

Source

fn capture_key_down( self, listener: impl Fn(&KeyDownEvent, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to key down events during the capture phase. The fluent API equivalent to Interactivity::capture_key_down.

See Context::listener to get access to a view’s state from this callback.

Source

fn on_key_up( self, listener: impl Fn(&KeyUpEvent, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to key up events during the bubble phase. The fluent API equivalent to Interactivity::on_key_up.

See Context::listener to get access to a view’s state from this callback.

Source

fn capture_key_up( self, listener: impl Fn(&KeyUpEvent, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to key up events during the capture phase. The fluent API equivalent to Interactivity::capture_key_up.

See Context::listener to get access to a view’s state from this callback.

Source

fn on_modifiers_changed( self, listener: impl Fn(&ModifiersChangedEvent, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to modifiers changing events. The fluent API equivalent to Interactivity::on_modifiers_changed.

See Context::listener to get access to a view’s state from this callback.

Source

fn drag_over<S: 'static>( self, f: impl 'static + Fn(StyleRefinement, &S, &mut Window, &mut App) -> StyleRefinement, ) -> Self

Apply the given style when the given data type is dragged over this element

Source

fn group_drag_over<S: 'static>( self, group_name: impl Into<SharedString>, f: impl FnOnce(StyleRefinement) -> StyleRefinement, ) -> Self

Apply the given style when the given data type is dragged over this element’s group

Source

fn on_drop<T: 'static>( self, listener: impl Fn(&T, &mut Window, &mut App) + 'static, ) -> Self

Bind the given callback to drop events of the given type, whether or not the drag started on this element. The fluent API equivalent to Interactivity::on_drop.

See Context::listener to get access to a view’s state from this callback.

Source

fn can_drop( self, predicate: impl Fn(&dyn Any, &mut Window, &mut App) -> bool + 'static, ) -> Self

Use the given predicate to determine whether or not a drop event should be dispatched to this element. The fluent API equivalent to Interactivity::can_drop.

Source

fn occlude(self) -> Self

Block the mouse from all interactions with elements behind this element’s hitbox. Typically block_mouse_except_scroll should be preferred. The fluent API equivalent to Interactivity::occlude_mouse.

Source

fn window_control_area(self, area: WindowControlArea) -> Self

Set the bounds of this element as a window control area for the platform window. The fluent API equivalent to Interactivity::window_control_area.

Source

fn block_mouse_except_scroll(self) -> Self

Block non-scroll mouse interactions with elements behind this element’s hitbox. The fluent API equivalent to Interactivity::block_mouse_except_scroll.

See Hitbox::is_hovered for details.

Source

fn focus(self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self
where Self: Sized,

Set the given styles to be applied when this element, specifically, is focused. Requires that the element is focusable. Elements can be made focusable using InteractiveElement::track_focus.

Source

fn in_focus(self, f: impl FnOnce(StyleRefinement) -> StyleRefinement) -> Self
where Self: Sized,

Set the given styles to be applied when this element is inside another element that is focused. Requires that the element is focusable. Elements can be made focusable using InteractiveElement::track_focus.

Source

fn focus_visible( self, f: impl FnOnce(StyleRefinement) -> StyleRefinement, ) -> Self
where Self: Sized,

Set the given styles to be applied when this element is focused via keyboard navigation. This is similar to CSS’s :focus-visible pseudo-class - it only applies when the element is focused AND the user is navigating via keyboard (not mouse clicks). Requires that the element is focusable. Elements can be made focusable using InteractiveElement::track_focus.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§