Trait druid::widget::TabsPolicy

source ·
pub trait TabsPolicy: Data {
    type Key: Hash + Eq + Clone;
    type Input: Data;
    type BodyWidget: Widget<Self::Input>;
    type LabelWidget: Widget<Self::Input>;
    type Build;

    // Required methods
    fn tabs_changed(&self, old_data: &Self::Input, data: &Self::Input) -> bool;
    fn tabs(&self, data: &Self::Input) -> Vec<Self::Key> ;
    fn tab_info(&self, key: Self::Key, data: &Self::Input) -> TabInfo<Self::Input>;
    fn tab_body(&self, key: Self::Key, data: &Self::Input) -> Self::BodyWidget;
    fn tab_label(
        &self,
        key: Self::Key,
        info: TabInfo<Self::Input>,
        data: &Self::Input
    ) -> Self::LabelWidget;

    // Provided methods
    fn close_tab(&self, key: Self::Key, data: &mut Self::Input) { ... }
    fn build(build: Self::Build) -> Self { ... }
    fn default_make_label(info: TabInfo<Self::Input>) -> Label<Self::Input> { ... }
}
Expand description

A policy that determines how a Tabs instance derives its tabs from its app data.

Required Associated Types§

source

type Key: Hash + Eq + Clone

The identity of a tab.

source

type Input: Data

The input data that will: a) be used to determine the tabs present b) be the input data for all of the child widgets.

source

type BodyWidget: Widget<Self::Input>

The common type for all body widgets in this set of tabs. A flexible default is Box<dyn WidgetSelf::Input>

source

type LabelWidget: Widget<Self::Input>

The common type for all label widgets in this set of tabs Usually this would be LabelSelf::Input

source

type Build

The information required to build up this policy. This is to support policies where at least some tabs are provided up front during widget construction. If the Build type implements the AddTab trait, the add_tab and with_tab methods will be available on the Tabs instance to allow the It can be filled in with () by implementations that do not require it.

Required Methods§

source

fn tabs_changed(&self, old_data: &Self::Input, data: &Self::Input) -> bool

Examining the input data, has the set of tabs present changed? Expected to be cheap, eg pointer or numeric comparison.

source

fn tabs(&self, data: &Self::Input) -> Vec<Self::Key>

From the input data, return the new set of tabs

source

fn tab_info(&self, key: Self::Key, data: &Self::Input) -> TabInfo<Self::Input>

For this tab key, return the relevant tab information that will drive label construction

source

fn tab_body(&self, key: Self::Key, data: &Self::Input) -> Self::BodyWidget

For this tab key, return the body widget

source

fn tab_label( &self, key: Self::Key, info: TabInfo<Self::Input>, data: &Self::Input ) -> Self::LabelWidget

Label widget for the tab. Usually implemented with a call to default_make_label ( can’t default here because Self::LabelWidget isn’t determined)

Provided Methods§

source

fn close_tab(&self, key: Self::Key, data: &mut Self::Input)

Change the data to reflect the user requesting to close a tab.

source

fn build(build: Self::Build) -> Self

Construct an instance of this TabsFromData from its Build type. The main use case for this is StaticTabs, where the tabs are provided by the app developer up front.

source

fn default_make_label(info: TabInfo<Self::Input>) -> Label<Self::Input>

A default implementation for make label, if you do not wish to construct a custom widget.

Examples found in repository?
examples/tabs.rs (line 204)
198
199
200
201
202
203
204
205
    fn tab_label(
        &self,
        _key: Self::Key,
        info: TabInfo<Self::Input>,
        _data: &Self::Input,
    ) -> Self::LabelWidget {
        Self::default_make_label(info)
    }

Implementors§