1786011156

This commit is contained in:
2026-08-06 12:12:36 +02:00
parent 2a07e79233
commit dbe3f879a2
2 changed files with 21 additions and 24 deletions

View File

@@ -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);

View File

@@ -24,6 +24,7 @@ pub struct Trekstor<S> {
state: S,
ctx: Context,
window: Rc<MinimalSoftwareWindow>,
// buffer: Vec<Rgba8Pixel>,
last_time: Instant,
current_time: Instant,
update_timestep: Duration,
@@ -39,6 +40,7 @@ impl<S> Trekstor<S> {
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<S> Trekstor<S> {
}
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<S> Trekstor<S> {
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<S> Trekstor<S> {
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();
}