Skip to main content

TabContent

Trait TabContent 

Source
pub trait TabContent: 'static {
    // Required methods
    fn render(
        &self,
        focused: bool,
        window: &mut Window,
        cx: &mut App,
    ) -> AnyElement;
    fn title(&self) -> SharedString;

    // Provided methods
    fn on_focus_in(&mut self, _cx: &mut App) { ... }
    fn on_focus_out(&mut self, _cx: &mut App) { ... }
    fn on_resize(&mut self, _bounds: Bounds<Pixels>, _cx: &mut App) { ... }
    fn on_close(&mut self, _cx: &mut App) { ... }
}
Expand description

Content rendered inside a single tab of a Pane.

Object-safe by design (no generics, no Self return type) so Pane can hold a heterogeneous Vec<Box<dyn TabContent>>.

§Example

struct FileTab { path: SharedString }
impl TabContent for FileTab {
    fn render(&self, _focused: bool, _window: &mut Window, _cx: &mut App) -> AnyElement {
        div().child(self.path.clone()).into_any_element()
    }
    fn title(&self) -> SharedString { self.path.clone() }
}

Required Methods§

Source

fn render(&self, focused: bool, window: &mut Window, cx: &mut App) -> AnyElement

Renders this tab’s body. focused is true when this tab is the active tab of a Pane that is itself PaneGroup’s active pane.

Source

fn title(&self) -> SharedString

The label shown on the tab strip.

Provided Methods§

Source

fn on_focus_in(&mut self, _cx: &mut App)

Fired when this tab becomes the active tab of a focused Pane: activation (Pane::activate), being added (Pane::add_tab), inheriting focus after the active tab is closed, or its pane regaining focus (Pane::set_focused). A terminal implementor would e.g. resume cursor blink / mark the PTY focused. Default: no-op, so existing implementors need no changes.

NOT fired for a pane’s initial tab seeded via Pane::with_tab (that builder runs before a Context exists, so no hook can fire) — an implementor needing initial-focus state should set it at construction or have the mounting code trigger focus explicitly after mount.

Takes &mut App (not &mut Window) because most fire sites (activate/add_tab/set_focused) run from a Context-only path with no Window in scope; focus-driven tab behaviour (blink toggle, PTY focus flag) needs no window geometry.

Source

fn on_focus_out(&mut self, _cx: &mut App)

Fired when this tab stops being the active tab of a focused Pane (another tab activated, or its pane losing focus). A terminal implementor would e.g. pause cursor blink. Default: no-op.

Source

fn on_resize(&mut self, _bounds: Bounds<Pixels>, _cx: &mut App)

Fired when the pane’s tab-content area changes size (measured via a canvas() in Pane’s render, one frame after the layout change). A terminal implementor would recompute rows/cols and resize its PTY (SIGWINCH). Default: no-op.

Source

fn on_close(&mut self, _cx: &mut App)

Fired exactly once, right before this tab is removed — whether via closing the single tab or via its whole pane being removed from the tree (Pane::close_all_tabs). A terminal implementor MUST shut its PTY down here: Drop timing is not guaranteed to coincide with tree removal (other live Entity handles can outlive it), so relying on Drop would leak the child process. Default: no-op.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§