Add error popups to room UI
This commit is contained in:
parent
ded927b9f0
commit
ab36df3c2b
4 changed files with 96 additions and 18 deletions
|
|
@ -1,13 +1,25 @@
|
|||
use async_trait::async_trait;
|
||||
use crossterm::style::ContentStyle;
|
||||
use toss::frame::{Frame, Pos, Size};
|
||||
|
||||
use super::{BoxedWidget, Widget};
|
||||
|
||||
pub struct Border(BoxedWidget);
|
||||
pub struct Border {
|
||||
inner: BoxedWidget,
|
||||
style: ContentStyle,
|
||||
}
|
||||
|
||||
impl Border {
|
||||
pub fn new<W: Into<BoxedWidget>>(inner: W) -> Self {
|
||||
Self(inner.into())
|
||||
Self {
|
||||
inner: inner.into(),
|
||||
style: ContentStyle::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn style(mut self, style: ContentStyle) -> Self {
|
||||
self.style = style;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -16,7 +28,7 @@ impl Widget for Border {
|
|||
fn size(&self, frame: &mut Frame, max_width: Option<u16>, max_height: Option<u16>) -> Size {
|
||||
let max_width = max_width.map(|w| w.saturating_sub(2));
|
||||
let max_height = max_height.map(|h| h.saturating_sub(2));
|
||||
let size = self.0.size(frame, max_width, max_height);
|
||||
let size = self.inner.size(frame, max_width, max_height);
|
||||
size + Size::new(2, 2)
|
||||
}
|
||||
|
||||
|
|
@ -27,23 +39,23 @@ impl Widget for Border {
|
|||
|
||||
let right = size.width as i32 - 1;
|
||||
let bottom = size.height as i32 - 1;
|
||||
frame.write(Pos::new(0, 0), "┌");
|
||||
frame.write(Pos::new(right, 0), "┐");
|
||||
frame.write(Pos::new(0, bottom), "└");
|
||||
frame.write(Pos::new(right, bottom), "┘");
|
||||
frame.write(Pos::new(0, 0), ("┌", self.style));
|
||||
frame.write(Pos::new(right, 0), ("┐", self.style));
|
||||
frame.write(Pos::new(0, bottom), ("└", self.style));
|
||||
frame.write(Pos::new(right, bottom), ("┘", self.style));
|
||||
|
||||
for y in 1..bottom {
|
||||
frame.write(Pos::new(0, y), "│");
|
||||
frame.write(Pos::new(right, y), "│");
|
||||
frame.write(Pos::new(0, y), ("│", self.style));
|
||||
frame.write(Pos::new(right, y), ("│", self.style));
|
||||
}
|
||||
|
||||
for x in 1..right {
|
||||
frame.write(Pos::new(x, 0), "─");
|
||||
frame.write(Pos::new(x, bottom), "─");
|
||||
frame.write(Pos::new(x, 0), ("─", self.style));
|
||||
frame.write(Pos::new(x, bottom), ("─", self.style));
|
||||
}
|
||||
|
||||
frame.push(Pos::new(1, 1), size - Size::new(2, 2));
|
||||
self.0.render(frame).await;
|
||||
self.inner.render(frame).await;
|
||||
frame.pop();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue