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:
use embedded_graphics::{ mono_font::{ascii::FONT_6X9, MonoTextStyleBuilder}, pixelcolor::BinaryColor, prelude::*, primitives::Rectangle, }; use embedded_text::{style::TextBoxStyleBuilder, TextBox}; let character_style = MonoTextStyleBuilder::new() .font(&FONT_6X9) .text_color(BinaryColor::On) .build(); // This TextBox contains two lines of text, but is 60px high let text_box = TextBox::new( "Two lines\nof text", Rectangle::new(Point::zero(), Size::new(60, 60)), character_style, ); // Exact does not change the size of the TextBox let orig_size = text_box.bounding_box().size; let size = text_box.bounding_box().size; assert_eq!(size, orig_size);
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 grows the TextBox.
use embedded_graphics::{ mono_font::{ascii::FONT_6X9, MonoTextStyleBuilder}, pixelcolor::BinaryColor, prelude::*, primitives::Rectangle, }; use embedded_text::{ style::{HeightMode, TextBoxStyleBuilder}, TextBox, }; // Set style, use 6x9 MonoFont so the 2 lines are 18px high. let character_style = MonoTextStyleBuilder::new() .font(&FONT_6X9) .text_color(BinaryColor::On) .build(); let style = TextBoxStyleBuilder::new().height_mode(HeightMode::FitToText).build(); // This TextBox contains two lines of text, but is 1px high let text_box = TextBox::with_textbox_style( "Two lines\nof text", Rectangle::new(Point::zero(), Size::new(60, 0)), character_style, style, ); // FitToText grows the TextBox to the height of the text let size = text_box.bounding_box().size; assert_eq!(size, Size::new(60, 18));
Example: FitToText also shrinks the TextBox.
use embedded_graphics::{ mono_font::{ascii::FONT_6X9, MonoTextStyle}, pixelcolor::BinaryColor, prelude::*, primitives::Rectangle, }; use embedded_text::{ style::{HeightMode, TextBoxStyleBuilder}, TextBox, }; // Set style, use 6x9 MonoFont so the 2 lines are 18px high. let character_style = MonoTextStyle::new(&FONT_6X9, BinaryColor::On); let style = TextBoxStyleBuilder::new().height_mode(HeightMode::FitToText).build(); // This TextBox contains two lines of text, but is 1px high let text_box = TextBox::with_textbox_style( "Two lines\nof text", Rectangle::new(Point::zero(), Size::new(60, 60)), character_style, style, ); // FitToText shrinks the TextBox to the height of the text let size = text_box.bounding_box().size; assert_eq!(size, Size::new(60, 18));
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::{ mono_font::{ascii::FONT_6X9, MonoTextStyle}, pixelcolor::BinaryColor, prelude::*, primitives::Rectangle, }; use embedded_text::{ style::{HeightMode, VerticalOverdraw, TextBoxStyleBuilder}, TextBox, }; // Set style, use 6x9 MonoFont so the 2 lines are 18px high. let character_style = MonoTextStyle::new(&FONT_6X9, BinaryColor::On); let style = TextBoxStyleBuilder::new() .height_mode(HeightMode::ShrinkToText(VerticalOverdraw::FullRowsOnly)) .build(); // This TextBox contains two lines of text, but is 1px high let text_box = TextBox::with_textbox_style( "Two lines\nof text", Rectangle::new(Point::zero(), Size::new(60, 0)), character_style, style, ); let size = text_box.bounding_box().size; assert_eq!(size, Size::new(60, 0));
Example: ShrinkToText shrinks the TextBox.
use embedded_graphics::{ mono_font::{ascii::FONT_6X9, MonoTextStyle}, pixelcolor::BinaryColor, prelude::*, primitives::Rectangle, }; use embedded_text::{ style::{HeightMode, VerticalOverdraw, TextBoxStyleBuilder}, TextBox, }; // Set style, use 6x9 MonoFont so the 2 lines are 18px high. let character_style = MonoTextStyle::new(&FONT_6X9, BinaryColor::On); let style = TextBoxStyleBuilder::new() .height_mode(HeightMode::ShrinkToText(VerticalOverdraw::FullRowsOnly)) .build(); // This TextBox contains two lines of text, but is 60px high let text_box = TextBox::with_textbox_style( "Two lines\nof text", Rectangle::new(Point::zero(), Size::new(60, 60)), character_style, style, ); let size = text_box.bounding_box().size; assert_eq!(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.