Try to draw simple "Hello world!"
This commit is contained in:
parent
13ed6ef3e3
commit
6ab43a8d5e
6 changed files with 47 additions and 8 deletions
|
|
@ -7,6 +7,7 @@ edition.workspace = true
|
|||
anyhow.workspace = true
|
||||
axum = "0.7.4"
|
||||
clap = { version = "4.5.1", features = ["derive", "deprecated"] }
|
||||
cosmic-text.workspace = true
|
||||
escpos = { version = "0.7.2", features = ["full"] }
|
||||
image.workspace = true
|
||||
palette.workspace = true
|
||||
|
|
|
|||
|
|
@ -1,3 +1,10 @@
|
|||
use cosmic_text::{Attrs, Metrics};
|
||||
use palette::Srgb;
|
||||
use showbits_common::{
|
||||
widgets::{FontStuff, HasFontStuff, Text},
|
||||
Tree, WidgetExt,
|
||||
};
|
||||
use taffy::style_helpers::length;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::printer::Printer;
|
||||
|
|
@ -10,14 +17,30 @@ pub enum Command {
|
|||
ChatMessage { username: String, content: String },
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Context {
|
||||
font_stuff: FontStuff,
|
||||
}
|
||||
|
||||
impl HasFontStuff for Context {
|
||||
fn font_stuff(&mut self) -> &mut FontStuff {
|
||||
&mut self.font_stuff
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Drawer {
|
||||
rx: mpsc::Receiver<Command>,
|
||||
printer: Printer,
|
||||
ctx: Context,
|
||||
}
|
||||
|
||||
impl Drawer {
|
||||
pub fn new(rx: mpsc::Receiver<Command>, printer: Printer) -> Self {
|
||||
Self { rx, printer }
|
||||
Self {
|
||||
rx,
|
||||
printer,
|
||||
ctx: Context::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(&mut self) -> anyhow::Result<()> {
|
||||
|
|
@ -35,17 +58,30 @@ impl Drawer {
|
|||
match command {
|
||||
Command::Stop => {} // Already handled one level above
|
||||
Command::Rip => self.printer.rip()?,
|
||||
Command::Test => todo!(),
|
||||
Command::Test => self.on_test()?,
|
||||
Command::Text(_) => todo!(),
|
||||
Command::ChatMessage { username, content } => todo!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// fn on_rip(&mut self) -> anyhow::Result<()> {
|
||||
// self.printer.init()?.feeds(6)?.print()?;
|
||||
// Ok(())
|
||||
// }
|
||||
fn on_test(&mut self) -> anyhow::Result<()> {
|
||||
let mut tree = Tree::<Context>::new();
|
||||
|
||||
let root = Text::simple(
|
||||
&mut self.ctx.font_stuff,
|
||||
Metrics::new(16.0, 32.0),
|
||||
Attrs::new(),
|
||||
"Hello world!",
|
||||
)
|
||||
.color(Srgb::new(1.0, 1.0, 1.0))
|
||||
.node()
|
||||
.margin_all(length(10.0))
|
||||
.register(&mut tree)?;
|
||||
|
||||
self.printer.print_tree(&mut tree, &mut self.ctx, root)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// fn on_text(&mut self, text: String) -> anyhow::Result<()> {
|
||||
// let text = util::sanitize(&text);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue