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));
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));
Trait Implementations§
Source§impl Clone for HeightMode
impl Clone for HeightMode
Source§fn clone(&self) -> HeightMode
fn clone(&self) -> HeightMode
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for HeightMode
impl Debug for HeightMode
Source§impl Hash for HeightMode
impl Hash for HeightMode
Source§impl PartialEq for HeightMode
impl PartialEq for HeightMode
impl Copy for HeightMode
impl Eq for HeightMode
impl StructuralPartialEq for HeightMode
Auto Trait Implementations§
impl Freeze for HeightMode
impl RefUnwindSafe for HeightMode
impl Send for HeightMode
impl Sync for HeightMode
impl Unpin for HeightMode
impl UnwindSafe for HeightMode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.