Reimplement chat message command
This commit is contained in:
parent
5cdc62bd29
commit
9ebcabbf36
2 changed files with 54 additions and 21 deletions
|
|
@ -103,4 +103,8 @@ impl<C> Tree<C> {
|
||||||
|
|
||||||
Ok(image)
|
Ok(image)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn print_debug(&mut self, root: NodeId) {
|
||||||
|
self.tree.print_tree(root)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,10 @@ use showbits_common::{
|
||||||
widgets::{Block, FontStuff, HasFontStuff, Text},
|
widgets::{Block, FontStuff, HasFontStuff, Text},
|
||||||
Node, Tree, WidgetExt,
|
Node, Tree, WidgetExt,
|
||||||
};
|
};
|
||||||
use taffy::style_helpers::{length, percent};
|
use taffy::{
|
||||||
|
style_helpers::{length, percent},
|
||||||
|
AlignItems, FlexDirection,
|
||||||
|
};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use crate::printer::Printer;
|
use crate::printer::Printer;
|
||||||
|
|
@ -59,7 +62,9 @@ impl Drawer {
|
||||||
Command::Rip => self.printer.rip()?,
|
Command::Rip => self.printer.rip()?,
|
||||||
Command::Test => self.on_test()?,
|
Command::Test => self.on_test()?,
|
||||||
Command::Text(text) => self.on_text(text)?,
|
Command::Text(text) => self.on_text(text)?,
|
||||||
Command::ChatMessage { username, content } => todo!(),
|
Command::ChatMessage { username, content } => {
|
||||||
|
self.on_chat_message(username, content)?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -115,27 +120,51 @@ impl Drawer {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn on_chat_message(&mut self, username: String, content: String) -> anyhow::Result<()> {
|
fn on_chat_message(&mut self, username: String, content: String) -> anyhow::Result<()> {
|
||||||
// let username = util::sanitize(&username);
|
let mut tree = Tree::<Context>::new(WHITE);
|
||||||
// let content = util::sanitize(&content);
|
|
||||||
|
|
||||||
// let username = username
|
let max_username_width_in_chars = 12.0;
|
||||||
// .chars()
|
let max_content_height_in_lines = 16.0;
|
||||||
// .map(|c| if c.is_ascii_whitespace() { '_' } else { c })
|
|
||||||
// .take(16)
|
|
||||||
// .collect::<String>();
|
|
||||||
|
|
||||||
// let content = content.chars().take(300).collect::<String>();
|
let username = Text::new()
|
||||||
|
.and_plain(username)
|
||||||
|
.widget(&mut self.ctx.font_stuff)
|
||||||
|
.node()
|
||||||
|
.with_max_size_width(length(max_username_width_in_chars * 8.0))
|
||||||
|
.register(&mut tree)?;
|
||||||
|
|
||||||
// self.printer
|
let username = Block::new()
|
||||||
// .init()?
|
.with_border(BLACK)
|
||||||
// .reverse(true)?
|
.node()
|
||||||
// .write(&username)?
|
.with_border_all(length(1.0))
|
||||||
// .reverse(false)?
|
.with_padding_horiz(length(1.0))
|
||||||
// .write(" ")?
|
.with_flex_shrink(0.0) // Avoid wrapping
|
||||||
// .writeln(&content)?
|
.and_child(username)
|
||||||
// .print()?;
|
.register(&mut tree)?;
|
||||||
|
|
||||||
// Ok(())
|
let content = Text::new()
|
||||||
// }
|
.and_plain(content)
|
||||||
|
.widget(&mut self.ctx.font_stuff)
|
||||||
|
.node()
|
||||||
|
.with_max_size_height(length(max_content_height_in_lines * 16.0))
|
||||||
|
.register(&mut tree)?;
|
||||||
|
|
||||||
|
let content = Node::empty()
|
||||||
|
.with_padding_vert(length(1.0))
|
||||||
|
.and_child(content)
|
||||||
|
.register(&mut tree)?;
|
||||||
|
|
||||||
|
let root = Node::empty()
|
||||||
|
.with_size_width(percent(1.0))
|
||||||
|
.with_padding_vert(length(1.0))
|
||||||
|
.with_flex_direction(FlexDirection::Row)
|
||||||
|
.with_align_items(Some(AlignItems::Start))
|
||||||
|
.with_gap_width(length(4.0))
|
||||||
|
.and_child(username)
|
||||||
|
.and_child(content)
|
||||||
|
.register(&mut tree)?;
|
||||||
|
|
||||||
|
self.printer.print_tree(&mut tree, &mut self.ctx, root)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue