pub struct ContainerBuilder { /* private fields */ }Expand description
ContainerBuilder is used to create Container instances using the builder
pattern. This allows for a flexible and readable way to construct complex
containers by chaining method calls.
§Example
// Create a container with a header, two options, a separator, some text,
// and a selector.
let container: Container = ContainerBuilder::new()
.header(...)?
.option(...)?
.option(...)?
.separator_normal(...)
.text(...)?
.selector(...)?
.build();Implementations§
Source§impl ContainerBuilder
impl ContainerBuilder
Sourcepub fn header_expl(self, header: Header) -> Self
pub fn header_expl(self, header: Header) -> Self
Explicitly sets a Header component for the Container. Unlike the header
method, which takes a label and internally constructs a Header, this
method allows you to directly provide a preconstructed Header component.
§Parameters
header: AHeadercomponent.
§Returns
ContainerBuilder: Returnsself.
§Example
// Create a `Header` component.
let header = Header::new(...)?;
// Set a preconstructed `Header` component.
ContainerBuilder::new()
.header_expl(header);Sourcepub fn header(self, label: &str) -> FtuiResult<Self>
pub fn header(self, label: &str) -> FtuiResult<Self>
Sets a Header component for the Container.
§Parameters
label: A&strrepresenting the text to display in the header.
§Returns
Ok(ContainerBuilder): Returnsself.Err(FtuiError): Returns an error.
§Example
// Sets a `Header` component with the label "Welcome".
ContainerBuilder::new()
.header("Welcome")?;Sourcepub fn option_expl(self, option: Option) -> Self
pub fn option_expl(self, option: Option) -> Self
Explicitly add an Option component to the Container. Unlike the option
method, which takes a label and an optional callback to internally constructs
an Option, this method allows you to directly provide a preconstructed
Option component.
§Parameters
option: AnOptioncomponent.
§Returns
ContainerBuilder: Returnsself.
§Example
// Create an `Option` component.
let option = Option::new(...)?;
// Set a preconstructed `Option` component.
ContainerBuilder::new()
.option_expl(option);Sourcepub fn option(
self,
label: &str,
callback: impl Into<Option<Callback>>,
) -> FtuiResult<Self>
pub fn option( self, label: &str, callback: impl Into<Option<Callback>>, ) -> FtuiResult<Self>
Adds an Option component to the Container.
§Parameters
label: A&strrepresenting the text displayed for this option.callback: An optionalCallbackinvoked when the option is selected.
§Returns
Ok(ContainerBuilder): Returnsself.Err(FtuiError): Returns an error.
§Example
// Add an `Option` component with the label "Option" and no `Callback`.
ContainerBuilder::new()
.option("Option", None)?;Sourcepub fn option_id_expl(self, option: Option, store_id: &mut u16) -> Self
pub fn option_id_expl(self, option: Option, store_id: &mut u16) -> Self
Explicitly add an Option component to the Container and stores its ID.
Unlike the option_id method, which takes a label and an optional callback
to internally constructs an Option, this method allows you to directly
provide a preconstructed Option component.
§Parameters
option: AnOptioncomponent.store_id: A&mut u16to store the createdOptioncomponent ID.
§Returns
Ok(ContainerBuilder): Returnsself.Err(FtuiError): Returns an error.
§Example
let mut id = 0u16;
// Create an `Option` component.
let option = Option::new(...)?;
// Add the create `Option` component and storing the generated ID in `id`.
ContainerBuilder::new()
.option_id(option, &mut id)?;Sourcepub fn option_id(
self,
label: &str,
callback: impl Into<Option<Callback>>,
store_id: &mut u16,
) -> FtuiResult<Self>
pub fn option_id( self, label: &str, callback: impl Into<Option<Callback>>, store_id: &mut u16, ) -> FtuiResult<Self>
Adds an Option component to the Container and stores its ID.
§Parameters
label: The text displayed for this option.callback: An optionalCallbackinvoked when the option is selected.store_id: A&mut u16to store the createdOptioncomponent ID.
§Returns
Ok(ContainerBuilder): Returnsself.Err(FtuiError): Returns an error.
§Example
let mut id = 0u16;
// Add an `Option` labeled "Option" with no `Callback`,
// storing the generated ID in `id`.
ContainerBuilder::new()
.option_id("Option", None, &mut id)?;Sourcepub fn text_expl(self, text: Text) -> Self
pub fn text_expl(self, text: Text) -> Self
Explicitly add a Text component to the Container. Unlike the text
method, which takes a label and flags to internally constructs an Text,
this method allows you to directly provide a preconstructed Text component.
§Parameters
text: ATextcomponent.
§Returns
ContainerBuilder: Returnsself.
§Example
// Create an `Text` component.
let text = Text::new(...)?;
// Set a preconstructed `Text` component.
ContainerBuilder::new()
.text_expl(text);Sourcepub fn text(
self,
label: &str,
flags: impl Into<Option<TextFlags>>,
) -> FtuiResult<Self>
pub fn text( self, label: &str, flags: impl Into<Option<TextFlags>>, ) -> FtuiResult<Self>
Adds a Text component to the Container.
§Parameters
label: A&strrepresenting the text to display.flags: A set ofTextFlags, combined using the bitwise OR operator.
§Notes
- This is what bitwise OR operator look like ->
flag1 | flag2 | flag3 ...
§Returns
Ok(ContainerBuilder): Returnsself.Err(FtuiError): Returns an error.
§Example
// Create a `Text` component labeled "Text", right-aligned and with
// a magenta background.
ContainerBuilder::new()
.text("Text", TextFlags::ALIGN_RIGHT | TextFlags::COLOR_MAGENTA_BACK)?;Sourcepub fn text_id_expl(self, text: Text, store_id: &mut u16) -> Self
pub fn text_id_expl(self, text: Text, store_id: &mut u16) -> Self
Explicitly add a Text component to the Container and stores its ID.
Unlike the text_id method, which takes a label and flags to internally
constructs an Text, this method allows you to directly provide a
preconstructed Text component.
§Parameters
text: AnTextcomponent.store_id: A&mut u16to store the createdOptioncomponent ID.
§Returns
ContainerBuilder: Returnsself.
§Example
let mut id = 0u16;
// Create an `Text` component.
let text = Text::new(...)?;
// Add the create `Text` component and storing the generated ID in `id`.
ContainerBuilder::new()
.text_id_expl(text, &mut id)?;Sourcepub fn text_id(
self,
label: &str,
flags: impl Into<Option<TextFlags>>,
store_id: &mut u16,
) -> FtuiResult<Self>
pub fn text_id( self, label: &str, flags: impl Into<Option<TextFlags>>, store_id: &mut u16, ) -> FtuiResult<Self>
Adds a Text component to the Container and stores its ID.
§Parameters
label: A&strrepresenting the text to display.flags: A set ofTextFlags, combined using the bitwise OR operator.store_id: A&mut u16to store the createdTextcomponent ID.
§Notes
- This is what bitwise OR operator look like ->
flag1 | flag2 | flag3 ...
§Returns
Ok(ContainerBuilder): Returnsself.Err(FtuiError): Returns an error.
§Example
let mut id = 0u16;
// Create a `Text` component labeled "Text", right-aligned and with
// a magenta background. storing the generated ID in `id`.
ContainerBuilder::new()
.text(
"Text",
TextFlags::ALIGN_RIGHT | TextFlags::COLOR_MAGENTA_BACK, &mut id)?;Sourcepub fn separator_normal_expl(self, separator: Separator) -> Self
pub fn separator_normal_expl(self, separator: Separator) -> Self
Explicitly add a normal Separator component to the Container.
Unlike the Separator method, which takes a style and internally
constructs a Separator, this method allows you to directly provide a
preconstructed Separator component.
§Parameters
separator: ASeparatorcomponent.
§Returns
ContainerBuilder: Returnsself.
§Example
// Create a normal `Separator` component.
let separator = Separator::normal(...)?;
// Set a preconstructed `Header` component.
ContainerBuilder::new()
.separator_normal_expl(separator);Sourcepub fn separator_normal(self, style: SeparatorStyle) -> Self
pub fn separator_normal(self, style: SeparatorStyle) -> Self
Add a standard (non-dotted) Separator with the given style.
§Parameters
style: The visual style of the separator, specified as aSeparatorStyle.
§Returns
ContainerBuilder: Returnsself.
§Example
// Add a normal separator with a solid style.
ContainerBuilder::new()
separator_normal(SeparatorStyle::Solid);Sourcepub fn separator_dotted_expl(self, separator: Separator) -> Self
pub fn separator_dotted_expl(self, separator: Separator) -> Self
Explicitly add a dotted Separator component to the Container.
Unlike the Separator method, which takes a style and internally
constructs a Separator, this method allows you to directly provide a
preconstructed Separator component.
§Parameters
separator: ASeparatorcomponent.
§Returns
ContainerBuilder: Returnsself.
§Example
// Create a dotted `Separator` component.
let separator = Separator::dotted(...)?;
// Set a preconstructed `Header` component.
ContainerBuilder::new()
.separator_dotted_expl(separator);Sourcepub fn separator_dotted(self, style: SeparatorStyle) -> Self
pub fn separator_dotted(self, style: SeparatorStyle) -> Self
Sourcepub fn selector_expl(self, selector: Selector) -> Self
pub fn selector_expl(self, selector: Selector) -> Self
Explicitly sets a Selector component for the Container. Unlike the selector
method, which takes triggers and internally constructs a selector, this
method allows you to directly provide a preconstructed Selector component.
§Parameters
selector: ASelectorcomponent.
§Returns
ContainerBuilder: Returnsself.
§Example
// Create a `Header` component.
let selector = Selector::new(...)?;
// Set a preconstructed `Selector` component.
ContainerBuilder::new()
.selector_expl(selector);Sourcepub fn selector(
self,
up_trig: Trigger,
down_trig: Trigger,
selc_trig: Trigger,
) -> Self
pub fn selector( self, up_trig: Trigger, down_trig: Trigger, selc_trig: Trigger, ) -> Self
Set a Selector for the Container to handle user navigation.
§Parameters
up_trig: ATriggerthat moves the selector up when activated.down_trig: ATriggerthat moves the selector down when activated.selc_trig: ATriggerthat confirms the selection when activated.
§Returns
ContainerBuilder: Returnsself.
§Example
// A `Trigger` that always activate.
tui::trg_new_trigger_func!(always_true_trigger, _arg, {
Ok(true)
});
// A `Trigger` that never activate .
tui::trg_new_trigger_func!(always_false_trigger, _arg, {
Ok(false)
});
// Set a `Selector` that always moves down.
ContainerBuilder::new()
.selector(
Trigger::no_arg(always_false_trigger),
Trigger::no_arg(always_true_trigger),
Trigger::no_arg(always_false_trigger),
);Sourcepub fn selector_no_triggers(self) -> Self
pub fn selector_no_triggers(self) -> Self
Sets a Selector with no Triggers for the Container.
In this case, navigation must be handled manually using the following methods:
Container::selector_upContainer::selector_downContainer::selector_select
§Returns
ContainerBuilder: Returnsself.
§Example
// Set a `Selector` with no `Trigger`s.
ContainerBuilder::new()
.selector_no_triggers();Sourcepub fn build(self) -> Container
pub fn build(self) -> Container
Finalizes the construction of a Container. This method should be called
after all desired components have been added using the builder pattern.
It consumes self and returns the completed Container.
§Returns
Container: Returns the createdContainer.
§Example
let container: Container = ContainerBuilder::new()
.header(...)?
.option(...)?
.option(...)?
.separator_normal(...)
.text(...)?
.selector(...)?
.build(); // Finalize and retrieve the constructed container.