Initial commit
This commit is contained in:
12
crates/ui/Cargo.toml
Normal file
12
crates/ui/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "ui"
|
||||
edition.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
mousefood.workspace = true
|
||||
ratatui.workspace = true
|
||||
embedded-graphics.workspace = true
|
||||
35
crates/ui/src/lib.rs
Normal file
35
crates/ui/src/lib.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
#![doc = "Shared UI helpers for firmware and simulator."]
|
||||
|
||||
use std::error::Error;
|
||||
|
||||
use embedded_graphics::prelude::{Dimensions, DrawTarget};
|
||||
use mousefood::prelude::*;
|
||||
use ratatui::{
|
||||
Terminal,
|
||||
style::Stylize,
|
||||
widgets::{Block, Paragraph},
|
||||
};
|
||||
|
||||
/// Returns the first shared text used by the simulator experiment.
|
||||
#[must_use]
|
||||
pub const fn hello_world() -> &'static str {
|
||||
"Hello, world from Ratatui"
|
||||
}
|
||||
|
||||
pub fn start_ui<D>(display: &mut D) -> Result<(), Box<dyn Error>>
|
||||
where
|
||||
D: DrawTarget<Color = Rgb888> + Dimensions + 'static,
|
||||
{
|
||||
let backend = EmbeddedBackend::new(display, EmbeddedBackendConfig::default());
|
||||
let mut terminal = Terminal::new(backend)?;
|
||||
|
||||
terminal.draw(|frame| {
|
||||
let widget = Paragraph::new(crate::hello_world().bold().yellow())
|
||||
.block(Block::bordered().title("Vaka"))
|
||||
.centered();
|
||||
|
||||
frame.render_widget(widget, frame.area());
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user