Skip to main content

Text

Struct Text 

Source
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

Source

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 &str representing the text content.
  • flags: A set of TextFlags combined using the bitwise OR operator.
§Notes

The bitwise OR operator combines flags like this: flag1 | flag2 | flag3

§Returns
  • Ok(Text): Returns a Text instance
  • Err(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)?;
Source

pub fn label(&self) -> &String

Source

pub fn set_label(&mut self, label: impl Into<String>)

Updates the label of the Text component.

§Parameters
  • label: The new label.
§Example
// Create a `Text` component with the label "Text" and no flags.
let mut text = Text::new("Text", None)?;

// Update the label to "New Label".
text.set_label("New Label");

Trait Implementations§

Source§

impl Clone for Text

Source§

fn clone(&self) -> Text

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 Text

Source§

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

Formats the value using the given formatter. Read more
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.

§Notes

  • Only the label and flags are considered when comparing Text instances.

§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)
Source§

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

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

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

Inequality operator !=. Read more

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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.