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::{pixelcolor::Rgb888, prelude::Size};
|
||||||
use embedded_graphics_simulator::{
|
use embedded_graphics_simulator::{
|
||||||
OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window,
|
OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window, sdl2::Keycode,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let mut display = SimulatorDisplay::<Rgb888>::new(Size::new(240, 240));
|
let mut display = SimulatorDisplay::<Rgb888>::new(Size::new(240, 240));
|
||||||
|
|
||||||
ui::start_ui(&mut display)?;
|
|
||||||
|
|
||||||
let output_settings = OutputSettingsBuilder::new().scale(2).build();
|
let output_settings = OutputSettingsBuilder::new().scale(2).build();
|
||||||
let mut window = Window::new("Vaka simulator", &output_settings);
|
let mut window = Window::new("Vaka simulator", &output_settings);
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
'running: loop {
|
'running: loop {
|
||||||
window.update(&display);
|
window.update(&display);
|
||||||
|
|
||||||
for event in window.events() {
|
for event in window.events() {
|
||||||
if matches!(event, SimulatorEvent::Quit) {
|
match event {
|
||||||
break 'running;
|
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::{
|
use ratatui::{
|
||||||
Terminal,
|
Terminal,
|
||||||
style::Stylize,
|
style::Stylize,
|
||||||
|
text::Line,
|
||||||
widgets::{Block, Paragraph},
|
widgets::{Block, Paragraph},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ pub const fn hello_world() -> &'static str {
|
|||||||
"Hello, world from Ratatui"
|
"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
|
where
|
||||||
D: DrawTarget<Color = Rgb888> + Dimensions + 'static,
|
D: DrawTarget<Color = Rgb888> + Dimensions + 'static,
|
||||||
{
|
{
|
||||||
@@ -24,7 +25,10 @@ where
|
|||||||
let mut terminal = Terminal::new(backend)?;
|
let mut terminal = Terminal::new(backend)?;
|
||||||
|
|
||||||
terminal.draw(|frame| {
|
terminal.draw(|frame| {
|
||||||
let widget = Paragraph::new(crate::hello_world().bold().yellow())
|
let widget = Paragraph::new(Line::from(vec![
|
||||||
|
crate::hello_world().bold().yellow(),
|
||||||
|
format!(": {i}").into(),
|
||||||
|
]))
|
||||||
.block(Block::bordered().title("Vaka"))
|
.block(Block::bordered().title("Vaka"))
|
||||||
.centered();
|
.centered();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user