Skip to main content

Text

Struct Text 

Source
pub struct Text<'a> { /* private fields */ }
Expand description

A single line of text in one Style, clipped (not wrapped) to area.width() columns. Only the first row of area is used.

The plain-content cousin of PrintLine (which prints a multi-span Line, for mixed styling within one line) and Paragraph (which word-wraps across multiple lines): reach for Text for a single already-one-line label or readout in a single style, with no wrapping and no per-span styling. style defaults to Style::new() and align to Align::Left; set them with Text::style/Text::align.

Unlike super::BoxBorder, super::Gauge, super::StatBar, super::Table, and super::Button, Text has no theme()/ theme_on() pair: a line of plain text has no single semantic Theme role to map onto, so callers set style directly.

§Examples

use retroglyph_core::grid::{Grid, Rect};
use retroglyph_ui::{Align, Surface, Text, Widget};

let area = Rect::new(0, 0, 10, 1);
let mut grid = Grid::new(10, 1);
Text::new("OK")
    .align(Align::Right)
    .render(&mut Surface::new(&mut grid, area, 0));

Implementations§

Source§

impl<'a> Text<'a>

Source

pub fn new(content: &'a str) -> Self

A line of content in the default style, left-aligned.

Source

pub const fn style(self, style: Style) -> Self

Set the text’s style.

Source

pub const fn align(self, align: Align) -> Self

Set how the line is aligned within area.width() columns.

Trait Implementations§

Source§

impl<'a> Clone for Text<'a>

Source§

fn clone(&self) -> Text<'a>

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<'a> Debug for Text<'a>

Source§

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

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

impl Widget for Text<'_>

Source§

fn render(&self, surface: &mut Surface<'_>)

Draw this widget into surface, filling surface.area(). Read more
Source§

impl<'a> Copy for Text<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Text<'a>

§

impl<'a> RefUnwindSafe for Text<'a>

§

impl<'a> Send for Text<'a>

§

impl<'a> Sync for Text<'a>

§

impl<'a> Unpin for Text<'a>

§

impl<'a> UnsafeUnpin for Text<'a>

§

impl<'a> UnwindSafe for Text<'a>

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.
§

impl<C> WithAlpha for C
where C: Copy,

§

fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>

Wraps self with alpha, storing alpha before the color in memory (see [AlphaFirst]).
§

fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>

Wraps self with alpha, storing alpha after the color in memory (see [AlphaLast]).