Turn Text into drawing
This commit is contained in:
parent
dddef6b3b5
commit
0bc2942b2b
3 changed files with 36 additions and 24 deletions
|
|
@ -1,5 +1,6 @@
|
|||
mod calendar;
|
||||
mod cells;
|
||||
mod text;
|
||||
|
||||
use image::{Luma, Pixel, RgbaImage};
|
||||
use palette::{FromColor, IntoColor, LinLumaa};
|
||||
|
|
@ -16,7 +17,7 @@ use tokio::sync::mpsc;
|
|||
|
||||
use crate::printer::Printer;
|
||||
|
||||
pub use self::{calendar::CalendarDrawing, cells::CellsDrawing};
|
||||
pub use self::{calendar::CalendarDrawing, cells::CellsDrawing, text::TextDrawing};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Context {
|
||||
|
|
@ -32,7 +33,6 @@ pub struct BoxedDrawing(Box<dyn Drawing + Send>);
|
|||
pub enum Command {
|
||||
Draw(BoxedDrawing),
|
||||
|
||||
Text(String),
|
||||
Image { image: RgbaImage, bright: bool },
|
||||
Photo { image: RgbaImage, title: String },
|
||||
ChatMessage { username: String, content: String },
|
||||
|
|
@ -78,7 +78,6 @@ impl Drawer {
|
|||
match command {
|
||||
Command::Draw(drawing) => drawing.0.draw(&mut self.printer, &mut self.ctx)?,
|
||||
|
||||
Command::Text(text) => self.on_text(text)?,
|
||||
Command::Image { image, bright } => self.on_image(image, bright)?,
|
||||
Command::Photo { image, title } => self.on_photo(image, title)?,
|
||||
Command::ChatMessage { username, content } => {
|
||||
|
|
@ -88,25 +87,6 @@ impl Drawer {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn on_text(&mut self, text: String) -> anyhow::Result<()> {
|
||||
let mut tree = Tree::<Context>::new(WHITE);
|
||||
|
||||
let text = Text::new()
|
||||
.with_metrics(Text::default_metrics().scale(2.0))
|
||||
.and_plain(text)
|
||||
.widget(&mut self.ctx.font_stuff)
|
||||
.node()
|
||||
.register(&mut tree)?;
|
||||
|
||||
let root = Node::empty()
|
||||
.with_size_width(percent(1.0))
|
||||
.and_child(text)
|
||||
.register(&mut tree)?;
|
||||
|
||||
self.printer.print_tree(&mut tree, &mut self.ctx, root)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn on_image(&mut self, mut image: RgbaImage, bright: bool) -> anyhow::Result<()> {
|
||||
let mut tree = Tree::<Context>::new(WHITE);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue