pub struct DocumentTabs<T: 'static> { /* private fields */ }Expand description
Tabs for the documents the app has open, as a browser’s or a terminal’s: the platform’s own (in the title bar on macOS, as Safari’s and Xcode’s, and on Windows; libadwaita’s tab bar on GNOME, a tab bar on KDE). The tabs have no pages: the app shows the chosen document itself, in one place, as a terminal draws its sessions on one surface.
Its tabs are DocumentTabs, usually built from the app’s list of
documents with children_with. selection holds the value of the
chosen tab, and choosing another sets it. One is always chosen while
there are tabs, as on every platform: a value no tab has chooses the
first, and when the chosen tab goes, the one now in its place (the
last, if it was last); either sets selection.
The user closes tabs, moves them and asks for new ones where the app
lets them: on_close, on_reorder and on_new_tab each turn the
platform’s own way on (close buttons, dragging, a new-tab button). A
close only asks: the tab stays until the app takes its document away.
let docs = signal(vec![Doc::new(1, "notes.txt")]);
let current = signal(1);
DocumentTabs::new(current)
.children_with(move || docs.with(|d| d.iter().map(|d| DocumentTab::new(d.name.clone(), d.id)).collect::<Vec<_>>()))
.on_close(move |id| docs.update(|d| d.retain(|d| d.id != id)))
.on_new_tab(move || /* open one, and choose it */)Where the platform puts its tabs in the window’s chrome (macOS,
Windows), they take no room where they’re declared; see
tabs_style.
In view!: <DocumentTabs selection=current @close=… @new_tab=…>,
with <DocumentTab value=1>"notes.txt"</DocumentTab>s as children.
Implementations§
Source§impl<T: PartialEq + Clone + 'static> DocumentTabs<T>
impl<T: PartialEq + Clone + 'static> DocumentTabs<T>
pub fn new(selection: Signal<T>) -> DocumentTabs<T>
Sourcepub fn children(self, tabs: impl DocumentTabsChildren<T>) -> DocumentTabs<T>
pub fn children(self, tabs: impl DocumentTabsChildren<T>) -> DocumentTabs<T>
Its tabs, in order.
pub fn tab(self, tab: DocumentTab<T>) -> DocumentTabs<T>
Sourcepub fn children_with<E: DocumentTabsChildren<T>>(
self,
tabs: impl Fn() -> E + 'static,
) -> DocumentTabs<T>
pub fn children_with<E: DocumentTabsChildren<T>>( self, tabs: impl Fn() -> E + 'static, ) -> DocumentTabs<T>
Tabs built by tabs, and built again whenever what it reads changes
(the app’s documents), after any children.
Sourcepub fn on_close(self, close: impl Fn(T) + 'static) -> DocumentTabs<T>
pub fn on_close(self, close: impl Fn(T) + 'static) -> DocumentTabs<T>
Called with a tab’s value when the user asks to close it: its close button, a middle click, the platform’s own way. Gives the tabs close buttons. The tab stays until the app takes it away, so it can ask about unsaved changes first.
Sourcepub fn on_reorder(self, reorder: impl Fn(T, usize) + 'static) -> DocumentTabs<T>
pub fn on_reorder(self, reorder: impl Fn(T, usize) + 'static) -> DocumentTabs<T>
Called with a tab’s value and its new index when the user moves it (drags it, or moves it from the keyboard where the platform can). Lets the user move tabs. The tab already shows there: move the document in the app’s list too.
Sourcepub fn on_new_tab(self, new_tab: impl Fn() + 'static) -> DocumentTabs<T>
pub fn on_new_tab(self, new_tab: impl Fn() + 'static) -> DocumentTabs<T>
Called when the user asks for a new tab with the platform’s new-tab button, which this gives the tabs: open a document, and choose it.
Sourcepub fn tabs_style(
self,
style: impl IntoValue<DocumentTabsStyle>,
) -> DocumentTabs<T>
pub fn tabs_style( self, style: impl IntoValue<DocumentTabsStyle>, ) -> DocumentTabs<T>
Where it shows its tabs: the platform’s own place (the default), a
strip where it’s declared on every platform, the window’s own (the
title bar on macOS and Windows; GNOME and KDE have none, and show a
strip), or the title’s own row (Safari’s compact tabs on macOS, the
header bar’s title on GNOME; KDE shows a strip). In view!, after
selection.
Sourcepub fn native(self, tweak: Tweak<DocumentTabs<T>>) -> DocumentTabs<T>
pub fn native(self, tweak: Tweak<DocumentTabs<T>>) -> DocumentTabs<T>
Raw platform settings: see Tweak. Pinned tabs, tabs dragged out
to a window of their own, a tab’s width: each platform’s own.
Trait Implementations§
Source§impl<T: 'static> ElementBuilder for DocumentTabs<T>
impl<T: 'static> ElementBuilder for DocumentTabs<T>
fn element(&mut self) -> &mut Element
Source§fn style(self, f: impl FnOnce(&mut Style)) -> Self
fn style(self, f: impl FnOnce(&mut Style)) -> Self
Source§fn style_with(self, f: impl Fn(&mut Style) + 'static) -> Self
fn style_with(self, f: impl Fn(&mut Style) + 'static) -> Self
f re-runs whenever the
signals it reads change, and must set every field it cares about.fn width(self, value: impl IntoValue<Length>) -> Self
fn height(self, value: impl IntoValue<Length>) -> Self
fn min_width(self, value: impl IntoValue<Length>) -> Self
fn min_height(self, value: impl IntoValue<Length>) -> Self
fn max_width(self, value: impl IntoValue<Length>) -> Self
fn max_height(self, value: impl IntoValue<Length>) -> Self
fn aspect_ratio(self, value: impl IntoValue<f32>) -> Self
fn padding(self, value: impl IntoValue<Length>) -> Self
fn padding_x(self, value: impl IntoValue<Length>) -> Self
fn padding_y(self, value: impl IntoValue<Length>) -> Self
fn padding_start(self, value: impl IntoValue<Length>) -> Self
fn padding_end(self, value: impl IntoValue<Length>) -> Self
fn padding_top(self, value: impl IntoValue<Length>) -> Self
fn padding_bottom(self, value: impl IntoValue<Length>) -> Self
fn margin(self, value: impl IntoValue<Length>) -> Self
fn margin_x(self, value: impl IntoValue<Length>) -> Self
fn margin_y(self, value: impl IntoValue<Length>) -> Self
fn margin_start(self, value: impl IntoValue<Length>) -> Self
fn margin_end(self, value: impl IntoValue<Length>) -> Self
fn margin_top(self, value: impl IntoValue<Length>) -> Self
fn margin_bottom(self, value: impl IntoValue<Length>) -> Self
fn grow(self, value: impl IntoValue<f32>) -> Self
fn shrink(self, value: impl IntoValue<f32>) -> Self
fn basis(self, value: impl IntoValue<Length>) -> Self
fn align_self(self, value: impl IntoValue<Align>) -> Self
Source§fn justify_self(self, value: impl IntoValue<Align>) -> Self
fn justify_self(self, value: impl IntoValue<Align>) -> Self
Source§fn top(self, value: impl IntoValue<Length>) -> Self
fn top(self, value: impl IntoValue<Length>) -> Self
absolute()).fn bottom(self, value: impl IntoValue<Length>) -> Self
Source§fn start(self, value: impl IntoValue<Length>) -> Self
fn start(self, value: impl IntoValue<Length>) -> Self
fn end(self, value: impl IntoValue<Length>) -> Self
fn grid_column(self, value: impl IntoValue<GridPlacement>) -> Self
fn grid_row(self, value: impl IntoValue<GridPlacement>) -> Self
fn direction(self, value: impl IntoValue<TextDirection>) -> Self
display the node had.fn size( self, width: impl IntoValue<Length>, height: impl IntoValue<Length>, ) -> Self
Source§fn tooltip(self, text: impl IntoValue<String>) -> Self
fn tooltip(self, text: impl IntoValue<String>) -> Self
entries, and built again whenever what it
reads changes, as Menu::children_with builds its entries.entries each time the platform opens it,
for a menu that depends on what’s selected or under the pointer at
that moment: a table row’s menu acting on the selection. What it
reads is read then, not followed.