refactor: add error field and display

This commit is contained in:
electria 2026-07-01 09:36:46 -07:00
commit ad0b37d0c3
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -19,6 +19,8 @@ enum Message {
struct State {
image: Option<RgbaImage>,
image_display: Option<widget::image::Allocation>,
error: Option<String>,
}
impl State {
fn new() -> (Self, Task<Message>) {
@ -33,25 +35,35 @@ impl State {
.into_rgba8(),
)
}),
error: None,
};
let allocate_image = state.allocate_image();
(state, allocate_image)
}
fn view(&self) -> Element<'_, Message, Theme, Renderer> {
if let Some(allocation) = self.image_display.as_ref() {
widget::image::viewer(allocation.handle().clone())
.width(Length::Fill)
.height(Length::Fill)
.into()
} else {
widget::container(widget::text(include_str!("usage.txt")))
.height(Length::Fill)
.width(Length::Fill)
.align_x(Alignment::Center)
.align_y(Alignment::Center)
.into()
}
widget::column([
if let Some(allocation) = self.image_display.as_ref() {
widget::image::viewer(allocation.handle().clone())
.width(Length::Fill)
.height(Length::Fill)
.into()
} else {
widget::container(widget::text(include_str!("usage.txt")))
.height(Length::Fill)
.width(Length::Fill)
.align_x(Alignment::Center)
.align_y(Alignment::Center)
.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> {
match message {