1786013766

This commit is contained in:
2026-08-06 12:56:06 +02:00
parent 3f0719e479
commit 67282c4a95
4 changed files with 56 additions and 83 deletions

View File

@@ -3,10 +3,14 @@ mod trekstor;
use crate::trekstor::Trekstor;
fn main() {
let mut trekstor = Trekstor::new(30);
slint::include_modules!();
trekstor.update();
fn main() -> Result<(), slint::PlatformError> {
slint::platform::set_platform(Box::new(Trekstor::new())).expect("set platform");
let ui = AppWindow::new()?;
ui.run()
// let red = (255, 0, 0, 255);
// let green = (0, 255, 0, 255);

View File

@@ -1,8 +1,5 @@
use std::rc::Rc;
use std::thread::sleep;
use std::time::{Duration, Instant};
use embedded_graphics::prelude::DrawTarget;
use evdev::KeyCode;
use slint::LogicalPosition;
use slint::platform::software_renderer::{MinimalSoftwareWindow, RepaintBufferType};
@@ -22,87 +19,14 @@ pub struct Context {
}
pub struct Trekstor {
ctx: Context,
window: Rc<MinimalSoftwareWindow>,
// buffer: Vec<Rgba8Pixel>,
last_time: Instant,
current_time: Instant,
update_timestep: Duration,
}
impl Trekstor {
pub fn new(update_fps: i32) -> Self {
let screen = Screen::new();
let input = InputState::new(&screen);
pub fn new() -> Self {
let window = MinimalSoftwareWindow::new(RepaintBufferType::ReusedBuffer);
Self {
ctx: Context { screen, input },
window,
// buffer: Vec::new(),
current_time: Instant::now(),
last_time: Instant::now(),
update_timestep: Duration::from_nanos(
(1_000_000_000f64 / update_fps as f64).round() as u64
),
}
}
pub fn update(&mut self) {
// dbg!(self.ctx.screen.width() * self.ctx.screen.height());
let mut buffer1 = [Rgba::from((0, 0, 0, 0)); 614400];
loop {
self.current_time = Instant::now();
let dt = self.current_time - self.last_time;
self.last_time = self.current_time;
if dt < self.update_timestep {
sleep(self.update_timestep - dt);
}
self.ctx.input.handle_event();
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,
})
.unwrap();
}
if self.ctx.input.is_just_released(KeyCode::BTN_TOUCH) {
self.window
.try_dispatch_event(WindowEvent::PointerReleased {
position: LogicalPosition::new(
self.ctx.input.x as f32,
self.ctx.input.y as f32,
),
button: slint::platform::PointerEventButton::Left,
})
.unwrap();
}
self.window.draw_if_needed(|renderer| {
dbg!("Rendering");
renderer.render(&mut buffer1, self.ctx.screen.width() as usize);
// self.ctx
// .screen
// .fill_contiguous(&self.ctx.screen.rect(), buffer1)
// .ok();
});
self.ctx.screen.flush();
self.ctx.input.finish();
}
Self { window }
}
}
@@ -112,5 +36,49 @@ impl Platform for Trekstor {
) -> Result<Rc<dyn slint::platform::WindowAdapter>, slint::PlatformError> {
Ok(self.window.clone())
}
// ..
fn run_event_loop(&self) -> Result<(), slint::PlatformError> {
let screen = Screen::new();
let input = InputState::new(&screen);
let mut ctx = Context { screen, input };
let mut buffer1 = [Rgba::from((0, 0, 0, 0)); 614400];
loop {
ctx.input.handle_event();
slint::platform::update_timers_and_animations();
if ctx.input.is_just_pressed(KeyCode::BTN_TOUCH) {
self.window
.try_dispatch_event(WindowEvent::PointerPressed {
position: LogicalPosition::new(ctx.input.x as f32, ctx.input.y as f32),
button: slint::platform::PointerEventButton::Left,
})
.unwrap();
}
if ctx.input.is_just_released(KeyCode::BTN_TOUCH) {
self.window
.try_dispatch_event(WindowEvent::PointerReleased {
position: LogicalPosition::new(ctx.input.x as f32, ctx.input.y as f32),
button: slint::platform::PointerEventButton::Left,
})
.unwrap();
}
self.window.draw_if_needed(|renderer| {
dbg!("Rendering");
renderer.render(&mut buffer1, ctx.screen.width() as usize);
// ctx
// .screen
// .fill_contiguous(&ctx.screen.rect(), buffer1)
// .ok();
});
ctx.screen.flush();
ctx.input.finish();
}
}
}

View File

@@ -9,6 +9,7 @@ pub struct Screen {
height: u32,
}
#[allow(unused)]
impl Screen {
pub fn new() -> Self {
let framebuffer = Framebuffer::open().expect("Failed to open framebuffer");

View File

@@ -1,6 +1,6 @@
import { AboutSlint, Button, VerticalBox } from "std-widgets.slint";
export component Demo {
export component AppWindow inherits Window {
VerticalBox {
alignment: start;
Text {