Fix rendering of editor and pseudo message
This commit is contained in:
parent
e6e6bcaf31
commit
18573e5a37
4 changed files with 53 additions and 27 deletions
|
|
@ -4,11 +4,12 @@ use time::macros::format_description;
|
|||
use time::OffsetDateTime;
|
||||
|
||||
use crate::ui::widgets::background::Background;
|
||||
use crate::ui::widgets::empty::Empty;
|
||||
use crate::ui::widgets::text::Text;
|
||||
use crate::ui::widgets::BoxedWidget;
|
||||
|
||||
const TIME_FORMAT: &[FormatItem<'_>] = format_description!("[year]-[month]-[day] [hour]:[minute]");
|
||||
const TIME_EMPTY: &str = " ";
|
||||
const TIME_WIDTH: u16 = 16;
|
||||
|
||||
fn style() -> ContentStyle {
|
||||
ContentStyle::default().grey()
|
||||
|
|
@ -19,19 +20,20 @@ fn style_inverted() -> ContentStyle {
|
|||
}
|
||||
|
||||
pub fn widget(time: Option<OffsetDateTime>, highlighted: bool) -> BoxedWidget {
|
||||
let text = if let Some(time) = time {
|
||||
time.format(TIME_FORMAT).expect("could not format time")
|
||||
} else {
|
||||
TIME_EMPTY.to_string()
|
||||
};
|
||||
|
||||
let style = if highlighted {
|
||||
style_inverted()
|
||||
} else {
|
||||
style()
|
||||
};
|
||||
|
||||
Background::new(Text::new((text, style)))
|
||||
.style(style)
|
||||
.into()
|
||||
if let Some(time) = time {
|
||||
let text = time.format(TIME_FORMAT).expect("could not format time");
|
||||
Background::new(Text::new((text, style)))
|
||||
.style(style)
|
||||
.into()
|
||||
} else {
|
||||
Background::new(Empty::new().width(TIME_WIDTH))
|
||||
.style(style)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue