Skip to main content

TabBarLayout

Struct TabBarLayout 

Source
pub struct TabBarLayout {
    pub bar_width: f32,
    pub bar_height: f32,
    pub visible_tabs: Vec<VisibleTab>,
    pub visible_segments: Vec<VisibleSegment>,
    pub scroll_left: Option<Rect>,
    pub scroll_right: Option<Rect>,
    pub hit_regions: Vec<(Rect, TabBarHit)>,
    pub resolved_scroll_offset: usize,
}
Expand description

Fully-resolved tab-bar layout. Backends iterate visible_tabs / visible_segments for painting; call Self::hit_test for clicks.

§Writing resolved_scroll_offset back

When a frame paints with a stale TabBar.scroll_offset (e.g. after a window resize or a jump to a tab that wasn’t previously visible), the layout corrects it. The backend should write resolved_scroll_offset back to the app’s stored scroll state so the next frame starts coherent. See TabBar::layout docs for the two-pass-paint pattern.

Fields§

§bar_width: f32

Total bar width in the measurer’s unit (copied from input).

§bar_height: f32

Total bar height in the measurer’s unit (copied from input).

§visible_tabs: Vec<VisibleTab>

Tabs that made it onto the bar, left-to-right as drawn.

§visible_segments: Vec<VisibleSegment>

Right-aligned segments that fit, drawn left-to-right starting from their resolved left edge.

§scroll_left: Option<Rect>

Left scroll-arrow rectangle, present iff resolved_scroll_offset > 0 and scroll_arrow_width > 0.0.

§scroll_right: Option<Rect>

Right scroll-arrow rectangle, present iff tabs extend beyond the visible area and scroll_arrow_width > 0.0.

§hit_regions: Vec<(Rect, TabBarHit)>

Ordered hit-region list. hit_test walks this from the start and returns the first containing region. More-specific regions (close buttons) come before containing regions (tab bodies).

§resolved_scroll_offset: usize

Scroll offset actually used. May differ from TabBar.scroll_offset if the input was stale.

Implementations§

Source§

impl TabBarLayout

Source

pub fn hit_test(&self, x: f32, y: f32) -> TabBarHit

Test which clickable region (if any) contains point (x, y). Returns TabBarHit::Empty when no region matches.

Source

pub fn tab_center(&self, tab_idx: usize) -> Option<(f32, f32)>

Center point of tab tab_idx’s full bounds (label + close button), in this layout’s own bar-relative coordinate space — the same space visible_tabs[].bounds uses (origin at the bar’s top-left, not the target surface). None if tab_idx isn’t in visible_tabs, i.e. it’s scrolled out of view behind the bar’s scroll_offset.

Backends that cache a TabBarLayout per WidgetId at paint time add the cached bar rect’s own (x, y) origin to this to get an absolute screen point — see TuiDriver::tab_center / GtkDriver::tab_center, which every tab bar needs since every tab paints the same label-independent chrome and find() can’t disambiguate tab 3’s target from tab 0’s the way it can for uniquely-labeled text.

Source

pub fn tab_close_center(&self, tab_idx: usize) -> Option<(f32, f32)>

Center point of tab tab_idx’s close-button hit region, in the same bar-relative space as Self::tab_center. None when the tab is scrolled out of view (see Self::tab_center) or when it drew no close button this frame — is_closable: false on the tab, or show_tab_close: false on the bar.

Trait Implementations§

Source§

impl Clone for TabBarLayout

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TabBarLayout

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TabBarLayout

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TabBarLayout

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more