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
Exact(VerticalOverdraw)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
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
Trait Implementations
This method tests for self and other values to be equal, and is used
by ==. Read more
This method tests for !=.
Auto Trait Implementations
impl RefUnwindSafe for HeightMode
impl Send for HeightMode
impl Sync for HeightMode
impl Unpin for HeightMode
impl UnwindSafe for HeightMode
Blanket Implementations
Mutably borrows from an owned value. Read more
Casts the value.
Casts the value.
type Output = T
type Output = T
Should always be Self
Casts the value.
Casts the value.
Casts the value.