Skip to main content

AppMessages

Struct AppMessages 

Source
pub struct AppMessages { /* private fields */ }
Expand description

This struct provides access to app messages. You must use AppMessages::open to be able to register handlers and send messages.

You receive an instance of this from crate::main.

Implementations§

Source§

impl AppMessages

Source

pub fn open<'handle>( &'handle mut self, size_inbound: u32, size_outbound: u32, ) -> OpenAppMessages<'handle>

Open the app message service with the given buffer sizes.

Returns an OpenAppMessages that can be used to send messages and register event listeners via OpenAppMessages::listen.

When the returned OpenAppMessages is dropped, the app message service is closed and SDK callbacks are deregistered.

Examples found in repository?
example/src/lib.rs (line 47)
43async fn async_main_(mut services: bordstein::PebbleServices, _spawner: embassy_executor::Spawner) {
44    bordstein::info!("Async main called!");
45
46    with_window(async |mut h| {
47        let app_messages = services.app_messages.open(1024, 512);
48        stack_pin_init!(let _app_message_listener = app_messages.listen(
49            |_d| {},
50            |_| {},
51            |_| {},
52            |_, _| {},
53        ));
54        stack_pin_init!(let _app_message_listener = app_messages.listen(
55            |_d| {},
56            |_| {},
57            |_| {},
58            |_, _| {},
59        ));
60        stack_pin_init!(let _app_message_listener = app_messages.listen_received(
61            |_d| {},
62        ));
63
64        let _ = app_messages.send(|d| d.u8(10001, 123));
65
66        h.set_background_colour(GColor8::RED);
67
68        let window_bounds = h.root_layer().bounds();
69        bordstein::info!("Window bounds: {:?}", window_bounds);
70
71        stack_pin_init!(let timer_minutes = TickService::listen(TimeUnits::MINUTE_UNIT, |time, _| {
72            bordstein::info!("minute timer tick: {:?}", time);
73        }));
74
75        {
76            stack_pin_init!(let timer_seconds = TickService::listen(TimeUnits::SECOND_UNIT, |time, _| {
77                bordstein::info!("second timer tick: {:?}", time);
78            }));
79
80            let root_layer = h.root_layer();
81            let status_bar = root_layer.new_child::<StatusBarLayer>(()).unwrap();
82
83            let remaining_space =
84                window_bounds.shrink_to_avoid(status_bar.layer().bounds(), shapes::Edge::Top, 0);
85
86            let mut child_layer = root_layer
87                .new_child::<ScrollLayer>(remaining_space)
88                .unwrap();
89
90            child_layer.set_click_config_onto_window(&mut h);
91
92            let mut num_taps: u32 = 0;
93
94            let mut accelerometer_service = services.accelerometer.enable();
95            stack_pin_init!(let tap_events = accelerometer_service.subscribe_to_tap_service(|axis, dir| {
96                num_taps += 1;
97                bordstein::info!("Tap! {}, {:?}, {}", num_taps, axis, dir);
98            }));
99
100            let mut text_layer = child_layer
101                .new_child::<TextLayer>(child_layer.layer().bounds().with_height(100))
102                .unwrap();
103            text_layer.set_text_alignment(GTextAlignment::GTextAlignmentCenter);
104
105            let mut fill_layer = child_layer
106                .new_child::<TextLayer>(child_layer.layer().bounds().translate(0, text_layer.layer().bounds().size.h))
107                .unwrap();
108
109            child_layer.set_content_size(GSize::total_bounds_of_rects([
110                text_layer.layer().frame(),
111                fill_layer.layer().frame(),
112            ]));
113            // child_layer.set_content_size(GSize::new(200, 500));
114
115            bordstein::info!("Scroll bounds: {:?}", child_layer.get_content_size());
116
117            let _guard = fill_layer.set_text(cr#"
118foo
119bar
120baz
121hello
122this
123is
124some
125text
126lorem
127ipsum
128dolor
129sit
130amet
131"#);
132
133            let mut text_content: CString<64>;
134            for i in 0..100 {
135                text_content = CString::<64>::new();
136                let _ = ufmt::uwrite!(&mut text_content, "{}", i);
137                let _guard = text_layer.set_text(&text_content);
138
139                embassy_time::Timer::after_secs(1).await;
140
141                // app_messages
142                //     .send(|d| {
143                //         d.u16(10001, 1234)?;
144
145                //         Ok(())
146                //     })
147                //     .unwrap();
148
149                child_layer.set_content_offset(GPoint::new(0, i * -10), true);
150
151                bordstein::info!("Scroll offset: {:?}", child_layer.get_content_offset());
152            }
153
154            bordstein::info!("Child bounds: {:?}", child_layer.layer().bounds());
155        }
156
157        stack_pin_init!(let timer_seconds_stream = TickService::stream(TimeUnits::SECOND_UNIT));
158        while let Some(t) = timer_seconds_stream.next().await {
159            bordstein::info!("second tick stream: {}", t.0.secs);
160        }
161
162        // layers now destroyed, app should show just the window with its red background
163
164        // if you have nothing else to do, but want to wait until the system
165        // closes the window, you can use core::future::pending.
166        core::future::pending::<()>().await;
167    })
168    .await
169    .unwrap();
170}

Auto Trait Implementations§

§

impl Freeze for AppMessages

§

impl RefUnwindSafe for AppMessages

§

impl Send for AppMessages

§

impl Sync for AppMessages

§

impl Unpin for AppMessages

§

impl UnsafeUnpin for AppMessages

§

impl UnwindSafe for AppMessages

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Init<T> for T

§

unsafe fn __init(self, slot: *mut T) -> Result<(), Infallible>

Initializes slot. Read more
§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> PinInit<T> for T

§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>

Initializes slot. Read more
§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.