refactor: simplify view code
This commit is contained in:
parent
88e0086db3
commit
4333248ecc
1 changed files with 13 additions and 17 deletions
30
src/main.rs
30
src/main.rs
|
|
@ -68,10 +68,8 @@ impl State {
|
|||
let main = self.image_display.as_ref().map_or_else(
|
||||
|| {
|
||||
widget::container(widget::text(include_str!("usage.txt")))
|
||||
.height(Length::Fill)
|
||||
.width(Length::Fill)
|
||||
.align_x(Alignment::Center)
|
||||
.align_y(Alignment::Center)
|
||||
.center_x(Length::Fill)
|
||||
.center_y(Length::Fill)
|
||||
.boxed()
|
||||
},
|
||||
|allocation| {
|
||||
|
|
@ -85,20 +83,18 @@ impl State {
|
|||
},
|
||||
);
|
||||
|
||||
let mut bar = Vec::new();
|
||||
if let Some(error) = self.error.as_ref() {
|
||||
bar.push(widget::text(error).style(widget::text::danger).boxed());
|
||||
}
|
||||
if self.infobar_shown && self.info.is_some() {
|
||||
bar.push(
|
||||
widget::container(widget::text(self.title()))
|
||||
.align_x(Alignment::End)
|
||||
.width(Length::Fill)
|
||||
.boxed(),
|
||||
);
|
||||
}
|
||||
let error = self
|
||||
.error
|
||||
.as_ref()
|
||||
.map(|error| widget::text(error).style(widget::text::danger));
|
||||
|
||||
widget::column([main, widget::row(bar).boxed()])
|
||||
let info = (self.infobar_shown && self.info.is_some()).then(|| {
|
||||
widget::container(widget::text(self.title()))
|
||||
.align_x(Alignment::End)
|
||||
.width(Length::Fill)
|
||||
});
|
||||
|
||||
widget::column![main, widget::row![error, info]]
|
||||
}
|
||||
fn update(&mut self, message: Message) -> Task<Message> {
|
||||
match message {
|
||||
|
|
|
|||
Loading…
Reference in a new issue