From dbe3f879a2f915da2ecbeb6b8bc20f54a2193f4a Mon Sep 17 00:00:00 2001 From: Avii Date: Thu, 6 Aug 2026 12:12:36 +0200 Subject: [PATCH] 1786011156 --- src/main.rs | 17 +---------------- src/trekstor.rs | 28 ++++++++++++++++++++-------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/main.rs b/src/main.rs index 40daf58..96b4ff4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,22 +16,7 @@ fn main() { let mut trekstor = Trekstor::new(60, app_state); - trekstor.update(|ctx, state| { - if ctx.input.is_just_released(KeyCode::BTN_TOUCH) { - println!("Released {}x{}", ctx.input.x, ctx.input.y); - state.x = ctx.input.x; - state.y = ctx.input.y; - } - - ctx.screen.clear((0, 0, 0, 255).into()).ok(); - - Rectangle::new(Point::new(state.x - 5, state.y - 5), Size::new(10, 10)) - .into_styled(PrimitiveStyle::with_fill((255, 0, 0, 255).into())) - .draw(&mut ctx.screen) - .ok(); - - true - }); + trekstor.update(); // let red = (255, 0, 0, 255); // let green = (0, 255, 0, 255); diff --git a/src/trekstor.rs b/src/trekstor.rs index f77c822..211544f 100644 --- a/src/trekstor.rs +++ b/src/trekstor.rs @@ -24,6 +24,7 @@ pub struct Trekstor { state: S, ctx: Context, window: Rc, + // buffer: Vec, last_time: Instant, current_time: Instant, update_timestep: Duration, @@ -39,6 +40,7 @@ impl Trekstor { state, ctx: Context { screen, input }, window, + // buffer: Vec::new(), current_time: Instant::now(), last_time: Instant::now(), update_timestep: Duration::from_nanos( @@ -48,6 +50,9 @@ impl Trekstor { } pub fn update(&mut self) { + dbg!(self.ctx.screen.width() * self.ctx.screen.height()); + let mut buffer1 = [slint::platform::software_renderer::Rgb565Pixel(0); 1]; + loop { self.current_time = Instant::now(); let dt = self.current_time - self.last_time; @@ -62,13 +67,15 @@ impl Trekstor { slint::platform::update_timers_and_animations(); if self.ctx.input.is_just_pressed(KeyCode::BTN_TOUCH) { - self.window.try_dispatch_event(WindowEvent::PointerPressed { - position: LogicalPosition::new( - self.ctx.input.x as f32, - self.ctx.input.y as f32, - ), - button: slint::platform::PointerEventButton::Left, - }); + self.window + .try_dispatch_event(WindowEvent::PointerPressed { + position: LogicalPosition::new( + self.ctx.input.x as f32, + self.ctx.input.y as f32, + ), + button: slint::platform::PointerEventButton::Left, + }) + .unwrap(); } if self.ctx.input.is_just_released(KeyCode::BTN_TOUCH) { @@ -79,9 +86,14 @@ impl Trekstor { self.ctx.input.y as f32, ), button: slint::platform::PointerEventButton::Left, - }); + }) + .unwrap(); } + self.window.draw_if_needed(|renderer| { + renderer.render(&mut buffer1, self.ctx.screen.width() as usize); + }); + self.ctx.screen.flush(); self.ctx.input.finish(); }