1786013766
This commit is contained in:
10
src/main.rs
10
src/main.rs
@@ -3,10 +3,14 @@ mod trekstor;
|
|||||||
|
|
||||||
use crate::trekstor::Trekstor;
|
use crate::trekstor::Trekstor;
|
||||||
|
|
||||||
fn main() {
|
slint::include_modules!();
|
||||||
let mut trekstor = Trekstor::new(30);
|
|
||||||
|
|
||||||
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 red = (255, 0, 0, 255);
|
||||||
// let green = (0, 255, 0, 255);
|
// let green = (0, 255, 0, 255);
|
||||||
|
|||||||
126
src/trekstor.rs
126
src/trekstor.rs
@@ -1,8 +1,5 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::thread::sleep;
|
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
|
|
||||||
use embedded_graphics::prelude::DrawTarget;
|
|
||||||
use evdev::KeyCode;
|
use evdev::KeyCode;
|
||||||
use slint::LogicalPosition;
|
use slint::LogicalPosition;
|
||||||
use slint::platform::software_renderer::{MinimalSoftwareWindow, RepaintBufferType};
|
use slint::platform::software_renderer::{MinimalSoftwareWindow, RepaintBufferType};
|
||||||
@@ -22,87 +19,14 @@ pub struct Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Trekstor {
|
pub struct Trekstor {
|
||||||
ctx: Context,
|
|
||||||
window: Rc<MinimalSoftwareWindow>,
|
window: Rc<MinimalSoftwareWindow>,
|
||||||
// buffer: Vec<Rgba8Pixel>,
|
|
||||||
last_time: Instant,
|
|
||||||
current_time: Instant,
|
|
||||||
update_timestep: Duration,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Trekstor {
|
impl Trekstor {
|
||||||
pub fn new(update_fps: i32) -> Self {
|
pub fn new() -> Self {
|
||||||
let screen = Screen::new();
|
|
||||||
let input = InputState::new(&screen);
|
|
||||||
let window = MinimalSoftwareWindow::new(RepaintBufferType::ReusedBuffer);
|
let window = MinimalSoftwareWindow::new(RepaintBufferType::ReusedBuffer);
|
||||||
|
|
||||||
Self {
|
Self { window }
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,5 +36,49 @@ impl Platform for Trekstor {
|
|||||||
) -> Result<Rc<dyn slint::platform::WindowAdapter>, slint::PlatformError> {
|
) -> Result<Rc<dyn slint::platform::WindowAdapter>, slint::PlatformError> {
|
||||||
Ok(self.window.clone())
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ pub struct Screen {
|
|||||||
height: u32,
|
height: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
impl Screen {
|
impl Screen {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let framebuffer = Framebuffer::open().expect("Failed to open framebuffer");
|
let framebuffer = Framebuffer::open().expect("Failed to open framebuffer");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { AboutSlint, Button, VerticalBox } from "std-widgets.slint";
|
import { AboutSlint, Button, VerticalBox } from "std-widgets.slint";
|
||||||
|
|
||||||
export component Demo {
|
export component AppWindow inherits Window {
|
||||||
VerticalBox {
|
VerticalBox {
|
||||||
alignment: start;
|
alignment: start;
|
||||||
Text {
|
Text {
|
||||||
|
|||||||
Reference in New Issue
Block a user