Small thingy
This commit is contained in:
@@ -4,23 +4,30 @@ use std::{error::Error, thread, time::Duration};
|
||||
|
||||
use embedded_graphics::{pixelcolor::Rgb888, prelude::Size};
|
||||
use embedded_graphics_simulator::{
|
||||
OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window,
|
||||
OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window, sdl2::Keycode,
|
||||
};
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut display = SimulatorDisplay::<Rgb888>::new(Size::new(240, 240));
|
||||
|
||||
ui::start_ui(&mut display)?;
|
||||
|
||||
let output_settings = OutputSettingsBuilder::new().scale(2).build();
|
||||
let mut window = Window::new("Vaka simulator", &output_settings);
|
||||
|
||||
let mut i = 0;
|
||||
'running: loop {
|
||||
window.update(&display);
|
||||
|
||||
for event in window.events() {
|
||||
if matches!(event, SimulatorEvent::Quit) {
|
||||
break 'running;
|
||||
match event {
|
||||
SimulatorEvent::KeyDown {
|
||||
keycode: Keycode::Return,
|
||||
..
|
||||
} => {
|
||||
i+=1;
|
||||
ui::draw_ui(&mut display, i)?;
|
||||
}
|
||||
SimulatorEvent::Quit => break 'running,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ use mousefood::prelude::*;
|
||||
use ratatui::{
|
||||
Terminal,
|
||||
style::Stylize,
|
||||
text::Line,
|
||||
widgets::{Block, Paragraph},
|
||||
};
|
||||
|
||||
@@ -16,7 +17,7 @@ pub const fn hello_world() -> &'static str {
|
||||
"Hello, world from Ratatui"
|
||||
}
|
||||
|
||||
pub fn start_ui<D>(display: &mut D) -> Result<(), Box<dyn Error>>
|
||||
pub fn draw_ui<D>(display: &mut D, i: usize) -> Result<(), Box<dyn Error>>
|
||||
where
|
||||
D: DrawTarget<Color = Rgb888> + Dimensions + 'static,
|
||||
{
|
||||
@@ -24,9 +25,12 @@ where
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
|
||||
terminal.draw(|frame| {
|
||||
let widget = Paragraph::new(crate::hello_world().bold().yellow())
|
||||
.block(Block::bordered().title("Vaka"))
|
||||
.centered();
|
||||
let widget = Paragraph::new(Line::from(vec![
|
||||
crate::hello_world().bold().yellow(),
|
||||
format!(": {i}").into(),
|
||||
]))
|
||||
.block(Block::bordered().title("Vaka"))
|
||||
.centered();
|
||||
|
||||
frame.render_widget(widget, frame.area());
|
||||
})?;
|
||||
|
||||
Reference in New Issue
Block a user