pub struct Text { /* private fields */ }Expand description
A UI component representing a text element in a Container. Text components
are displayed in the order they are added to the Container. They can be
customized using TextFlags to adjust alignment, color, and other styling options.
§Usage
The Text component is used within a Container to display static text elements.
§Derives
Debug, Clone, PartialEq
§PartialEq Implementation
Only the label and flags are considered when comparing Text instances.
Implementations§
Source§impl Text
impl Text
Sourcepub fn new(label: &str, flags: impl Into<Option<TextFlags>>) -> FtuiResult<Self>
pub fn new(label: &str, flags: impl Into<Option<TextFlags>>) -> FtuiResult<Self>
Creates a new Text component with the specified label and flags.
§Parameters
label: A&strrepresenting the text content.flags: A set ofTextFlagscombined using the bitwise OR operator.
§Notes
The bitwise OR operator combines flags like this: flag1 | flag2 | flag3
§Returns
Ok(Text): Returns aTextinstanceErr(FtuiError): Returns an error.
§Example
// Create a `Text` component labeled "Text".
// The text is right-aligned.
// The background color is red.
let _ = Text::new(
"Text", TextFlags::ALIGN_RIGHT | TextFlags::COLOR_RED_BACK)?;pub fn label(&self) -> &String
Trait Implementations§
Source§impl PartialEq for Text
Implementation of the PartialEq trait for the Text struct. This implementation
defines equality based on two fields: label and flags.
impl PartialEq for Text
Implementation of the PartialEq trait for the Text struct. This implementation
defines equality based on two fields: label and flags.
§Notes
- Only the
labelandflagsare considered when comparingTextinstances.
§Example
use feather_tui as tui;
// Create two `Text` instances with identical `label` and `flags`
let text1 = tui::cpn::Text::new("Text", tui::cpn::TextFlags::NONE);
let text2 = tui::cpn::Text::new("Text", tui::cpn::TextFlags::NONE);
// Assert that both `text1` and `text2` are equal, since they have the same `label` and `flags`
assert_eq!(text1, text2); // This will evaluate to true
// Create a new `Text` instance with a different flag (ALIGN_RIGHT)
let text3 = tui::cpn::Text::new("Text", tui::cpn::TextFlags::ALIGN_RIGHT);
// Assert that `text1` and `text3` are not equal, since their `flags` are different
assert_ne!(text1, text3); // This will evaluate to true (text1 != text3)
// Create a new `Text` instance with a different `label`
let text4 = tui::cpn::Text::new("Hello", tui::cpn::TextFlags::ALIGN_RIGHT);
// Assert that `text3` and `text4` are not equal, since their `label` is different
assert_ne!(text3, text4); // This will evaluate to true (text3 != text4)Auto Trait Implementations§
impl Freeze for Text
impl RefUnwindSafe for Text
impl Send for Text
impl Sync for Text
impl Unpin for Text
impl UnsafeUnpin for Text
impl UnwindSafe for Text
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more