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>
impl<'a> Sidebar<'a>
Sourcepub const fn state(self, state: &'a mut SidebarState) -> Self
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.
Sourcepub const fn collapsed(self, collapsed: bool) -> Self
pub const fn collapsed(self, collapsed: bool) -> Self
Set whether the sidebar starts collapsed (uncontrolled mode only)
Sourcepub const fn collapsed_width(self, width: f32) -> Self
pub const fn collapsed_width(self, width: f32) -> Self
Set the collapsed width (default: 48px / 3rem)
Sourcepub const fn expanded_width(self, width: f32) -> Self
pub const fn expanded_width(self, width: f32) -> Self
Set the expanded width (default: 256px / 16rem)
Sourcepub const fn collapsible(self, mode: CollapsibleMode) -> Self
pub const fn collapsible(self, mode: CollapsibleMode) -> Self
Set the collapsible mode
Sourcepub const fn show_icons(self, show_icons: bool) -> Self
pub const fn show_icons(self, show_icons: bool) -> Self
Set whether to show icons
Sourcepub const fn variant(self, variant: SidebarVariant) -> Self
pub const fn variant(self, variant: SidebarVariant) -> Self
Set the visual variant
Sourcepub fn show<R>(
self,
ui: &mut Ui,
content: impl FnOnce(&mut SidebarBuilder<'_>) -> R,
) -> SidebarResponse
pub fn show<R>( self, ui: &mut Ui, content: impl FnOnce(&mut SidebarBuilder<'_>) -> R, ) -> SidebarResponse
Show the sidebar
Trait Implementations§
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> 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
Mutably borrows from an owned value. Read more