pub struct Sidebar<T: 'static> { /* private fields */ }Expand description
The sidebar of the window it’s declared in: the list down its leading side that picks what the window shows, as in macOS’s System Settings and GNOME’s Settings (a source list on macOS, libadwaita’s navigation split view on GTK, a NavigationView’s pane on Windows, a first column of Kirigami’s page row on KDE). Declare it anywhere in the window’s content; it stays while it does.
Its items are SidebarItems, in SidebarSections or on their own.
selection holds the value of the chosen item, and choosing another
sets it; a value no item has chooses none. The window’s content is
what’s beside the sidebar: show the page for the selection there. The
platform draws the sidebar, sizes it, and collapses it in a narrow
window its own way. The window’s size is its content’s, and the
sidebar is added to it.
let page = signal(Page::General);
Column::new().children((
Sidebar::new(page).children((
SidebarItem::new("General", Page::General).icon(platform! {
macos => "gearshape",
gtk | kde => "preferences-system-symbolic",
windows => "\u{E713}",
}),
SidebarSection::new("Network").children((
SidebarItem::new("Wi-Fi", Page::WiFi),
SidebarItem::new("Bluetooth", Page::Bluetooth),
)),
)),
Show::new(move || page.get() == Page::General, general),
))In view!: <Sidebar selection=page>, with
<SidebarItem value=Page::General>"General"</SidebarItem>s and
<SidebarSection title="Network">s as children.
Implementations§
Source§impl<T: PartialEq + Clone + 'static> Sidebar<T>
impl<T: PartialEq + Clone + 'static> Sidebar<T>
pub fn new(selection: Signal<T>) -> Sidebar<T>
Sourcepub fn shown(self, shown: Signal<bool>) -> Sidebar<T>
pub fn shown(self, shown: Signal<bool>) -> Sidebar<T>
Shown beside the window’s content while shown is true, hidden
otherwise, as the platform shows and hides a sidebar. The user can
change it too (the platform’s toggle, its divider dragged away),
which sets the signal. Where the platform’s sidebar can’t be hidden
in a wide window (GTK), it’s the page shown in a narrow one.
Sourcepub fn native(self, tweak: Tweak<Sidebar<T>>) -> Sidebar<T>
pub fn native(self, tweak: Tweak<Sidebar<T>>) -> Sidebar<T>
Raw platform settings: see Tweak. How wide a sidebar is, say,
is each platform’s own.
Sourcepub fn children(self, children: impl SidebarEntries<T>) -> Sidebar<T>
pub fn children(self, children: impl SidebarEntries<T>) -> Sidebar<T>
Items and sections, in order. Items outside a section next to each other are one section without a heading.