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
impl ElementRef
Sourcepub fn on_focus_in(&self, listener: impl Fn() + 'static)
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).
Sourcepub fn on_focus_out(&self, listener: impl Fn() + 'static)
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
impl ElementRef
Sourcepub fn node(&self) -> Option<NodeId>
pub fn node(&self) -> Option<NodeId>
The element’s node, while one is rendered (and the ref’s owner lives).
Sourcepub fn focus(&self)
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.
Sourcepub fn blur(&self)
pub fn blur(&self)
Unfocuses an input, or takes the keyboard focus off a view that takes presses.
Sourcepub fn clear_selection(&self)
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.
Sourcepub fn select_all(&self)
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.
Sourcepub fn set_accessibility_focus(&self)
pub fn set_accessibility_focus(&self)
Moves the screen reader’s focus to the element (TS:
setAccessibilityFocus(ref)).
Sourcepub fn animate_layout(&self, transition: LayoutTransition)
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.
Sourcepub fn set_selection(&self, start: u32, end: u32)
pub fn set_selection(&self, start: u32, end: u32)
Selects start..end of an input (UTF-16 units; a caret when equal).
Sourcepub fn insert_text(&self, text: impl Into<String>)
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).
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.
Closes the edit menu ElementRef::open_edit_menu opened.
Sourcepub fn scroll_to(&self, offset: Point<Points>, animated: bool)
pub fn scroll_to(&self, offset: Point<Points>, animated: bool)
Scrolls a scroll view to a content offset.
Sourcepub fn scroll_to_offset(&self, offset: Points, animated: bool)
pub fn scroll_to_offset(&self, offset: Points, animated: bool)
Scrolls a list to offset along its axis.
Sourcepub fn scroll_to_end(&self, animated: bool)
pub fn scroll_to_end(&self, animated: bool)
Scrolls a scroll view or a list to the end of its content.
Sourcepub fn scroll_to_index(
&self,
index: u32,
view_position: Percentage,
view_offset: Points,
animated: bool,
)
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.
Sourcepub fn reveal(&self, options: RevealOptions)
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.
Sourcepub fn zoom_to(&self, scale: f32, center: Option<Point<Points>>, animated: bool)
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.
Sourcepub fn go_forward(&self)
pub fn go_forward(&self)
Goes forward in a web view’s history.
Sourcepub fn stop_loading(&self)
pub fn stop_loading(&self)
Stops a web view loading.
Sourcepub fn inject_java_script(&self, script: impl Into<String>)
pub fn inject_java_script(&self, script: impl Into<String>)
Runs script in a web view’s page.
Sourcepub fn evaluate(
&self,
script: impl Into<String>,
options: EvaluateOptions,
) -> Answer<Result<Evaluation, JsError>> ⓘ
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.
Sourcepub fn post_message(&self, data: impl Into<String>)
pub fn post_message(&self, data: impl Into<String>)
Sends data to a web view’s page (a message event on window).
Sourcepub fn send_input(&self, input: WebInput)
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).
Sourcepub fn load(&self, load: WebLoad)
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.
Sourcepub fn command(&self, name: &str, args: JsonValue)
pub fn command(&self, name: &str, args: JsonValue)
Calls command name of a native component with args.
Sourcepub fn measure(&self) -> Answer<Option<Measurement>> ⓘ
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.
Sourcepub fn measure_scroll_position(&self) -> Answer<Option<ListScrollPosition>> ⓘ
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
impl ElementRef
Sourcepub fn press_at(&self, press: PressEvent) -> Answer<bool> ⓘ
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.
Sourcepub fn hover_at(&self, mouse: Option<MouseEvent>)
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.
Sourcepub fn transition_time(&self) -> Answer<Duration> ⓘ
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.
Sourcepub fn text_content(&self) -> Answer<String> ⓘ
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
impl Clone for ElementRef
impl Copy for ElementRef
Source§impl Debug for ElementRef
impl Debug for ElementRef
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)).
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)).