Skip to main content

InteractiveElement

Trait InteractiveElement 

Source
pub trait InteractiveElement: Sized {
Show 53 methods // Required method fn interactivity(&mut self) -> &mut Interactivity; // Provided methods fn on_file_drop_exit( self, listener: impl Fn(&FileDropEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn transitions( self, build: impl FnOnce(StyleTransitions) -> StyleTransitions, ) -> Self { ... } 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: Display { ... } 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, f: 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_pressure( self, listener: impl Fn(&MousePressureEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn capture_mouse_pressure( self, listener: impl Fn(&MousePressureEvent, &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_down_all( self, listener: impl Fn(&MouseDownEvent, DispatchPhase, &Hitbox, &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_up_all( self, listener: impl Fn(&MouseUpEvent, DispatchPhase, &Hitbox, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_mouse_move( self, listener: impl Fn(&MouseMoveEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_mouse_move_all( self, listener: impl Fn(&MouseMoveEvent, DispatchPhase, &Hitbox, &mut Window, &mut App) + 'static, ) -> Self { ... } fn on_mouse_exit( self, listener: impl Fn(&MouseExitEvent, &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 on_pinch( self, listener: impl Fn(&PinchEvent, &mut Window, &mut App) + 'static, ) -> Self { ... } fn capture_pinch( self, listener: impl Fn(&PinchEvent, &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 on_drag_over<S: 'static>( self, f: impl 'static + Fn(StyleRefinement, &S, &mut Window, &mut App) -> StyleRefinement, ) -> Self { ... } fn on_drag_over_any( self, f: impl 'static + Fn(StyleRefinement, &dyn Any, &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 on_drop_alt<T: 'static>(self, listener: DropListener<T>) -> 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 { ... } fn cursor_with( self, resolver: impl Fn(Point<Pixels>, Bounds<Pixels>) -> Option<CursorStyle> + 'static, ) -> Self where Self: Sized { ... }
}
Expand description

An element that can respond to the mouse and keyboard, style itself on state, and take focus.

Implement this trait with Element to give a custom element the event handlers and styles of Div. Return its Interactivity from interactivity; the default methods update that value and return self, so calls chain.

Most handlers need no id. The exceptions are the ones that keep state between frames, such as clicks, starting a drag, scrolling and tooltips. Those live on StatefulInteractiveElement, and are reached by calling id first.

Event handlers run in two phases. Capture walks from the back of the window to the front, then bubble walks from the front to the back. Methods named capture_* use capture; most other methods use bubble. Each *_out and *_all variant documents its own hitbox rule. See the input dispatch concept for the full path.

§Example

let toggle = div()
    .id("toggle")
    .px_2()
    .bg(rgb(0xe5e7eb))
    .hover(|style| style.bg(rgb(0xd1d5db)))
    .on_click(|_, _, _| {});

Required Methods§

Source

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

Returns the Interactivity that stores this element’s listeners, styles and state.

Every other method on this trait is implemented by calling this one, so implement it by returning a field.

Provided Methods§

Source

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

Bind the given callback to FileDropEvent::Exited when a platform file drag leaves this element’s window while the element is hovered.

This is a window-local exit event, not notification that the platform drag session ended. The fluent API equivalent to Interactivity::on_file_drop_exit.

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

Source

fn transitions( self, build: impl FnOnce(StyleTransitions) -> StyleTransitions, ) -> Self

Animates changes to this element’s style properties over time.

build receives a StyleTransitions and returns it with the properties to animate and their timing. When a style property changes between frames, such as a width set by a hover style, the change plays as a transition instead of jumping.

If the element has no id, GPUI derives one from the call site. Give repeated elements built at the same call site an explicit id, so that each one keeps its own motion state.

Source

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

Adds this element to a named group, so that group-level styles can react to any member.

Members of the group share a name. Other elements can then use group_hover, group_active or group_drag_over with that name to style themselves when any member is hovered, pressed or has a dragged value over it. The group name must match exactly.

Source

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

Gives this element an ElementId, which turns it into a Stateful element.

An id is required for anything that keeps state between frames: clicks, scrolling, drag and drop, active styles, and tooltips. GPUI matches the id against the previous frame to find that state, so the id must be stable across renders and unique among siblings. Use a value that identifies the content, such as a database id, for elements that can move. Ids may be strings, numbers, or tuples of these.

§Example
let row = div()
    .id(("row", 3usize))
    .on_click(|_, _, _| {});
Source

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

Makes this element focusable with the given FocusHandle, and styles it with the focus styles when focused.

The element joins the focus path when the handle is focused, so keyboard input reaches it. Focus styles set with focus, in_focus and focus_visible apply only to elements that track a handle. Use focusable when you don’t need to hold the handle. See the focus guide.

Source

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

Sets whether this element is reached by Tab navigation.

When false, the element keeps its place in the tab order, but Window::focus_next and Window::focus_prev skip it. Use it on a container that should take focus only to pass it on to its first tab stop. This works with tab_index and tab_group.

Source

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

Sets this element’s position in the tab order and makes it a tab stop.

Elements with lower indices are visited first. Elements with the same index, or no index, keep their order in the tree. It also makes the element focusable, which needs either an id or a focus handle from track_focus. Use it sparingly: a tab group is usually better than numbering every element in a window. See tab_group.

Source

fn tab_group(self) -> Self

Makes this element a tab group, so that its children are ordered within the group.

A tab group takes its own position in the tab order, from its tab_index, which defaults to 0. Its children start again at index 0, so you can reorder the stops inside the group without renumbering the rest of the window.

Source

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

Sets the key context for this element, which selects the keybindings that apply inside it.

A binding that names a context applies only when an element with that context is on the focus path. Use a short name that matches the bindings, such as "Editor". If the value cannot be converted to a KeyContext, the error is logged and the element keeps no context.

Source

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

Applies f’s style to this element while the pointer is over it.

The style applies only while the element is hovered, not during a drag, and not after keyboard input. Hover is recalculated each frame, so the style follows the pointer without any state in your code.

§Example
let button = div()
    .id("save")
    .bg(rgb(0x2563eb))
    .hover(|style| style.bg(rgb(0x1d4ed8)));
Source

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

Applies f’s style to this element while any member of group_name is hovered.

Set the group with group on the parent. The style does not apply during a drag or after keyboard input.

Source

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

Runs listener when button is pressed over this element, during the bubble phase.

The listener runs only if the pointer is over the element’s hitbox. It receives the MouseDownEvent, the window and the app. The fluent equivalent of Interactivity::on_mouse_down. Use Context::listener to call into a view.

Source

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

Sets a name for this element that tests can use to find its bounds.

Pass the name to VisualTestContext::debug_bounds to get the bounds of the element in a test. Selectors are recorded only in tests and in debug builds with the test-support feature; elsewhere this is a no-op, so test-support can stay enabled in release builds.

Source

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

Runs listener for a press of any button over this element, during the capture phase.

Use it to see a press before the element on top of this one handles it. The fluent equivalent of Interactivity::capture_any_mouse_down.

Source

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

Runs listener for a press of any button over this element, during the bubble phase.

The fluent equivalent of Interactivity::on_any_mouse_down.

Source

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

Runs listener when button is released over this element, during the bubble phase.

The listener runs only if the pointer is over the element’s hitbox. The fluent equivalent of Interactivity::on_mouse_up.

Source

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

Runs listener for a release of any button over this element, during the capture phase.

The fluent equivalent of Interactivity::capture_any_mouse_up.

Source

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

Runs listener for pressure changes over this element, during the bubble phase.

The fluent equivalent of Interactivity::on_mouse_pressure.

Source

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

Runs listener for pressure changes over this element, during the capture phase.

The fluent equivalent of Interactivity::capture_mouse_pressure.

Source

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

Runs listener for a press of any button outside this element, during the capture phase.

Use it to dismiss a popover or menu when the user clicks elsewhere. It does not run while a window prompt is open. The fluent equivalent of Interactivity::on_mouse_down_out.

Source

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

Runs listener for every mouse press, in both phases, whether or not the pointer is over the element.

The listener receives the phase, the element’s hitbox, and the event. The fluent equivalent of Interactivity::on_mouse_down_all.

Source

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

Runs listener when button is released outside this element, during the capture phase.

The listener runs only if the pointer is not over the element’s hitbox at the release. The fluent equivalent of Interactivity::on_mouse_up_out.

Source

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

Runs listener for every mouse release, in both phases, whether or not the pointer is over the element.

The listener receives the phase, the element’s hitbox, and the event. The fluent equivalent of Interactivity::on_mouse_up_all.

Source

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

Runs listener when the pointer moves over this element, during the bubble phase.

The fluent equivalent of Interactivity::on_mouse_move.

Source

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

Runs listener for every mouse move, whether or not the pointer is over the element.

The listener receives the phase, the element’s hitbox, and the event. The fluent equivalent of Interactivity::on_mouse_move_all.

Source

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

Runs listener when the pointer leaves the window while it is over this element.

The fluent equivalent of Interactivity::on_mouse_exit.

Source

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

Runs listener for pointer moves during any drag of type T, wherever the drag started.

The listener runs for every move while the drag is active, even outside this element. This is the right hook for drags that don’t drop anywhere, such as resizing a splitter. The fluent equivalent of Interactivity::on_drag_move.

Source

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

Runs listener for scroll wheel events that this element should handle, during the bubble phase.

The innermost element runs first, and the event continues to ancestors unless a listener calls App::stop_propagation. The fluent equivalent of Interactivity::on_scroll_wheel.

Source

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

Runs listener for pinch gestures over this element, during the bubble phase.

The fluent equivalent of Interactivity::on_pinch.

Source

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

Runs listener for pinch gestures during the capture phase.

The fluent equivalent of Interactivity::capture_pinch.

Source

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

Runs listener when an action of type A is dispatched to this element, during the capture phase.

The capture phase runs before the bubble phase, so the listener sees the action before this element’s on_action handler and before its descendants’. Dispatch continues unless the listener calls App::stop_propagation. The fluent equivalent of Interactivity::capture_action.

Source

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

Runs listener when an action of type A is dispatched to this element, during the bubble phase.

The action reaches this element when it is on the focus path and no capture listener stopped it. Dispatch stops at this element after the listener runs, unless the listener calls App::propagate. The fluent equivalent of Interactivity::on_action.

§Example
use gpui::{Context, Window, actions, div, prelude::*};

actions!(note_example, [Save]);

struct Note {
    saves: usize,
}

impl Render for Note {
    fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
        div().on_action(cx.listener(|note: &mut Note, _: &Save, _window, cx| {
            note.saves += 1;
            cx.notify();
        }))
    }
}
Source

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

Runs listener when an action of the same type as action is dispatched, during the bubble phase.

Use this when the action type is only known at runtime. The listener receives the value passed here, so only its type decides when it runs. The fluent equivalent of Interactivity::on_boxed_action.

Source

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

Runs listener for key presses, during the bubble phase.

The listener runs only if no action bound to the keystroke handled it, and the element must be on the focus path. Use it for text entry and other keys that have no action. The fluent equivalent of Interactivity::on_key_down.

Source

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

Runs listener for key presses during the capture phase. Like on_key_down, it runs only if no action bound to the keystroke handled it.

The fluent equivalent of Interactivity::capture_key_down.

Source

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

Runs listener for key releases, during the bubble phase.

The fluent equivalent of Interactivity::on_key_up.

Source

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

Runs listener for key releases during the capture phase.

The fluent equivalent of Interactivity::capture_key_up.

Source

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

Runs listener when the set of pressed modifier keys changes.

The fluent equivalent of Interactivity::on_modifiers_changed.

Source

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

Applies f’s style while a value of type S is dragged over this element.

Same as on_drag_over.

Source

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

Applies f’s style while a value of type S is dragged over this element and the element accepts it.

The style applies only while the pointer is over the element, and only when the element has a drop listener for S whose can_drop check passes, if it has one. Style the element differently for each kind of drag. Use on_drag_over_any for a style that doesn’t depend on the type.

§Example
#[derive(Clone)]
struct FileDrag(String);

let drop_zone = div()
    .on_drag_over::<FileDrag>(|style, _file, _window, _cx| {
        style.bg(rgb(0xdbeafe))
    });
Source

fn on_drag_over_any( self, f: impl 'static + Fn(StyleRefinement, &dyn Any, &mut Window, &mut App) -> StyleRefinement, ) -> Self

Applies f’s style while any dragged value is over this element and the element can accept it.

The fluent equivalent of Interactivity::on_drag_over_any. It applies only when the element has a drop listener for the dragged type.

Source

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

Applies f’s style while a value of type S is dragged over any member of group_name.

Set the group with group on the parent. The style applies only when the dragged type matches and the group member is hovered.

Source

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

Runs listener when a drag of type T is released over this element.

The drop runs whether or not the drag started on this element. Use can_drop or a DropListener to refuse some drops. The fluent equivalent of Interactivity::on_drop.

Source

fn on_drop_alt<T: 'static>(self, listener: DropListener<T>) -> Self

Attaches a DropListener that handles drags of type T over this element.

Use this when one element needs a can_drop check, a drag-over style and a drop handler together. The fluent equivalent of Interactivity::on_drop_alt.

Source

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

Sets a predicate that decides whether this element accepts the dragged value.

The predicate runs only while the pointer is over the element, and it receives the dragged value. Use it for checks that don’t depend on the type of the value. The fluent equivalent of Interactivity::can_drop.

Source

fn occlude(self) -> Self

Stops the mouse from reaching elements behind this element.

Use it for floating panels, so that a click on the panel doesn’t also click the content underneath. Prefer block_mouse_except_scroll when the content should still scroll. The fluent equivalent of Interactivity::occlude_mouse.

Source

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

Marks this element’s bounds as a window control area, such as a custom title bar button.

The platform uses area to decide what clicks and drags here do, such as moving or closing the window. The fluent equivalent of Interactivity::window_control_area.

Source

fn block_mouse_except_scroll(self) -> Self

Stops mouse interactions from reaching elements behind this element, but lets scroll events through.

Use it for a panel that covers content which should still scroll. The fluent equivalent of Interactivity::block_mouse_except_scroll.

Source

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

Applies f’s style when this element itself has focus.

The element must track a focus handle with track_focus. The style applies whenever the element is focused, whether focus came from the mouse or the keyboard. To style only keyboard focus, use focus_visible.

Source

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

Applies f’s style when this element or one of its ancestors has focus.

This tests FocusHandle::within_focused. To style a parent while its child has focus, query FocusHandle::contains_focused during rendering and choose the style from that result. The element must track a focus handle with track_focus.

Source

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

Applies f’s style when this element has focus and the last input was from the keyboard.

This is like the CSS :focus-visible pseudo-class: the ring shows during keyboard navigation and not after a mouse click. The element must track a focus handle with track_focus.

§Example
let button = div()
    .focus_visible(|style| style.border_2().border_color(rgb(0x2563eb)));
Source

fn cursor_with( self, resolver: impl Fn(Point<Pixels>, Bounds<Pixels>) -> Option<CursorStyle> + 'static, ) -> Self
where Self: Sized,

Resolves this element’s cursor from pointer position and bounds. Return None to defer to another cursor request.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§