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),
))Items can be what the window is about rather than its pages, as
Mail’s mailboxes or a VM manager’s machines are: a subtitle under
the title, a context_menu each, on_activate for a double-click or
Enter, and children_with for items that come and go.
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 children_with<E: SidebarEntries<T>>(
self,
entries: impl Fn() -> E + 'static,
) -> Sidebar<T>
pub fn children_with<E: SidebarEntries<T>>( self, entries: impl Fn() -> E + 'static, ) -> Sidebar<T>
Items and sections built by entries, and built again whenever what
it reads changes (a list of documents, of machines), after any
children. An item whose value is gone stops being chosen, and the
selection is left as it is.
Sourcepub fn on_activate(self, activate: impl Fn(T) + 'static) -> Sidebar<T>
pub fn on_activate(self, activate: impl Fn(T) + 'static) -> Sidebar<T>
Called with an item’s value when it’s activated, where the platform’s sidebar has that, as a list’s row is: double-clicked or Enter pressed on it (AppKit, GTK, Kirigami; WinUI’s double-tap). The item is chosen first.
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.