Files
dashboard/src/trekstor.rs
2026-08-06 13:40:18 +02:00

105 lines
3.2 KiB
Rust

use std::rc::Rc;
use evdev::KeyCode;
use linfb::shape::Color;
use slint::platform::software_renderer::{MinimalSoftwareWindow, RepaintBufferType, Rgb565Pixel};
use slint::platform::{Platform, WindowEvent};
use slint::{LogicalPosition, Rgb8Pixel};
use self::input::InputState;
use self::screen::Screen;
mod input;
mod screen;
pub struct Context {
pub screen: Screen,
pub input: InputState,
}
pub struct Trekstor {
window: Rc<MinimalSoftwareWindow>,
}
impl Trekstor {
pub fn new() -> Self {
let window = MinimalSoftwareWindow::new(RepaintBufferType::ReusedBuffer);
Self { window }
}
}
impl Platform for Trekstor {
fn create_window_adapter(
&self,
) -> 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 = [Rgb565Pixel(0); 614400];
let window_width = ctx.screen.width() - 1;
// let window_height = ctx.screen.height() - 1;
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, window_width as usize);
for (i, px) in buffer1.into_iter().enumerate() {
// if i > (window_width as usize - 1) {
// break;
// }
let x = (i % window_width as usize) as u32;
let y = (i / window_width as usize) as u32;
// // if x >= window_width || y >= window_height {
// // println!("Out of bounds {} {}", x, y);
// // continue;
// // }
let pixel = Rgb8Pixel::from(px);
dbg!(x, y, Color::from((pixel.r, pixel.g, pixel.b, 255)));
// // ctx.screen.framebuffer.set_pixel(
// // x,
// // y,
// // Color::from((px.r(), px.b(), px.b(), px.a())),
// // );
}
ctx.screen.flush();
});
ctx.input.finish();
}
}
}