pub struct TreeState { /* private fields */ }Expand description
Retained state entity for a Material Tree.
Wraps gpui-base’s virtualized tree state while exposing Material-owned nodes,
events, and WAI-ARIA keyboard helpers that honor local ThemeScope direction
and skip disabled nodes.
Implementations§
Source§impl TreeState
impl TreeState
Sourcepub fn items(
self,
items: impl Into<Vec<TreeNode>>,
cx: &mut Context<'_, TreeState>,
) -> TreeState
pub fn items( self, items: impl Into<Vec<TreeNode>>, cx: &mut Context<'_, TreeState>, ) -> TreeState
Populates the initial tree items during construction.
Sourcepub fn set_items(
&mut self,
items: impl Into<Vec<TreeNode>>,
cx: &mut Context<'_, TreeState>,
)
pub fn set_items( &mut self, items: impl Into<Vec<TreeNode>>, cx: &mut Context<'_, TreeState>, )
Replaces the tree model, clearing the previous selection.
Sourcepub fn visible_count(&self) -> usize
pub fn visible_count(&self) -> usize
Returns the number of currently visible flattened rows.
Sourcepub fn selected_index(&self, cx: &App) -> Option<usize>
pub fn selected_index(&self, cx: &App) -> Option<usize>
Returns the currently selected visible row index, if any.
Sourcepub fn selected_id(&self, cx: &App) -> Option<SharedString>
pub fn selected_id(&self, cx: &App) -> Option<SharedString>
Returns the ID of the currently selected node, if any.
Sourcepub fn is_expanded(&self, id: &str) -> bool
pub fn is_expanded(&self, id: &str) -> bool
Returns whether the node with id is currently expanded.
Sourcepub fn select(&mut self, id: Option<&str>, cx: &mut Context<'_, TreeState>)
pub fn select(&mut self, id: Option<&str>, cx: &mut Context<'_, TreeState>)
Selects the node with id (expanding hidden ancestors if needed) or clears selection when None.
Disabled nodes cannot be selected.
Sourcepub fn set_expanded(
&mut self,
id: &str,
expanded: bool,
cx: &mut Context<'_, TreeState>,
) -> bool
pub fn set_expanded( &mut self, id: &str, expanded: bool, cx: &mut Context<'_, TreeState>, ) -> bool
Expands or collapses the branch node with id, returning true when state changed.
Sourcepub fn toggle_expanded(
&mut self,
id: &str,
cx: &mut Context<'_, TreeState>,
) -> Option<bool>
pub fn toggle_expanded( &mut self, id: &str, cx: &mut Context<'_, TreeState>, ) -> Option<bool>
Toggles the expansion state of the branch node with id, returning the new expanded state
if the node is an enabled branch.
Sourcepub fn expand_all(&mut self, cx: &mut Context<'_, TreeState>)
pub fn expand_all(&mut self, cx: &mut Context<'_, TreeState>)
Expands all enabled branch nodes.
Sourcepub fn collapse_all(&mut self, cx: &mut Context<'_, TreeState>)
pub fn collapse_all(&mut self, cx: &mut Context<'_, TreeState>)
Collapses all enabled branch nodes.
Sourcepub fn reveal(
&mut self,
id: &str,
strategy: ScrollStrategy,
cx: &mut Context<'_, TreeState>,
)
pub fn reveal( &mut self, id: &str, strategy: ScrollStrategy, cx: &mut Context<'_, TreeState>, )
Expands ancestors of id and scrolls it into view.
Sourcepub fn scroll_handle(&self, cx: &App) -> UniformListScrollHandle
pub fn scroll_handle(&self, cx: &App) -> UniformListScrollHandle
Returns a clone of the underlying list scroll handle (compatible with DisplayScrollbar).
Sourcepub fn focus(&self, window: &mut Window, cx: &mut App)
pub fn focus(&self, window: &mut Window, cx: &mut App)
Focuses the tree for keyboard navigation.
Sourcepub fn is_focused(&self, window: &Window, cx: &App) -> bool
pub fn is_focused(&self, window: &Window, cx: &App) -> bool
Returns true when this tree currently owns keyboard focus.
Trait Implementations§
impl EventEmitter<TreeEvent> for TreeState
Auto Trait Implementations§
impl !RefUnwindSafe for TreeState
impl !Send for TreeState
impl !Sync for TreeState
impl !UnwindSafe for TreeState
impl Forget for TreeState
impl Freeze for TreeStatewhere
NonZero<u32>: Freeze,
*const (): Freeze,
*const ArcInner<RwLock<RawRwLock, EntityRefCounts>> is !null: Freeze,
PhantomData<fn(TreeState) -> TreeState>: Freeze,
*const ArcInner<RwLock<RawRwLock, FocusMap>> is !null: Freeze,
PhantomData<ArcInner<RwLock<RawRwLock, FocusMap>>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<TreeNode>: Freeze,
PhantomData<FlatNode>: Freeze,
PhantomData<(SharedString, IconName)>: Freeze,
*const dyn FnOnce() is !null: Freeze,
PhantomData<dyn FnOnce()>: Freeze,
impl Move for TreeState
impl Unpin for TreeState
impl UnsafeUnpin for TreeStatewhere
NonZeroU32Inner: UnsafeUnpin,
*const (): UnsafeUnpin,
*const ArcInner<RwLock<RawRwLock, EntityRefCounts>> is !null: UnsafeUnpin,
PhantomData<fn(TreeState) -> TreeState>: UnsafeUnpin,
*const ArcInner<RwLock<RawRwLock, FocusMap>> is !null: UnsafeUnpin,
PhantomData<ArcInner<RwLock<RawRwLock, FocusMap>>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<TreeNode>: UnsafeUnpin,
PhantomData<FlatNode>: UnsafeUnpin,
PhantomData<(SharedString, IconName)>: UnsafeUnpin,
*const dyn FnOnce() is !null: UnsafeUnpin,
PhantomData<dyn FnOnce()>: UnsafeUnpin,
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
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> 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