pub struct ImageViewStyle<C> {
pub alignment: ImageAlignment,
pub insets: EdgeInsets,
pub background: Option<C>,
pub border: Option<C>,
pub border_width: u32,
pub corner_radius: u32,
}Expand description
Visual configuration for an ImageView.
Fields§
§alignment: ImageAlignmentImage alignment inside the content rect.
insets: EdgeInsetsInner padding applied before image placement.
background: Option<C>Optional background fill for the shell.
border: Option<C>Optional border color for the shell.
border_width: u32Border width in pixels.
corner_radius: u32Corner radius for the shell.
Implementations§
Source§impl<C> ImageViewStyle<C>
impl<C> ImageViewStyle<C>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates the default image view style.
Examples found in repository?
examples/text_and_image.rs (line 29)
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/image_view.rs (line 98)
97 fn default() -> Self {
98 Self::new()
99 }
100}
101
102/// Reusable bitmap view similar to UIKit's `UIImageView`.
103pub struct ImageView<'a, T, C>
104where
105 T: ImageDrawable<Color = C> + OriginDimensions,
106 C: PixelColor,
107{
108 /// Outer frame for the view.
109 pub frame: Rectangle,
110 /// Referenced image content.
111 pub image: &'a T,
112 /// Shell and alignment style.
113 pub style: ImageViewStyle<C>,
114}
115
116impl<'a, T, C> ImageView<'a, T, C>
117where
118 T: ImageDrawable<Color = C> + OriginDimensions,
119 C: PixelColor,
120{
121 /// Creates a new image view with default styling.
122 pub const fn new(frame: Rectangle, image: &'a T) -> Self {
123 Self {
124 frame,
125 image,
126 style: ImageViewStyle::new(),
127 }
128 }Sourcepub fn with_alignment(self, alignment: ImageAlignment) -> Self
pub fn with_alignment(self, alignment: ImageAlignment) -> Self
Sets image alignment.
Examples found in repository?
examples/text_and_image.rs (line 30)
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_insets(self, insets: EdgeInsets) -> Self
pub fn with_insets(self, insets: EdgeInsets) -> Self
Sets content insets.
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}Sourcepub fn with_background(self, background: C) -> Self
pub fn with_background(self, background: C) -> Self
Sets the shell background color.
Examples found in repository?
examples/text_and_image.rs (line 32)
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_border(self, border: C, border_width: u32) -> Self
pub fn with_border(self, border: C, border_width: u32) -> Self
Sets border color and width.
Examples found in repository?
examples/text_and_image.rs (line 33)
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_corner_radius(self, corner_radius: u32) -> Self
pub fn with_corner_radius(self, corner_radius: u32) -> Self
Sets the shell corner radius.
Examples found in repository?
examples/text_and_image.rs (line 34)
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}Trait Implementations§
Source§impl<C: Clone> Clone for ImageViewStyle<C>
impl<C: Clone> Clone for ImageViewStyle<C>
Source§fn clone(&self) -> ImageViewStyle<C>
fn clone(&self) -> ImageViewStyle<C>
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<C: Debug> Debug for ImageViewStyle<C>
impl<C: Debug> Debug for ImageViewStyle<C>
Source§impl<C> Default for ImageViewStyle<C>
impl<C> Default for ImageViewStyle<C>
Source§impl<C: PartialEq> PartialEq for ImageViewStyle<C>
impl<C: PartialEq> PartialEq for ImageViewStyle<C>
impl<C: Copy> Copy for ImageViewStyle<C>
impl<C: Eq> Eq for ImageViewStyle<C>
impl<C> StructuralPartialEq for ImageViewStyle<C>
Auto Trait Implementations§
impl<C> Freeze for ImageViewStyle<C>where
C: Freeze,
impl<C> RefUnwindSafe for ImageViewStyle<C>where
C: RefUnwindSafe,
impl<C> Send for ImageViewStyle<C>where
C: Send,
impl<C> Sync for ImageViewStyle<C>where
C: Sync,
impl<C> Unpin for ImageViewStyle<C>where
C: Unpin,
impl<C> UnsafeUnpin for ImageViewStyle<C>where
C: UnsafeUnpin,
impl<C> UnwindSafe for ImageViewStyle<C>where
C: UnwindSafe,
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.