Skip to main content

DocumentTabs

Struct DocumentTabs 

Source
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>

Source

pub fn new(selection: Signal<T>) -> DocumentTabs<T>

Source

pub fn children(self, tabs: impl DocumentTabsChildren<T>) -> DocumentTabs<T>

Its tabs, in order.

Source

pub fn tab(self, tab: DocumentTab<T>) -> DocumentTabs<T>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source§

fn element(&mut self) -> &mut Element

Source§

fn style(self, f: impl FnOnce(&mut Style)) -> Self

Escape hatch: edit the style directly (static).
Source§

fn style_with(self, f: impl Fn(&mut Style) + 'static) -> Self

Escape hatch: edit the style reactively. f re-runs whenever the signals it reads change, and must set every field it cares about.
Source§

fn width(self, value: impl IntoValue<Length>) -> Self

Source§

fn height(self, value: impl IntoValue<Length>) -> Self

Source§

fn min_width(self, value: impl IntoValue<Length>) -> Self

Source§

fn min_height(self, value: impl IntoValue<Length>) -> Self

Source§

fn max_width(self, value: impl IntoValue<Length>) -> Self

Source§

fn max_height(self, value: impl IntoValue<Length>) -> Self

Source§

fn aspect_ratio(self, value: impl IntoValue<f32>) -> Self

Source§

fn padding(self, value: impl IntoValue<Length>) -> Self

Source§

fn padding_x(self, value: impl IntoValue<Length>) -> Self

Source§

fn padding_y(self, value: impl IntoValue<Length>) -> Self

Source§

fn padding_start(self, value: impl IntoValue<Length>) -> Self

Source§

fn padding_end(self, value: impl IntoValue<Length>) -> Self

Source§

fn padding_top(self, value: impl IntoValue<Length>) -> Self

Source§

fn padding_bottom(self, value: impl IntoValue<Length>) -> Self

Source§

fn margin(self, value: impl IntoValue<Length>) -> Self

Source§

fn margin_x(self, value: impl IntoValue<Length>) -> Self

Source§

fn margin_y(self, value: impl IntoValue<Length>) -> Self

Source§

fn margin_start(self, value: impl IntoValue<Length>) -> Self

Source§

fn margin_end(self, value: impl IntoValue<Length>) -> Self

Source§

fn margin_top(self, value: impl IntoValue<Length>) -> Self

Source§

fn margin_bottom(self, value: impl IntoValue<Length>) -> Self

Source§

fn grow(self, value: impl IntoValue<f32>) -> Self

Source§

fn shrink(self, value: impl IntoValue<f32>) -> Self

Source§

fn basis(self, value: impl IntoValue<Length>) -> Self

Source§

fn align_self(self, value: impl IntoValue<Align>) -> Self

Source§

fn justify_self(self, value: impl IntoValue<Align>) -> Self

Alignment inside a grid cell along the inline axis.
Source§

fn top(self, value: impl IntoValue<Length>) -> Self

Inset from the top of the containing block (with absolute()).
Source§

fn bottom(self, value: impl IntoValue<Length>) -> Self

Source§

fn start(self, value: impl IntoValue<Length>) -> Self

Inset from the inline start (left in LTR, right in RTL).
Source§

fn end(self, value: impl IntoValue<Length>) -> Self

Source§

fn grid_column(self, value: impl IntoValue<GridPlacement>) -> Self

Source§

fn grid_row(self, value: impl IntoValue<GridPlacement>) -> Self

Source§

fn direction(self, value: impl IntoValue<TextDirection>) -> Self

Source§

fn hidden(self, value: impl IntoValue<bool>) -> Self

Not laid out, not visible, not focusable, not in the a11y tree. Un-hiding restores whatever display the node had.
Source§

fn size( self, width: impl IntoValue<Length>, height: impl IntoValue<Length>, ) -> Self

Source§

fn absolute(self) -> Self

Takes the node out of flow; position it with top/start/….
Source§

fn tooltip(self, text: impl IntoValue<String>) -> Self

A tooltip: text the platform shows, its own way, when the pointer rests on the widget, and assistive technology reads as its description. Empty: none.
Source§

fn context_menu(self, entries: impl MenuEntries) -> Self

A context menu: the platform shows it its own way, on a right-click, a long press or the menu key, and over children without one of their own. Takes items, separators and submenus, as a Menu does, with the same reactive titles, states and check marks: Read more
Source§

fn context_menu_with<E>(self, entries: impl Fn() -> E + 'static) -> Self
where E: MenuEntries,

A context menu built by entries, and built again whenever what it reads changes, as Menu::children_with builds its entries.
Source§

fn context_menu_on_open<E>(self, entries: impl Fn() -> E + 'static) -> Self
where E: MenuEntries,

A context menu built by 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.
Source§

fn a11y_label(self, label: impl IntoValue<String>) -> Self

Source§

fn a11y_description(self, description: impl IntoValue<String>) -> Self

Source§

fn a11y_role(self, role: Role) -> Self

Source§

fn a11y_hidden(self) -> Self

Source§

fn on_focus(self, handler: impl Fn() + 'static) -> Self

Called when this control gains keyboard focus.
Source§

fn on_blur(self, handler: impl Fn() + 'static) -> Self

Called when this control loses keyboard focus.
Source§

fn tab_index(self, index: u32) -> Self

Moves this control ahead in the Tab order. Controls with a tab index come first (lowest first); the rest follow in reading order. Prefer arranging the tree in the order users should visit it.
Source§

fn node_ref(self, node: NodeRef) -> Self

Points node at this widget’s node, for use_size and to focus it from code (NodeRef::focus).
Source§

fn test_id(self, id: impl Into<String>) -> Self

Last-resort handle for tests; prefer finding nodes by role and name.
Source§

impl<T: PartialEq + Clone + 'static> View for DocumentTabs<T>

Source§

fn build(self, ui: &Ui) -> NodeId

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for DocumentTabs<T>

§

impl<T> !Send for DocumentTabs<T>

§

impl<T> !Sync for DocumentTabs<T>

§

impl<T> !UnwindSafe for DocumentTabs<T>

§

impl<T> Forget for DocumentTabs<T>

§

impl<T> Freeze for DocumentTabs<T>
where Signal<T>: Freeze, Vec<DocumentTab<T>>: Freeze, Option<Box<dyn Fn() -> Vec<DocumentTab<T>>>>: Freeze, Option<Rc<dyn Fn(T)>>: Freeze, Option<Rc<dyn Fn(T, usize)>>: Freeze,

§

impl<T> Unpin for DocumentTabs<T>
where Signal<T>: Unpin, Vec<DocumentTab<T>>: Unpin, Option<Box<dyn Fn() -> Vec<DocumentTab<T>>>>: Unpin, Option<Rc<dyn Fn(T)>>: Unpin, Option<Rc<dyn Fn(T, usize)>>: Unpin,

§

impl<T> UnsafeUnpin for DocumentTabs<T>

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<V> Children for V
where V: View,

Source§

fn into_views(self, out: &mut Vec<AnyView>)

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.