Struct embedded_text::style::height_mode::FitToText [−][src]
pub struct FitToText;
Sets the height of the StyledTextBox to exactly fit the text.
Note: in this mode, vertical alignment is meaningless. Make sure to use TopAligned for
efficiency.
Example: FitToText grows the TextBox.
use embedded_text::prelude::*; use embedded_graphics::{fonts::Font6x8, pixelcolor::BinaryColor, prelude::*}; // This TextBox contains two lines of text, but is 1px high let text_box = TextBox::new( "Two lines\nof text", Rectangle::new(Point::zero(), Point::new(59, 0)), ); // Set style, use 6x8 font so the 2 lines are 16px high. let style = TextBoxStyleBuilder::new(Font6x8) .height_mode(FitToText) .text_color(BinaryColor::On) .build(); // FitToText grows the TextBox to the height of the text let size = text_box.into_styled(style).size(); assert_eq!(size, Size::new(60, 16));
Example: FitToText also shrinks the TextBox.
use embedded_text::prelude::*; use embedded_graphics::{fonts::Font6x8, pixelcolor::BinaryColor, prelude::*}; // This TextBox contains two lines of text, but is 1px high let text_box = TextBox::new( "Two lines\nof text", Rectangle::new(Point::zero(), Point::new(59, 59)), ); // Set style, use 6x8 font so the 2 lines are 16px high. let style = TextBoxStyleBuilder::new(Font6x8) .height_mode(FitToText) .text_color(BinaryColor::On) .build(); // FitToText shrinks the TextBox to the height of the text let size = text_box.into_styled(style).size(); assert_eq!(size, Size::new(60, 16));
Trait Implementations
impl HeightMode for FitToText[src]
impl HeightMode for FitToText[src]fn apply<C, F, A, V, H>(text_box: &mut StyledTextBox<'_, C, F, A, V, H>) where
C: PixelColor,
F: Font + Copy,
A: HorizontalTextAlignment,
V: VerticalTextAlignment,
H: HeightMode, [src]
C: PixelColor,
F: Font + Copy,
A: HorizontalTextAlignment,
V: VerticalTextAlignment,
H: HeightMode,
fn calculate_displayed_row_range<F: Font>(_: &Cursor<F>) -> Range<i32>[src]
Auto Trait Implementations
impl RefUnwindSafe for FitToText
impl RefUnwindSafe for FitToTextimpl UnwindSafe for FitToText
impl UnwindSafe for FitToText