Migrate room popups to AsyncWidget
This commit is contained in:
parent
31c8453a83
commit
b8da97aaa4
2 changed files with 12 additions and 17 deletions
|
|
@ -1,37 +1,33 @@
|
||||||
use crossterm::style::Stylize;
|
use crossterm::style::Stylize;
|
||||||
use toss::{Style, Styled};
|
use toss::widgets::{BoxedAsync, Text};
|
||||||
|
use toss::{Style, Styled, WidgetExt};
|
||||||
|
|
||||||
use crate::ui::widgets::float::Float;
|
use crate::ui::widgets2::Popup;
|
||||||
use crate::ui::widgets::popup::Popup;
|
use crate::ui::UiError;
|
||||||
use crate::ui::widgets::text::Text;
|
|
||||||
use crate::ui::widgets::BoxedWidget;
|
|
||||||
|
|
||||||
pub enum RoomPopup {
|
pub enum RoomPopup {
|
||||||
Error { description: String, reason: String },
|
Error { description: String, reason: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RoomPopup {
|
impl RoomPopup {
|
||||||
fn server_error_widget(description: &str, reason: &str) -> BoxedWidget {
|
fn server_error_widget(description: &str, reason: &str) -> BoxedAsync<'static, UiError> {
|
||||||
let border_style = Style::new().red().bold();
|
let border_style = Style::new().red().bold();
|
||||||
let text = Styled::new_plain(description)
|
let text = Styled::new_plain(description)
|
||||||
.then_plain("\n\n")
|
.then_plain("\n\n")
|
||||||
.then("Reason:", Style::new().bold())
|
.then("Reason:", Style::new().bold())
|
||||||
.then_plain(" ")
|
.then_plain(" ")
|
||||||
.then_plain(reason);
|
.then_plain(reason);
|
||||||
Popup::new(Text::new(text))
|
Popup::new(Text::new(text), ("Error", border_style))
|
||||||
.title(("Error", border_style))
|
.with_border_style(border_style)
|
||||||
.border(border_style)
|
.boxed_async()
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn widget(&self) -> BoxedWidget {
|
pub fn widget(&self) -> BoxedAsync<'static, UiError> {
|
||||||
let widget = match self {
|
match self {
|
||||||
Self::Error {
|
Self::Error {
|
||||||
description,
|
description,
|
||||||
reason,
|
reason,
|
||||||
} => Self::server_error_widget(description, reason),
|
} => Self::server_error_widget(description, reason),
|
||||||
};
|
}
|
||||||
|
|
||||||
Float::new(widget).horizontal(0.5).vertical(0.5).into()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ use crate::euph;
|
||||||
use crate::macros::logging_unwrap;
|
use crate::macros::logging_unwrap;
|
||||||
use crate::ui::chat2::{ChatState, Reaction};
|
use crate::ui::chat2::{ChatState, Reaction};
|
||||||
use crate::ui::input::{key, InputEvent, KeyBindingsList};
|
use crate::ui::input::{key, InputEvent, KeyBindingsList};
|
||||||
use crate::ui::widgets::WidgetWrapper;
|
|
||||||
use crate::ui::widgets2::ListState;
|
use crate::ui::widgets2::ListState;
|
||||||
use crate::ui::{util2, UiError, UiEvent};
|
use crate::ui::{util2, UiError, UiEvent};
|
||||||
use crate::vault::EuphRoomVault;
|
use crate::vault::EuphRoomVault;
|
||||||
|
|
@ -233,7 +232,7 @@ impl EuphRoom {
|
||||||
}
|
}
|
||||||
|
|
||||||
for popup in &self.popups {
|
for popup in &self.popups {
|
||||||
layers.push(WidgetWrapper::new(popup.widget()).boxed_async());
|
layers.push(popup.widget());
|
||||||
}
|
}
|
||||||
|
|
||||||
Layer::new(layers).boxed_async()
|
Layer::new(layers).boxed_async()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue