Add error popups to room UI

This commit is contained in:
Joscha 2022-08-20 19:39:28 +02:00
parent ded927b9f0
commit ab36df3c2b
4 changed files with 96 additions and 18 deletions

40
src/ui/euph/popup.rs Normal file
View file

@ -0,0 +1,40 @@
use crossterm::style::{ContentStyle, Stylize};
use toss::styled::Styled;
use crate::ui::widgets::background::Background;
use crate::ui::widgets::border::Border;
use crate::ui::widgets::layer::Layer;
use crate::ui::widgets::padding::Padding;
use crate::ui::widgets::text::Text;
use crate::ui::widgets::BoxedWidget;
pub enum Popup {
ServerError { description: String, reason: String },
}
impl Popup {
fn server_error_widget(description: &str, reason: &str) -> BoxedWidget {
let border_style = ContentStyle::default().red().bold();
let text = Styled::new_plain(description)
.then_plain("\n\n")
.then_plain(reason);
Layer::new(vec![
Padding::new(Text::new(("Error", border_style)))
.horizontal(1)
.into(),
Border::new(Background::new(Text::new(text)))
.style(border_style)
.into(),
])
.into()
}
pub fn widget(&self) -> BoxedWidget {
match self {
Self::ServerError {
description,
reason,
} => Self::server_error_widget(description, reason),
}
}
}