Skip to main content

ViewRegistration

Struct ViewRegistration 

Source
pub struct ViewRegistration<'a, ViewId, const N: usize> { /* private fields */ }
Expand description

Mutable registration object passed to crate::UiView::configure.

Implementations§

Source§

impl<'a, ViewId, const N: usize> ViewRegistration<'a, ViewId, N>

Source

pub fn new(frame: Rectangle) -> Self

Creates a registration rooted at the given frame.

Examples found in repository?
src/system.rs (line 30)
29    pub fn new(display: Display, root: Root, theme: FsTheme, i18n: I18n<'text>) -> Self {
30        let registration = ViewRegistration::new(display.bounds());
31        let mut system = Self {
32            display,
33            root,
34            theme,
35            i18n,
36            registration,
37            marker: PhantomData,
38        };
39        system.configure_root();
40        system
41    }
Source

pub const fn frame(&self) -> Rectangle

Returns the current root frame for the view.

Examples found in repository?
examples/runtime_shell.rs (line 29)
27    fn configure(&mut self, registration: &mut ViewRegistration<'static, RootId, 1>) {
28        let _ = registration.add_child(
29            ChildView::new(RootId::Surface, registration.frame()).with_kind(ViewKind::Custom),
30        );
31    }
32
33    fn handle_touch(
34        &mut self,
35        _touch: TouchEvent,
36        _registration: &ViewRegistration<'static, RootId, 1>,
37        _env: &ViewEnvironment<'_, 'static>,
38    ) -> ViewEvent<()> {
39        ViewEvent::redraw(ViewRedraw::Full)
40    }
41
42    fn draw<D>(
43        &self,
44        display: &mut D,
45        registration: &ViewRegistration<'static, RootId, 1>,
46        _env: &ViewEnvironment<'_, 'static>,
47    ) where
48        D: DrawTarget<Color = Rgb565>,
49    {
50        registration
51            .frame()
52            .into_styled(PrimitiveStyle::with_fill(Rgb565::new(31, 63, 31)))
53            .draw(display)
54            .ok();
55    }
More examples
Hide additional examples
examples/uikit_root.rs (line 45)
42    fn configure(&mut self, registration: &mut ViewRegistration<'static, DemoViewId, 2>) {
43        registration.set_title(Localized::new("root.title", "Devices"));
44        registration.set_clips_to_bounds(true);
45        let list_frame = registration.frame();
46        let _ = registration.add_child(
47            ChildView::new(DemoViewId::DevicesList, list_frame)
48                .with_kind(ViewKind::List)
49                .with_title(Localized::new("devices.title", "Devices")),
50        );
51        let _ = registration.add_child(
52            ChildView::new(
53                DemoViewId::AlertOverlay,
54                Rectangle::new(Point::new(16, 16), Size::new(0, 0)),
55            )
56            .with_kind(ViewKind::AlertHost)
57            .with_hidden(true)
58            .with_alpha(0),
59        );
60    }
Source

pub fn set_frame(&mut self, frame: Rectangle)

Updates the root frame for the view.

Examples found in repository?
src/system.rs (line 46)
44    pub fn configure_root(&mut self) {
45        self.registration.clear_children();
46        self.registration.set_frame(self.display.bounds());
47        self.root.configure(&mut self.registration);
48    }
Source

pub const fn properties(&self) -> &ViewProperties<'a>

Returns the accumulated properties for the registered view.

Source

pub fn set_title(&mut self, title: Localized<'a>)

Sets the view title.

Examples found in repository?
examples/uikit_root.rs (line 43)
42    fn configure(&mut self, registration: &mut ViewRegistration<'static, DemoViewId, 2>) {
43        registration.set_title(Localized::new("root.title", "Devices"));
44        registration.set_clips_to_bounds(true);
45        let list_frame = registration.frame();
46        let _ = registration.add_child(
47            ChildView::new(DemoViewId::DevicesList, list_frame)
48                .with_kind(ViewKind::List)
49                .with_title(Localized::new("devices.title", "Devices")),
50        );
51        let _ = registration.add_child(
52            ChildView::new(
53                DemoViewId::AlertOverlay,
54                Rectangle::new(Point::new(16, 16), Size::new(0, 0)),
55            )
56            .with_kind(ViewKind::AlertHost)
57            .with_hidden(true)
58            .with_alpha(0),
59        );
60    }
Source

pub fn set_alpha(&mut self, alpha: u8)

Sets the alpha value used for the view.

Source

pub fn set_hidden(&mut self, hidden: bool)

Marks the registered view as hidden or visible.

Source

pub fn set_clips_to_bounds(&mut self, clips_to_bounds: bool)

Enables or disables clipping to bounds.

Examples found in repository?
examples/uikit_root.rs (line 44)
42    fn configure(&mut self, registration: &mut ViewRegistration<'static, DemoViewId, 2>) {
43        registration.set_title(Localized::new("root.title", "Devices"));
44        registration.set_clips_to_bounds(true);
45        let list_frame = registration.frame();
46        let _ = registration.add_child(
47            ChildView::new(DemoViewId::DevicesList, list_frame)
48                .with_kind(ViewKind::List)
49                .with_title(Localized::new("devices.title", "Devices")),
50        );
51        let _ = registration.add_child(
52            ChildView::new(
53                DemoViewId::AlertOverlay,
54                Rectangle::new(Point::new(16, 16), Size::new(0, 0)),
55            )
56            .with_kind(ViewKind::AlertHost)
57            .with_hidden(true)
58            .with_alpha(0),
59        );
60    }
Source

pub fn set_user_interaction_enabled(&mut self, enabled: bool)

Enables or disables touch handling for the view.

Source

pub fn clear_children(&mut self)

Removes all previously registered child views.

Examples found in repository?
src/system.rs (line 45)
44    pub fn configure_root(&mut self) {
45        self.registration.clear_children();
46        self.registration.set_frame(self.display.bounds());
47        self.root.configure(&mut self.registration);
48    }
Source

pub fn add_child( &mut self, child: ChildView<'a, ViewId>, ) -> Result<(), ChildView<'a, ViewId>>

Registers one child view.

Examples found in repository?
examples/runtime_shell.rs (lines 28-30)
27    fn configure(&mut self, registration: &mut ViewRegistration<'static, RootId, 1>) {
28        let _ = registration.add_child(
29            ChildView::new(RootId::Surface, registration.frame()).with_kind(ViewKind::Custom),
30        );
31    }
More examples
Hide additional examples
examples/uikit_root.rs (lines 46-50)
42    fn configure(&mut self, registration: &mut ViewRegistration<'static, DemoViewId, 2>) {
43        registration.set_title(Localized::new("root.title", "Devices"));
44        registration.set_clips_to_bounds(true);
45        let list_frame = registration.frame();
46        let _ = registration.add_child(
47            ChildView::new(DemoViewId::DevicesList, list_frame)
48                .with_kind(ViewKind::List)
49                .with_title(Localized::new("devices.title", "Devices")),
50        );
51        let _ = registration.add_child(
52            ChildView::new(
53                DemoViewId::AlertOverlay,
54                Rectangle::new(Point::new(16, 16), Size::new(0, 0)),
55            )
56            .with_kind(ViewKind::AlertHost)
57            .with_hidden(true)
58            .with_alpha(0),
59        );
60    }
Source

pub fn children(&self) -> &[ChildView<'a, ViewId>]

Returns the registered children as a slice.

Examples found in repository?
examples/uikit_root.rs (line 68)
62    fn update(
63        &mut self,
64        dt_ms: u32,
65        registration: &ViewRegistration<'static, DemoViewId, 2>,
66        _env: &ViewEnvironment<'_, 'static>,
67    ) -> ViewEvent<DemoMessage> {
68        let list = registration.children()[0].frame;
69        ViewEvent::redraw(self.list.tick(dt_ms, list))
70    }
71
72    fn handle_touch(
73        &mut self,
74        touch: TouchEvent,
75        registration: &ViewRegistration<'static, DemoViewId, 2>,
76        _env: &ViewEnvironment<'_, 'static>,
77    ) -> ViewEvent<DemoMessage> {
78        self.list
79            .handle_touch(touch, registration.children()[0].frame)
80            .into_view_event()
81    }
82
83    fn draw<D>(
84        &self,
85        display: &mut D,
86        registration: &ViewRegistration<'static, DemoViewId, 2>,
87        env: &ViewEnvironment<'_, 'static>,
88    ) where
89        D: DrawTarget<Color = Rgb565>,
90    {
91        self.list
92            .draw(display, registration.children()[0].frame, env);
93    }

Trait Implementations§

Source§

impl<'a, ViewId: Clone, const N: usize> Clone for ViewRegistration<'a, ViewId, N>

Source§

fn clone(&self) -> ViewRegistration<'a, ViewId, N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, ViewId: Debug, const N: usize> Debug for ViewRegistration<'a, ViewId, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, ViewId: PartialEq, const N: usize> PartialEq for ViewRegistration<'a, ViewId, N>

Source§

fn eq(&self, other: &ViewRegistration<'a, ViewId, N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, ViewId: Eq, const N: usize> Eq for ViewRegistration<'a, ViewId, N>

Source§

impl<'a, ViewId, const N: usize> StructuralPartialEq for ViewRegistration<'a, ViewId, N>

Auto Trait Implementations§

§

impl<'a, ViewId, const N: usize> Freeze for ViewRegistration<'a, ViewId, N>
where ViewId: Freeze,

§

impl<'a, ViewId, const N: usize> RefUnwindSafe for ViewRegistration<'a, ViewId, N>
where ViewId: RefUnwindSafe,

§

impl<'a, ViewId, const N: usize> Send for ViewRegistration<'a, ViewId, N>
where ViewId: Send,

§

impl<'a, ViewId, const N: usize> Sync for ViewRegistration<'a, ViewId, N>
where ViewId: Sync,

§

impl<'a, ViewId, const N: usize> Unpin for ViewRegistration<'a, ViewId, N>
where ViewId: Unpin,

§

impl<'a, ViewId, const N: usize> UnsafeUnpin for ViewRegistration<'a, ViewId, N>
where ViewId: UnsafeUnpin,

§

impl<'a, ViewId, const N: usize> UnwindSafe for ViewRegistration<'a, ViewId, N>
where ViewId: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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.