refactor: add error field and display
This commit is contained in:
parent
c8810f3e86
commit
ad0b37d0c3
1 changed files with 25 additions and 13 deletions
14
src/main.rs
14
src/main.rs
|
|
@ -19,6 +19,8 @@ enum Message {
|
||||||
struct State {
|
struct State {
|
||||||
image: Option<RgbaImage>,
|
image: Option<RgbaImage>,
|
||||||
image_display: Option<widget::image::Allocation>,
|
image_display: Option<widget::image::Allocation>,
|
||||||
|
|
||||||
|
error: Option<String>,
|
||||||
}
|
}
|
||||||
impl State {
|
impl State {
|
||||||
fn new() -> (Self, Task<Message>) {
|
fn new() -> (Self, Task<Message>) {
|
||||||
|
|
@ -33,12 +35,15 @@ impl State {
|
||||||
.into_rgba8(),
|
.into_rgba8(),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
error: None,
|
||||||
};
|
};
|
||||||
let allocate_image = state.allocate_image();
|
let allocate_image = state.allocate_image();
|
||||||
|
|
||||||
(state, allocate_image)
|
(state, allocate_image)
|
||||||
}
|
}
|
||||||
fn view(&self) -> Element<'_, Message, Theme, Renderer> {
|
fn view(&self) -> Element<'_, Message, Theme, Renderer> {
|
||||||
|
widget::column([
|
||||||
if let Some(allocation) = self.image_display.as_ref() {
|
if let Some(allocation) = self.image_display.as_ref() {
|
||||||
widget::image::viewer(allocation.handle().clone())
|
widget::image::viewer(allocation.handle().clone())
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
|
|
@ -51,7 +56,14 @@ impl State {
|
||||||
.align_x(Alignment::Center)
|
.align_x(Alignment::Center)
|
||||||
.align_y(Alignment::Center)
|
.align_y(Alignment::Center)
|
||||||
.into()
|
.into()
|
||||||
}
|
},
|
||||||
|
if let Some(error) = self.error.as_ref() {
|
||||||
|
widget::text(error).style(widget::text::danger).into()
|
||||||
|
} else {
|
||||||
|
widget::space().into()
|
||||||
|
},
|
||||||
|
])
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
fn update(&mut self, message: Message) -> Task<Message> {
|
fn update(&mut self, message: Message) -> Task<Message> {
|
||||||
match message {
|
match message {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue