Skip to main content

Sidebar

Struct Sidebar 

Source
pub struct Sidebar<'a> { /* private fields */ }
Expand description

Animated sidebar component styled to match shadcn/ui

Supports both controlled mode (with external SidebarState) and uncontrolled mode.

§Controlled Mode Example

// Store state somewhere persistent
let mut sidebar_state = SidebarState::new(true);

// In your UI code:
Sidebar::new()
    .state(&mut sidebar_state)
    .show(ui, |sidebar| {
        sidebar.item("Home", "Home").active(true);
    });

// Toggle from anywhere:
if some_button_clicked {
    sidebar_state.toggle();
}

§Uncontrolled Mode Example

Sidebar::new()
    .collapsed(false)
    .show(ui, |sidebar| {
        sidebar.group_label("Platform");
        sidebar.item("Home", "Home").active(true);
        sidebar.item("Messages", "Messages").badge("5");
    })

Implementations§

Source§

impl<'a> Sidebar<'a>

Source

pub const fn new() -> Self

Create a new sidebar with shadcn defaults

Source

pub const fn state(self, state: &'a mut SidebarState) -> Self

Use external state for controlled mode

This allows you to control the sidebar from outside and persist state.

Source

pub const fn collapsed(self, collapsed: bool) -> Self

Set whether the sidebar starts collapsed (uncontrolled mode only)

Source

pub const fn collapsed_width(self, width: f32) -> Self

Set the collapsed width (default: 48px / 3rem)

Source

pub const fn expanded_width(self, width: f32) -> Self

Set the expanded width (default: 256px / 16rem)

Source

pub const fn collapsible(self, mode: CollapsibleMode) -> Self

Set the collapsible mode

Source

pub const fn show_icons(self, show_icons: bool) -> Self

Set whether to show icons

Source

pub const fn variant(self, variant: SidebarVariant) -> Self

Set the visual variant

Source

pub fn show<R>( self, ui: &mut Ui, content: impl FnOnce(&mut SidebarBuilder<'_>) -> R, ) -> SidebarResponse

Show the sidebar

Trait Implementations§

Source§

impl Default for Sidebar<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Sidebar<'a>

§

impl<'a> RefUnwindSafe for Sidebar<'a>

§

impl<'a> Send for Sidebar<'a>

§

impl<'a> Sync for Sidebar<'a>

§

impl<'a> Unpin for Sidebar<'a>

§

impl<'a> UnsafeUnpin for Sidebar<'a>

§

impl<'a> !UnwindSafe for Sidebar<'a>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.