pub struct EdgeInsets {
pub top: u32,
pub left: u32,
pub bottom: u32,
pub right: u32,
}Expand description
Padding values applied around a view’s content area.
Fields§
§top: u32Top padding in pixels.
left: u32Left padding in pixels.
bottom: u32Bottom padding in pixels.
right: u32Right padding in pixels.
Implementations§
Source§impl EdgeInsets
impl EdgeInsets
Sourcepub const fn new(top: u32, left: u32, bottom: u32, right: u32) -> Self
pub const fn new(top: u32, left: u32, bottom: u32, right: u32) -> Self
Creates explicit inset values.
Sourcepub const fn all(value: u32) -> Self
pub const fn all(value: u32) -> Self
Creates insets with the same value on every side.
Examples found in repository?
examples/text_and_image.rs (line 31)
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/types.rs (line 158)
152 pub const fn new() -> Self {
153 Self {
154 alignment: TextAlignment::Leading,
155 vertical_alignment: TextVerticalAlignment::Top,
156 wrap: TextWrap::SingleLine,
157 line_spacing: 4,
158 insets: EdgeInsets::all(0),
159 background: None,
160 border: None,
161 border_width: 0,
162 corner_radius: 0,
163 }
164 }Sourcepub fn inset_rect(self, rect: Rectangle) -> Rectangle
pub fn inset_rect(self, rect: Rectangle) -> Rectangle
Insets rect and clamps the size at zero.
Examples found in repository?
src/image_view.rs (line 149)
137 pub fn draw<D>(&self, display: &mut D)
138 where
139 D: DrawTarget<Color = C>,
140 {
141 draw_shell(
142 display,
143 self.frame,
144 self.style.background,
145 self.style.border,
146 self.style.border_width,
147 self.style.corner_radius,
148 );
149 let content = self.style.insets.inset_rect(self.frame);
150 if content.size.width == 0 || content.size.height == 0 {
151 return;
152 }
153
154 let image_size = self.image.size();
155 let origin = aligned_origin(content, image_size, self.style.alignment);
156 let mut clipped = display.clipped(&content);
157 Image::new(self.image, origin).draw(&mut clipped).ok();
158 }More examples
src/text_view/widget.rs (line 96)
87pub fn draw_text_view<D>(
88 display: &mut D,
89 frame: Rectangle,
90 spans: &[TextSpan<'_>],
91 view_style: &TextViewStyle,
92) where
93 D: DrawTarget<Color = Rgb565>,
94{
95 draw_shell(display, frame, view_style);
96 let content = view_style.insets.inset_rect(frame);
97 if content.size.width == 0 || content.size.height == 0 || spans.is_empty() {
98 return;
99 }
100
101 let lines = layout_lines(spans, view_style, content.size.width as i32);
102 if lines.is_empty() {
103 return;
104 }
105
106 let spacing = view_style.line_spacing as i32;
107 let total_height = lines.iter().map(|line| line.height).sum::<i32>()
108 + spacing * (lines.len().saturating_sub(1) as i32);
109 let available_height = content.size.height as i32;
110 let offset_y = match view_style.vertical_alignment {
111 TextVerticalAlignment::Top => 0,
112 TextVerticalAlignment::Center => ((available_height - total_height).max(0)) / 2,
113 TextVerticalAlignment::Bottom => (available_height - total_height).max(0),
114 };
115
116 let mut clipped = display.clipped(&content);
117 let mut cursor_y = content.top_left.y + offset_y;
118 for line in lines {
119 let offset_x = match view_style.alignment {
120 TextAlignment::Leading => 0,
121 TextAlignment::Center => ((content.size.width as i32 - line.width).max(0)) / 2,
122 TextAlignment::Trailing => (content.size.width as i32 - line.width).max(0),
123 };
124 draw_line(
125 &mut clipped,
126 spans,
127 line,
128 Point::new(content.top_left.x + offset_x, cursor_y),
129 );
130 cursor_y += line.height + spacing;
131 }
132}Trait Implementations§
Source§impl Clone for EdgeInsets
impl Clone for EdgeInsets
Source§fn clone(&self) -> EdgeInsets
fn clone(&self) -> EdgeInsets
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 EdgeInsets
impl Debug for EdgeInsets
Source§impl Default for EdgeInsets
impl Default for EdgeInsets
Source§fn default() -> EdgeInsets
fn default() -> EdgeInsets
Returns the “default value” for a type. Read more
Source§impl PartialEq for EdgeInsets
impl PartialEq for EdgeInsets
impl Copy for EdgeInsets
impl Eq for EdgeInsets
impl StructuralPartialEq for EdgeInsets
Auto Trait Implementations§
impl Freeze for EdgeInsets
impl RefUnwindSafe for EdgeInsets
impl Send for EdgeInsets
impl Sync for EdgeInsets
impl Unpin for EdgeInsets
impl UnsafeUnpin for EdgeInsets
impl UnwindSafe for EdgeInsets
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.