Skip to main content

ImageView

Struct ImageView 

Source
pub struct ImageView<'a, T, C>
where T: ImageDrawable<Color = C> + OriginDimensions, C: PixelColor,
{ pub frame: Rectangle, pub image: &'a T, pub style: ImageViewStyle<C>, }
Expand description

Reusable bitmap view similar to UIKit’s UIImageView.

Fields§

§frame: Rectangle

Outer frame for the view.

§image: &'a T

Referenced image content.

§style: ImageViewStyle<C>

Shell and alignment style.

Implementations§

Source§

impl<'a, T, C> ImageView<'a, T, C>
where T: ImageDrawable<Color = C> + OriginDimensions, C: PixelColor,

Source

pub const fn new(frame: Rectangle, image: &'a T) -> Self

Creates a new image view with default styling.

Examples found in repository?
examples/text_and_image.rs (lines 24-27)
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}
Source

pub fn with_style(self, style: ImageViewStyle<C>) -> Self

Replaces the view style.

Examples found in repository?
examples/text_and_image.rs (lines 28-35)
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}
Source

pub fn draw<D>(&self, display: &mut D)
where D: DrawTarget<Color = C>,

Draws the image view.

Examples found in repository?
examples/text_and_image.rs (line 36)
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}

Auto Trait Implementations§

§

impl<'a, T, C> Freeze for ImageView<'a, T, C>
where C: Freeze,

§

impl<'a, T, C> RefUnwindSafe for ImageView<'a, T, C>

§

impl<'a, T, C> Send for ImageView<'a, T, C>
where T: Sync, C: Send,

§

impl<'a, T, C> Sync for ImageView<'a, T, C>
where T: Sync, C: Sync,

§

impl<'a, T, C> Unpin for ImageView<'a, T, C>
where C: Unpin,

§

impl<'a, T, C> UnsafeUnpin for ImageView<'a, T, C>
where C: UnsafeUnpin,

§

impl<'a, T, C> UnwindSafe for ImageView<'a, T, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.