[−][src]Struct embedded_text::TextBox
A textbox object.
The TextBox
struct represents a piece of text that can be drawn on a display inside the given
bounding box.
The struct only contains the text and the bounding box, no additional information. To draw
a TextBox
it is necessary to attach a TextBoxStyle
to it using the into_styled
method
to create a StyledTextBox
object.
See the module-level documentation for more information.
Fields
text: &'a str
The text to be displayed in this TextBox
bounds: Rectangle
The bounding box of this TextBox
Implementations
impl<'a> TextBox<'a>
[src]
#[must_use]pub fn new(text: &'a str, bounds: Rectangle) -> Self
[src]
Creates a new TextBox
instance with a given bounding Rectangle
.
#[must_use]pub fn into_styled<C, F, A, V, H>(
self,
style: TextBoxStyle<C, F, A, V, H>
) -> StyledTextBox<'a, C, F, A, V, H> where
C: PixelColor,
F: Font + Copy,
A: HorizontalTextAlignment,
V: VerticalTextAlignment,
H: HeightMode,
[src]
self,
style: TextBoxStyle<C, F, A, V, H>
) -> StyledTextBox<'a, C, F, A, V, H> where
C: PixelColor,
F: Font + Copy,
A: HorizontalTextAlignment,
V: VerticalTextAlignment,
H: HeightMode,
Creates a StyledTextBox
by attaching a TextBoxStyle
to the TextBox
object.
By default, the size of the StyledTextBox
is equal to the size of the TextBox
. Use
HeightMode
options to change this.
Example:
In this example, we make a TextBox
and give it all our available space as size.
We create a TextBoxStyle
object to set how our TextBox
should be drawn.
- Set the 6x8 font
- Set the text color to
BinaryColor::On
- Leave the background color transparent
- Leave text alignment top/left
- Set
ShrinkToText
HeightMode
to shrink theTextBox
when possible.
use embedded_text::{prelude::*, style::vertical_overdraw::FullRowsOnly}; use embedded_graphics::{fonts::Font6x8, pixelcolor::BinaryColor, prelude::*}; let text_box = TextBox::new( "Two lines\nof text", Rectangle::new(Point::zero(), Point::new(59, 59)), ); let style = TextBoxStyleBuilder::new(Font6x8) .height_mode(ShrinkToText(FullRowsOnly)) .text_color(BinaryColor::On) .build(); let styled_text_box = text_box.into_styled(style); assert_eq!(16, styled_text_box.size().height);
Trait Implementations
impl<'a> Clone for TextBox<'a>
[src]
impl<'a> Copy for TextBox<'a>
[src]
impl<'a> Debug for TextBox<'a>
[src]
impl<'_> Dimensions for TextBox<'_>
[src]
#[must_use]pub fn top_left(&self) -> Point
[src]
#[must_use]pub fn bottom_right(&self) -> Point
[src]
#[must_use]pub fn size(&self) -> Size
[src]
impl<'a> Eq for TextBox<'a>
[src]
impl<'a> Hash for TextBox<'a>
[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a> PartialEq<TextBox<'a>> for TextBox<'a>
[src]
pub fn eq(&self, other: &TextBox<'a>) -> bool
[src]
pub fn ne(&self, other: &TextBox<'a>) -> bool
[src]
impl<'a> StructuralEq for TextBox<'a>
[src]
impl<'a> StructuralPartialEq for TextBox<'a>
[src]
impl<'_> Transform for TextBox<'_>
[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for TextBox<'a>
impl<'a> Send for TextBox<'a>
impl<'a> Sync for TextBox<'a>
impl<'a> Unpin for TextBox<'a>
impl<'a> UnwindSafe for TextBox<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,