lv_binding_rust icon indicating copy to clipboard operation
lv_binding_rust copied to clipboard

Attribute macros for `lvgl-rs`

Open nia-e opened this issue 2 years ago • 1 comments

In light of #24 it might be a good idea to allow for common bolierplate-y things like LVGL initialization, task/timer handler updates, etc. to be abstracted away. My idea is doing something like:

/* use ... */

static shared_native_display: RefCell<SimulatorDisplay<ColorSpace>> =
    RefCell::new(SimulatorDisplay::new(Size::new(240 as u32, 240 as u32)));

fn disp_handler<N>(refresh: &DisplayRefresh<N>) {
    shared_native_display.borrow_mut().draw_iter(refresh.as_pixels()).unwrap();
}

#[lvgl_main]
fn main() {
    let output_settings = OutputSettingsBuilder::new().scale(2).build();
    let mut window = Window::new("Macro Example", &output_settings);

    #[lvgl_display(hor = 240, ver = 240, handler = disp_handler)]
    let display;

    let screen = display.get_scr_act()?

    /* Styling, widgets. etc */

    #[lvgl_event_loop(frame_time = 16)]
    'running: loop {
        /* GUI logic */
    }
}

More could certainly be done (interesting ideas might include attribute macros for widgets as well, to be able to specify e.g. event handlers) but this might be a start.

Is this something worth working on?

nia-e avatar Mar 04 '23 15:03 nia-e

Looks very useful. I like the idea!

rafaelcaricio avatar Mar 05 '23 00:03 rafaelcaricio