Skip to main content

ElementRef

Struct ElementRef 

Source
pub struct ElementRef(/* private fields */);
Expand description

An element of a view: made with super::element_ref, put on the element (super::Element::element_ref). Its commands go to whatever element carries it now, in order with the component’s other changes; they do nothing while no rendered element carries it, and once the owner it was made under is gone. Works from listeners and tasks alike. A Copy handle (see the module’s docs).

Implementations§

Source§

impl ElementRef

Source

pub fn on_focus_in(&self, listener: impl Fn() + 'static)

Listens to the keyboard focus coming into the element: onto it or an element inside it, from outside (GPUI’s on_focus_in of a focus handle; the element enters focus-within). Moving between elements inside it is no new coming in. The content of an overlay is inside the element the overlay is in, wherever it shows: a popup’s trigger and the popup are both inside the view holding them.

It listens while the current owner lives, to whatever element carries the ref, and runs at the end of the commit round the focus moved in (what it changes goes out in the same batch). The focus is what the platform reports: an input’s, or a view’s that Tab or focus() reached where the keyboard moves between views (macOS, the web).

Source

pub fn on_focus_out(&self, listener: impl Fn() + 'static)

Listens to the keyboard focus leaving the element: going from it or an element inside it to one outside, or to none (GPUI’s on_focus_out; the element leaves focus-within). An element removed with the focus inside it, or one that stops carrying the ref, is left too, and the focus coming into the next element that carries the ref is heard by Self::on_focus_in. As Self::on_focus_in otherwise.

Source§

impl ElementRef

Source

pub fn node(&self) -> Option<NodeId>

The element’s node, while one is rendered (and the ref’s owner lives).

Source

pub fn focus(&self)

Focuses an input (showing the keyboard), or gives a view that takes presses the keyboard focus where Tab stops at it (macOS, the web), as Tab does: focus: styles, on_focus. A view focusable(false), disabled or hidden stays unfocused.

Source

pub fn blur(&self)

Unfocuses an input, or takes the keyboard focus off a view that takes presses.

Source

pub fn clear_selection(&self)

Clears the selection of a selectable view the element is, is inside or holds (TS: ref.clearSelection()): its texts lose the highlight and the selectable view hears on_text_selection_change with nothing selected.

Source

pub fn select_all(&self)

Selects all the text of the selectable view the element is or is inside (TS: ref.selectAll()), as the selection menu’s Select All does: its texts are highlighted, phones show the handles and the edit menu, and the selectable view hears on_text_selection_change.

Source

pub fn set_accessibility_focus(&self)

Moves the screen reader’s focus to the element (TS: setAccessibilityFocus(ref)).

Source

pub fn animate_layout(&self, transition: LayoutTransition)

Animates with transition the frames that the element’s change moves in the next commit: its own and its subtree’s, its siblings’ and those of its ancestors’ siblings, which its size pushes along (and the content of those that change size). The commit’s other frames change at once, as do its insertions and removals: a region that grows (a reveal) springs, while a list updating in the same commit elsewhere does not. super::animate_layout animates the whole commit instead, and wins when both are asked for.

Source

pub fn set_selection(&self, start: u32, end: u32)

Selects start..end of an input (UTF-16 units; a caret when equal).

Source

pub fn insert_text(&self, text: impl Into<String>)

Inserts text into an input in place of its selection, as the user’s edit (Command::InsertText): reported by on_change, a step of the input’s undo history where the platform keeps one. With crate::PasteBehavior::Report, what on_paste reported goes in this way once the app allows it (or what the app made of it).

Source

pub fn open_edit_menu( &self, bounds: Bounds<Points>, actions: impl IntoIterator<Item = EditAction>, )

Opens the system’s edit menu over bounds (in the root view) on a focused input, offering actions (Command::OpenEditMenu): a chosen action comes back as super::EventKind::EditAction, a paste as the input’s on_paste.

Source

pub fn close_edit_menu(&self)

Closes the edit menu ElementRef::open_edit_menu opened.

Source

pub fn scroll_to(&self, offset: Point<Points>, animated: bool)

Scrolls a scroll view to a content offset.

Source

pub fn scroll_to_offset(&self, offset: Points, animated: bool)

Scrolls a list to offset along its axis.

Source

pub fn scroll_to_end(&self, animated: bool)

Scrolls a scroll view or a list to the end of its content.

Source

pub fn scroll_to_index( &self, index: u32, view_position: Percentage, view_offset: Points, animated: bool, )

Scrolls a list to row index: view_position 0% puts it at the start of the viewport, 100% at the end, view_offset further.

Source

pub fn reveal(&self, options: RevealOptions)

Scrolls the scroll views around the element so it shows, placed by options (TS: ref.reveal(options)), with the layout of the commit this call goes out with. Lists keep their rows’ offsets to scroll_to_index.

Source

pub fn zoom_to(&self, scale: f32, center: Option<Point<Points>>, animated: bool)

Zooms a scroll view to scale, around center (in the content) or keeping the middle.

Source

pub fn reload(&self)

Reloads a web view’s page.

Source

pub fn go_back(&self)

Goes back in a web view’s history.

Source

pub fn go_forward(&self)

Goes forward in a web view’s history.

Source

pub fn stop_loading(&self)

Stops a web view loading.

Source

pub fn inject_java_script(&self, script: impl Into<String>)

Runs script in a web view’s page.

Source

pub fn evaluate( &self, script: impl Into<String>, options: EvaluateOptions, ) -> Answer<Result<Evaluation, JsError>> ⓘ

Runs script in a web view’s page and answers with its result (TS: ref.evaluate(script, options)): the script’s completion value, a returned Promise’s once it settles, as JSON. Fails with codes::WEBVIEW_SCRIPT when the script throws, its Promise rejects or its value is not JSON, codes::WEBVIEW_ABORTED when the page navigates or the web view goes away first, codes::TIMED_OUT after options.timeout, and codes::UNAVAILABLE where the platform has none (web_evaluate_available). Await it in a task.

Source

pub fn post_message(&self, data: impl Into<String>)

Sends data to a web view’s page (a message event on window).

Source

pub fn send_input(&self, input: WebInput)

Gives a web view’s page input as the user’s own: its events are trusted. Needs the webview.input capability; macOS delivers it, the other platforms ignore it for now (web_input_available tells).

Source

pub fn load(&self, load: WebLoad)

Loads load.src in a web view with load.headers on the document request only (not its subresources, later navigations or reloads), as an Authorization header for a signed-in page. Its host must be one the webview capability allows.

Source

pub fn seek(&self, seconds: f64)

Jumps a video to seconds.

Source

pub fn command(&self, name: &str, args: JsonValue)

Calls command name of a native component with args.

Source

pub fn measure(&self) -> Answer<Option<Measurement>> ⓘ

Where the element is (TS: ref.measure()): its frame in its parent and its top left corner in the root view it is in (the surface or its modal; scroll offsets applied), from the layout of the commit this call goes out with, so changes made before it count. None when no rendered element carries the ref or it is not laid out. Await it in a task.

Source

pub fn measure_scroll_position(&self) -> Answer<Option<ListScrollPosition>> ⓘ

Where a list’s viewport starts among its rows (TS: ref.measureScrollPosition()): the row there and how far into it, as the list lays its rows out, from the layout of the commit this call goes out with. ElementRef::scroll_to_index with the row and a view offset of -offset puts the viewport’s start back there, as for a list made anew. None when no rendered list carries the ref or it has no items. Await it in a task.

Source§

impl ElementRef

Source

pub fn press_at(&self, press: PressEvent) -> Answer<bool> ⓘ

Passes a press on into the element: the innermost, topmost view in it under press.page_position (in its root view, as a pointer’s) that hears presses gets onPress, its position in that view, with the layout of the commit this call goes out with. Answers whether a view took it. For a component whose own hit layer lies over content the app renders (a table’s cells): that content’s pressable views get the presses on them. The element’s own pointerEvents do not count; press states stay the hit layer’s, hovers are passed on with Self::hover_at. Await it in a task.

Source

pub fn hover_at(&self, mouse: Option<MouseEvent>)

Passes a pointer on into the element, as Self::press_at does a press: the views in it under mouse.page_position (in its root view, as a pointer’s) and the views around them up to the element are hovered, with the layout of the last commit. Their hover: classes and the group-hover: classes inside them apply, and those that listen hear onMouseEnter / onMouseLeave as the views under the pointer change and onMouseMove on each call. None: the pointer left the element. For a component whose own hit layer lies over content the app renders (a table’s cells), from the hit layer’s onMouseMove and onMouseLeave. The element’s own pointerEvents do not count.

Source

pub fn transition_time(&self) -> Answer<Duration> ⓘ

How long the element’s transitions run (transition*: the longest duration plus its delay), with the styles of the commit this call goes out with, so a class or style set before it counts; zero when it has none or no rendered element carries the ref. The platforms run transitions without reporting their end: a component that keeps an element through its exit (a popup’s ending style) waits this long. Await it in a task.

Source

pub fn text_content(&self) -> Answer<String> ⓘ

The text the element shows (the DOM’s textContent): the texts inside it in tree order, joined, with the commit this call goes out with, so a text changed before it counts. What display: none hides is left out; empty when no rendered element carries the ref. For a component that matches its content’s words (a menu’s typeahead). Await it in a task.

Trait Implementations§

Source§

impl Clone for ElementRef

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ElementRef

Source§

impl Debug for ElementRef

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<ElementRef> for Option<ElementTarget>

A Rust ref, as the element carrying it (a component’s prop that names an element, set from Rust: Some(error_line)).

Source§

fn from(element: ElementRef) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ElementRef

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.