pub struct TreeViewHandle { /* private fields */ }Expand description
A handle on a mounted TreeView, to scroll it to a row from outside the
widget — a view-model revealing the node a search found, say.
Rows are addressed by their flat visible index: the position of the row among the rows currently shown, counting the children of expanded nodes and skipping those of collapsed ones (the index the delegate’s selection and the keyboard use).
Cheap to clone, valid before the view is mounted, and it survives the view’s rebuilds. Its methods never compute an offset when they are called: they record the request and ask for a layout pass, and the view applies it there, after row measurement and scroll anchoring have settled. So a structural change made in the same turn (a node expanded above the target, say) is accounted for, a request made before mount is applied at the first layout, and a later request replaces an earlier pending one. A request on an empty tree is dropped; an index past the end reveals the last row.
The handle also reads and moves the tree’s keyboard cursor, the row the
arrow keys step from and assistive technology is told is current:
cursor, set_cursor and
cursor_signal, in the same flat visible indices.
In a multiple selection the cursor and the selection are separate: the
accelerator with an arrow moves the cursor alone, and a selection written
from outside leaves the cursor where it was.
let tree = TreeView::new(model, |item, _entry, _selected| {
Box::new(TextWidget::new(lit!(item)))
});
let handle = tree.handle();
// … `ctx.add(tree)`; later, after expanding the node's ancestors:
handle.ensure_index_visible(42);Implementations§
Source§impl TreeViewHandle
impl TreeViewHandle
Sourcepub fn scroll_to_index(&self, index: usize)
pub fn scroll_to_index(&self, index: usize)
Scroll so the row at the given flat visible index is aligned to the top of the viewport, as far as the scroll range allows, at the next layout pass.
Sourcepub fn ensure_index_visible(&self, index: usize)
pub fn ensure_index_visible(&self, index: usize)
Scroll the minimum distance that brings the row at the given flat visible index fully into view, at the next layout pass; no scroll when it already is.
Sourcepub fn cursor(&self) -> Option<usize>
pub fn cursor(&self) -> Option<usize>
The flat visible index the keyboard cursor is on, or None while the
tree has no cursor: it has not been navigated, clicked or given one by
set_cursor. With no cursor the keys start from
the first selected row, and from the first or last row when nothing is
selected.
The cursor follows its row: an expansion or a collapse above it, or an
insertion, moves the index with the row, and a row that leaves the
visible rows takes the cursor with it. In a single selection
the cursor follows the selection: the keys move them together, and a
selection written from outside moves the cursor onto it. In a multiple
selection they are separate: the accelerator with an arrow
(Ctrl+Arrow) moves the cursor alone, and a selection written from
outside leaves the cursor where it was.
Sourcepub fn set_cursor(&self, index: Option<usize>)
pub fn set_cursor(&self, index: Option<usize>)
Move the keyboard cursor to the row at flat visible index index, or
remove it with None.
An index past the last visible row is clamped to that row; on an empty tree the cursor is removed. While the tree holds keyboard focus it names the row as its active descendant at the next accessibility update, when the row is realized; the next arrow key steps from it, and the cursor follows that row through later structural changes.
Keyboard focus and the selection are left alone, and the tree does not
scroll: pair it with
ensure_index_visible to bring the row
into view. Usable before the tree is mounted and across its rebuilds;
in a single selection the tree seats the cursor on the selected row
when it is built and whenever the selection changes.
Sourcepub fn cursor_signal(&self) -> Signal<Option<usize>>
pub fn cursor_signal(&self) -> Signal<Option<usize>>
A read-only signal of the cursor, as cursor reports
it, for an application to observe or bind: a status line naming the
current row, actions enabled for it. It changes with every write of
the cursor, by the keys, a click, a structural change moving it or
set_cursor.
Trait Implementations§
Source§impl Clone for TreeViewHandle
impl Clone for TreeViewHandle
Source§fn clone(&self) -> TreeViewHandle
fn clone(&self) -> TreeViewHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for TreeViewHandle
impl !Send for TreeViewHandle
impl !Sync for TreeViewHandle
impl !UnwindSafe for TreeViewHandle
impl Freeze for TreeViewHandle
impl Unpin for TreeViewHandle
impl UnsafeUnpin for TreeViewHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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