pub struct TextViewStyle {
pub alignment: TextAlignment,
pub vertical_alignment: TextVerticalAlignment,
pub wrap: TextWrap,
pub line_spacing: u32,
pub insets: EdgeInsets,
pub background: Option<Rgb565>,
pub border: Option<Rgb565>,
pub border_width: u32,
pub corner_radius: u32,
}Expand description
Shared container style for crate::TextView and crate::RichTextView.
Fields§
§alignment: TextAlignmentHorizontal alignment for rendered lines.
vertical_alignment: TextVerticalAlignmentVertical alignment for the rendered block.
wrap: TextWrapWrapping behavior.
line_spacing: u32Extra spacing inserted between lines.
insets: EdgeInsetsContent padding.
background: Option<Rgb565>Optional background fill for the shell.
border: Option<Rgb565>Optional border color for the shell.
border_width: u32Border width in pixels.
corner_radius: u32Corner radius for the shell.
Implementations§
Source§impl TextViewStyle
impl TextViewStyle
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates the default text view style.
Examples found in repository?
examples/text_and_image.rs (line 44)
15fn main() {
16 let mut canvas = support::NullCanvas::new(Size::new(320, 240));
17
18 let image_data = [
19 0xF8, 0x00, 0x07, 0xE0, //
20 0x07, 0xE0, 0xF8, 0x00, //
21 ];
22 let image: ImageRawBE<Rgb565> = ImageRaw::new(&image_data, 2);
23
24 ImageView::new(
25 Rectangle::new(Point::new(16, 16), Size::new(72, 72)),
26 &image,
27 )
28 .with_style(
29 ImageViewStyle::new()
30 .with_alignment(ImageAlignment::Center)
31 .with_insets(EdgeInsets::all(8))
32 .with_background(Rgb565::new(28, 58, 28))
33 .with_border(Rgb565::new(20, 44, 20), 2)
34 .with_corner_radius(12),
35 )
36 .draw(&mut canvas);
37
38 TextView::new(
39 Rectangle::new(Point::new(104, 18), Size::new(192, 28)),
40 "Faststep",
41 TextRunStyle::title(Rgb565::BLACK),
42 )
43 .with_view_style(
44 TextViewStyle::new()
45 .with_alignment(TextAlignment::Leading)
46 .with_vertical_alignment(TextVerticalAlignment::Center),
47 )
48 .draw(&mut canvas);
49
50 let spans = [
51 TextSpan::new("UIKit-like ", TextRunStyle::body(Rgb565::BLACK)),
52 TextSpan::new("embedded UI", TextRunStyle::body_strong(Rgb565::BLUE)),
53 TextSpan::new(
54 "\nfor devices and simulators",
55 TextRunStyle::caption(Rgb565::GREEN),
56 ),
57 ];
58 RichTextView::new(
59 Rectangle::new(Point::new(104, 58), Size::new(192, 72)),
60 &spans,
61 )
62 .with_view_style(
63 TextViewStyle::new()
64 .with_wrap(TextWrap::Multiline)
65 .with_insets(EdgeInsets::all(4)),
66 )
67 .draw(&mut canvas);
68}More examples
src/text_view/widget.rs (line 31)
26 pub const fn new(frame: Rectangle, text: &'a str, style: super::TextRunStyle) -> Self {
27 Self {
28 frame,
29 text,
30 style,
31 view_style: TextViewStyle::new(),
32 }
33 }
34
35 /// Replaces the container style.
36 pub fn with_view_style(mut self, view_style: TextViewStyle) -> Self {
37 self.view_style = view_style;
38 self
39 }
40
41 /// Draws the text view.
42 pub fn draw<D>(&self, display: &mut D)
43 where
44 D: DrawTarget<Color = Rgb565>,
45 {
46 let spans = [TextSpan::new(self.text, self.style)];
47 draw_text_view(display, self.frame, &spans, &self.view_style);
48 }
49}
50
51/// Rich text view built from multiple styled spans.
52pub struct RichTextView<'a> {
53 /// Outer frame for the text view.
54 pub frame: Rectangle,
55 /// Styled spans rendered in order.
56 pub spans: &'a [TextSpan<'a>],
57 /// Container-level layout and shell styling.
58 pub view_style: TextViewStyle,
59}
60
61impl<'a> RichTextView<'a> {
62 /// Creates a rich text view.
63 pub const fn new(frame: Rectangle, spans: &'a [TextSpan<'a>]) -> Self {
64 Self {
65 frame,
66 spans,
67 view_style: TextViewStyle::new(),
68 }
69 }Sourcepub fn with_alignment(self, alignment: TextAlignment) -> Self
pub fn with_alignment(self, alignment: TextAlignment) -> Self
Sets horizontal alignment.
Examples found in repository?
examples/text_and_image.rs (line 45)
15fn main() {
16 let mut canvas = support::NullCanvas::new(Size::new(320, 240));
17
18 let image_data = [
19 0xF8, 0x00, 0x07, 0xE0, //
20 0x07, 0xE0, 0xF8, 0x00, //
21 ];
22 let image: ImageRawBE<Rgb565> = ImageRaw::new(&image_data, 2);
23
24 ImageView::new(
25 Rectangle::new(Point::new(16, 16), Size::new(72, 72)),
26 &image,
27 )
28 .with_style(
29 ImageViewStyle::new()
30 .with_alignment(ImageAlignment::Center)
31 .with_insets(EdgeInsets::all(8))
32 .with_background(Rgb565::new(28, 58, 28))
33 .with_border(Rgb565::new(20, 44, 20), 2)
34 .with_corner_radius(12),
35 )
36 .draw(&mut canvas);
37
38 TextView::new(
39 Rectangle::new(Point::new(104, 18), Size::new(192, 28)),
40 "Faststep",
41 TextRunStyle::title(Rgb565::BLACK),
42 )
43 .with_view_style(
44 TextViewStyle::new()
45 .with_alignment(TextAlignment::Leading)
46 .with_vertical_alignment(TextVerticalAlignment::Center),
47 )
48 .draw(&mut canvas);
49
50 let spans = [
51 TextSpan::new("UIKit-like ", TextRunStyle::body(Rgb565::BLACK)),
52 TextSpan::new("embedded UI", TextRunStyle::body_strong(Rgb565::BLUE)),
53 TextSpan::new(
54 "\nfor devices and simulators",
55 TextRunStyle::caption(Rgb565::GREEN),
56 ),
57 ];
58 RichTextView::new(
59 Rectangle::new(Point::new(104, 58), Size::new(192, 72)),
60 &spans,
61 )
62 .with_view_style(
63 TextViewStyle::new()
64 .with_wrap(TextWrap::Multiline)
65 .with_insets(EdgeInsets::all(4)),
66 )
67 .draw(&mut canvas);
68}Sourcepub fn with_vertical_alignment(self, alignment: TextVerticalAlignment) -> Self
pub fn with_vertical_alignment(self, alignment: TextVerticalAlignment) -> Self
Sets vertical alignment.
Examples found in repository?
examples/text_and_image.rs (line 46)
15fn main() {
16 let mut canvas = support::NullCanvas::new(Size::new(320, 240));
17
18 let image_data = [
19 0xF8, 0x00, 0x07, 0xE0, //
20 0x07, 0xE0, 0xF8, 0x00, //
21 ];
22 let image: ImageRawBE<Rgb565> = ImageRaw::new(&image_data, 2);
23
24 ImageView::new(
25 Rectangle::new(Point::new(16, 16), Size::new(72, 72)),
26 &image,
27 )
28 .with_style(
29 ImageViewStyle::new()
30 .with_alignment(ImageAlignment::Center)
31 .with_insets(EdgeInsets::all(8))
32 .with_background(Rgb565::new(28, 58, 28))
33 .with_border(Rgb565::new(20, 44, 20), 2)
34 .with_corner_radius(12),
35 )
36 .draw(&mut canvas);
37
38 TextView::new(
39 Rectangle::new(Point::new(104, 18), Size::new(192, 28)),
40 "Faststep",
41 TextRunStyle::title(Rgb565::BLACK),
42 )
43 .with_view_style(
44 TextViewStyle::new()
45 .with_alignment(TextAlignment::Leading)
46 .with_vertical_alignment(TextVerticalAlignment::Center),
47 )
48 .draw(&mut canvas);
49
50 let spans = [
51 TextSpan::new("UIKit-like ", TextRunStyle::body(Rgb565::BLACK)),
52 TextSpan::new("embedded UI", TextRunStyle::body_strong(Rgb565::BLUE)),
53 TextSpan::new(
54 "\nfor devices and simulators",
55 TextRunStyle::caption(Rgb565::GREEN),
56 ),
57 ];
58 RichTextView::new(
59 Rectangle::new(Point::new(104, 58), Size::new(192, 72)),
60 &spans,
61 )
62 .with_view_style(
63 TextViewStyle::new()
64 .with_wrap(TextWrap::Multiline)
65 .with_insets(EdgeInsets::all(4)),
66 )
67 .draw(&mut canvas);
68}Sourcepub fn with_wrap(self, wrap: TextWrap) -> Self
pub fn with_wrap(self, wrap: TextWrap) -> Self
Sets wrapping behavior.
Examples found in repository?
examples/text_and_image.rs (line 64)
15fn main() {
16 let mut canvas = support::NullCanvas::new(Size::new(320, 240));
17
18 let image_data = [
19 0xF8, 0x00, 0x07, 0xE0, //
20 0x07, 0xE0, 0xF8, 0x00, //
21 ];
22 let image: ImageRawBE<Rgb565> = ImageRaw::new(&image_data, 2);
23
24 ImageView::new(
25 Rectangle::new(Point::new(16, 16), Size::new(72, 72)),
26 &image,
27 )
28 .with_style(
29 ImageViewStyle::new()
30 .with_alignment(ImageAlignment::Center)
31 .with_insets(EdgeInsets::all(8))
32 .with_background(Rgb565::new(28, 58, 28))
33 .with_border(Rgb565::new(20, 44, 20), 2)
34 .with_corner_radius(12),
35 )
36 .draw(&mut canvas);
37
38 TextView::new(
39 Rectangle::new(Point::new(104, 18), Size::new(192, 28)),
40 "Faststep",
41 TextRunStyle::title(Rgb565::BLACK),
42 )
43 .with_view_style(
44 TextViewStyle::new()
45 .with_alignment(TextAlignment::Leading)
46 .with_vertical_alignment(TextVerticalAlignment::Center),
47 )
48 .draw(&mut canvas);
49
50 let spans = [
51 TextSpan::new("UIKit-like ", TextRunStyle::body(Rgb565::BLACK)),
52 TextSpan::new("embedded UI", TextRunStyle::body_strong(Rgb565::BLUE)),
53 TextSpan::new(
54 "\nfor devices and simulators",
55 TextRunStyle::caption(Rgb565::GREEN),
56 ),
57 ];
58 RichTextView::new(
59 Rectangle::new(Point::new(104, 58), Size::new(192, 72)),
60 &spans,
61 )
62 .with_view_style(
63 TextViewStyle::new()
64 .with_wrap(TextWrap::Multiline)
65 .with_insets(EdgeInsets::all(4)),
66 )
67 .draw(&mut canvas);
68}Sourcepub fn with_line_spacing(self, line_spacing: u32) -> Self
pub fn with_line_spacing(self, line_spacing: u32) -> Self
Sets extra line spacing.
Sourcepub fn with_insets(self, insets: EdgeInsets) -> Self
pub fn with_insets(self, insets: EdgeInsets) -> Self
Sets content padding.
Examples found in repository?
examples/text_and_image.rs (line 65)
15fn main() {
16 let mut canvas = support::NullCanvas::new(Size::new(320, 240));
17
18 let image_data = [
19 0xF8, 0x00, 0x07, 0xE0, //
20 0x07, 0xE0, 0xF8, 0x00, //
21 ];
22 let image: ImageRawBE<Rgb565> = ImageRaw::new(&image_data, 2);
23
24 ImageView::new(
25 Rectangle::new(Point::new(16, 16), Size::new(72, 72)),
26 &image,
27 )
28 .with_style(
29 ImageViewStyle::new()
30 .with_alignment(ImageAlignment::Center)
31 .with_insets(EdgeInsets::all(8))
32 .with_background(Rgb565::new(28, 58, 28))
33 .with_border(Rgb565::new(20, 44, 20), 2)
34 .with_corner_radius(12),
35 )
36 .draw(&mut canvas);
37
38 TextView::new(
39 Rectangle::new(Point::new(104, 18), Size::new(192, 28)),
40 "Faststep",
41 TextRunStyle::title(Rgb565::BLACK),
42 )
43 .with_view_style(
44 TextViewStyle::new()
45 .with_alignment(TextAlignment::Leading)
46 .with_vertical_alignment(TextVerticalAlignment::Center),
47 )
48 .draw(&mut canvas);
49
50 let spans = [
51 TextSpan::new("UIKit-like ", TextRunStyle::body(Rgb565::BLACK)),
52 TextSpan::new("embedded UI", TextRunStyle::body_strong(Rgb565::BLUE)),
53 TextSpan::new(
54 "\nfor devices and simulators",
55 TextRunStyle::caption(Rgb565::GREEN),
56 ),
57 ];
58 RichTextView::new(
59 Rectangle::new(Point::new(104, 58), Size::new(192, 72)),
60 &spans,
61 )
62 .with_view_style(
63 TextViewStyle::new()
64 .with_wrap(TextWrap::Multiline)
65 .with_insets(EdgeInsets::all(4)),
66 )
67 .draw(&mut canvas);
68}Sourcepub fn with_background(self, background: Rgb565) -> Self
pub fn with_background(self, background: Rgb565) -> Self
Sets the shell background color.
Sourcepub fn with_border(self, border: Rgb565, border_width: u32) -> Self
pub fn with_border(self, border: Rgb565, border_width: u32) -> Self
Sets shell border color and width.
Sourcepub fn with_corner_radius(self, corner_radius: u32) -> Self
pub fn with_corner_radius(self, corner_radius: u32) -> Self
Sets the shell corner radius.
Trait Implementations§
Source§impl Clone for TextViewStyle
impl Clone for TextViewStyle
Source§fn clone(&self) -> TextViewStyle
fn clone(&self) -> TextViewStyle
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 TextViewStyle
impl Debug for TextViewStyle
Source§impl Default for TextViewStyle
impl Default for TextViewStyle
Source§impl PartialEq for TextViewStyle
impl PartialEq for TextViewStyle
impl Copy for TextViewStyle
impl Eq for TextViewStyle
impl StructuralPartialEq for TextViewStyle
Auto Trait Implementations§
impl Freeze for TextViewStyle
impl RefUnwindSafe for TextViewStyle
impl Send for TextViewStyle
impl Sync for TextViewStyle
impl Unpin for TextViewStyle
impl UnsafeUnpin for TextViewStyle
impl UnwindSafe for TextViewStyle
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.