Try to draw simple "Hello world!"
This commit is contained in:
parent
13ed6ef3e3
commit
6ab43a8d5e
6 changed files with 47 additions and 8 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1173,6 +1173,7 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"axum",
|
"axum",
|
||||||
"clap",
|
"clap",
|
||||||
|
"cosmic-text",
|
||||||
"escpos",
|
"escpos",
|
||||||
"image",
|
"image",
|
||||||
"palette",
|
"palette",
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ edition = "2021"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
anyhow = "1.0.80"
|
anyhow = "1.0.80"
|
||||||
|
cosmic-text = "0.11.2"
|
||||||
image = "0.24.9"
|
image = "0.24.9"
|
||||||
palette = "0.7.5"
|
palette = "0.7.5"
|
||||||
showbits-common.path = "./showbits-common"
|
showbits-common.path = "./showbits-common"
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ edition.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
cosmic-text = "0.11.2"
|
cosmic-text.workspace = true
|
||||||
image.workspace = true
|
image.workspace = true
|
||||||
palette.workspace = true
|
palette.workspace = true
|
||||||
taffy.workspace = true
|
taffy.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,6 @@ impl<C: HasFontStuff> Widget<C> for Text {
|
||||||
view.rect(area, color);
|
view.rect(area, color);
|
||||||
});
|
});
|
||||||
|
|
||||||
todo!()
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ edition.workspace = true
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
axum = "0.7.4"
|
axum = "0.7.4"
|
||||||
clap = { version = "4.5.1", features = ["derive", "deprecated"] }
|
clap = { version = "4.5.1", features = ["derive", "deprecated"] }
|
||||||
|
cosmic-text.workspace = true
|
||||||
escpos = { version = "0.7.2", features = ["full"] }
|
escpos = { version = "0.7.2", features = ["full"] }
|
||||||
image.workspace = true
|
image.workspace = true
|
||||||
palette.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 tokio::sync::mpsc;
|
||||||
|
|
||||||
use crate::printer::Printer;
|
use crate::printer::Printer;
|
||||||
|
|
@ -10,14 +17,30 @@ pub enum Command {
|
||||||
ChatMessage { username: String, content: String },
|
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 {
|
pub struct Drawer {
|
||||||
rx: mpsc::Receiver<Command>,
|
rx: mpsc::Receiver<Command>,
|
||||||
printer: Printer,
|
printer: Printer,
|
||||||
|
ctx: Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drawer {
|
impl Drawer {
|
||||||
pub fn new(rx: mpsc::Receiver<Command>, printer: Printer) -> Self {
|
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<()> {
|
pub fn run(&mut self) -> anyhow::Result<()> {
|
||||||
|
|
@ -35,17 +58,30 @@ impl Drawer {
|
||||||
match command {
|
match command {
|
||||||
Command::Stop => {} // Already handled one level above
|
Command::Stop => {} // Already handled one level above
|
||||||
Command::Rip => self.printer.rip()?,
|
Command::Rip => self.printer.rip()?,
|
||||||
Command::Test => todo!(),
|
Command::Test => self.on_test()?,
|
||||||
Command::Text(_) => todo!(),
|
Command::Text(_) => todo!(),
|
||||||
Command::ChatMessage { username, content } => todo!(),
|
Command::ChatMessage { username, content } => todo!(),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn on_rip(&mut self) -> anyhow::Result<()> {
|
fn on_test(&mut self) -> anyhow::Result<()> {
|
||||||
// self.printer.init()?.feeds(6)?.print()?;
|
let mut tree = Tree::<Context>::new();
|
||||||
// Ok(())
|
|
||||||
// }
|
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<()> {
|
// fn on_text(&mut self, text: String) -> anyhow::Result<()> {
|
||||||
// let text = util::sanitize(&text);
|
// let text = util::sanitize(&text);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue