Enum embedded_text::style::HeightMode[][src]

pub enum HeightMode {
    Exact(VerticalOverdraw),
    FitToText,
    ShrinkToText(VerticalOverdraw),
}
Expand description

Specifies how the TextBox’s height should be adjusted.

Variants

Keep the original TextBox height.

Example: default mode is Exact(FullRowsOnly)

use embedded_graphics::primitives::Rectangle;
use embedded_text::TextBox;

// The default option is Exact, which does not change the size of the TextBox.
let bounding_box = Rectangle::new(Point::zero(), Size::new(60, 60));
let text_box = TextBox::new(
    "Two lines\nof text",
    bounding_box,
    character_style,
);

assert_eq!(text_box.bounding_box().size, Size::new(60, 60));

Example: display everything inside the bounding box.

use embedded_graphics::primitives::Rectangle;
use embedded_text::{TextBox, style::{HeightMode, VerticalOverdraw}};

// `HeightMode::Exact(VerticalOverdraw::Hidden)` will display everything inside the text
// box, not just completely visible rows.
let bounding_box = Rectangle::new(Point::zero(), Size::new(60, 10));
let text_box = TextBox::with_height_mode(
    "Two lines\nof text",
    bounding_box,
    character_style,
    HeightMode::Exact(VerticalOverdraw::Hidden),
);

assert_eq!(text_box.bounding_box().size, Size::new(60, 10));

Tuple Fields of Exact

0: VerticalOverdraw
FitToText

Sets the height of the TextBox to exactly fit the text.

Note: in this mode, vertical alignment is meaningless. Make sure to use Top alignment for efficiency.

Example: FitToText shrinks the TextBox.

use embedded_graphics::primitives::Rectangle;
use embedded_text::{TextBox, style::HeightMode};

// FitToText shrinks the TextBox to the height of the text
let bounding_box = Rectangle::new(Point::zero(), Size::new(60, 60));
let text_box = TextBox::with_height_mode(
    "Two lines\nof text",
    bounding_box,
    character_style,
    HeightMode::FitToText,
);

assert_eq!(text_box.bounding_box().size, Size::new(60, 18));

Example: FitToText grows the TextBox.

use embedded_graphics::primitives::Rectangle;
use embedded_text::{TextBox, style::HeightMode};

// FitToText grows the TextBox to the height of the text
let bounding_box = Rectangle::new(Point::zero(), Size::new(60, 0));
let text_box = TextBox::with_height_mode(
    "Two lines\nof text",
    bounding_box,
    character_style,
    HeightMode::FitToText,
);

assert_eq!(text_box.bounding_box().size, Size::new(60, 18));
ShrinkToText(VerticalOverdraw)

If the text does not fill the bounding box, shrink the TextBox to be as tall as the text.

Example: ShrinkToText does not grow the TextBox.

use embedded_graphics::primitives::Rectangle;
use embedded_text::{TextBox, style::{HeightMode, VerticalOverdraw}};

// This TextBox contains two lines of text, but is 0px high
let bounding_box = Rectangle::new(Point::zero(), Size::new(60, 0));
let text_box = TextBox::with_height_mode(
    "Two lines\nof text",
    bounding_box,
    character_style,
    HeightMode::ShrinkToText(VerticalOverdraw::FullRowsOnly),
);

assert_eq!(text_box.bounding_box().size, Size::new(60, 0));

Example: ShrinkToText shrinks the TextBox.

use embedded_graphics::primitives::Rectangle;
use embedded_text::{TextBox, style::{HeightMode, VerticalOverdraw}};

// This TextBox contains two lines of text, but is 60px high
let bounding_box = Rectangle::new(Point::zero(), Size::new(60, 60));
let text_box = TextBox::with_height_mode(
    "Two lines\nof text",
    bounding_box,
    character_style,
    HeightMode::ShrinkToText(VerticalOverdraw::Hidden),
);

assert_eq!(text_box.bounding_box().size, Size::new(60, 18));

Tuple Fields of ShrinkToText

0: VerticalOverdraw

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Casts the value.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Casts the value.

Performs the conversion.

Performs the conversion.

Casts the value.

Should always be Self

Casts the value.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Casts the value.

Casts the value.