pub fn update_controls(
    ui: &mut egui::Ui,
    update_state: &mut DeviceUpdateState,
    message_sender: &std::sync::mpsc::Sender<Message>,
) {
    ui.vertical(|ui| {
        ui.set_width(ui.available_width() / 3.0);
        ui.set_height(ui.available_height());

        if update_state.error.is_some() {
            ui.vertical_centered(|ui| {
                ui.add_space(10.0);
                ui.add(egui::Label::new(
                    egui::RichText::new("Error:").color(egui::Color32::RED),
                ));
                ui.add(egui::Label::new(
                    egui::RichText::new(update_state.error.as_ref().unwrap())
                        .color(egui::Color32::RED),
                ));
                ui.add_space(10.0);

                let continue_button =
                    ui.add(egui::widgets::Button::new("Continue").fill(egui::Color32::BLUE));

                if continue_button.clicked() {
                    update_state.error = None;
                };
            });
        } else if update_state.running {
            ui.centered_and_justified(|ui| {
                ui.label("Update in progress...");
            });
        } else if update_state.finished {
            ui.vertical_centered(|ui| {
                ui.add_space(10.0);
                ui.add(egui::Label::new(
                    egui::RichText::new("Update finished successfully.")
                        .color(egui::Color32::GREEN),
                ));
                ui.add_space(10.0);

                let continue_button =
                    ui.add(egui::widgets::Button::new("Continue").fill(egui::Color32::BLUE));

                if continue_button.clicked() {
                    *update_state = DeviceUpdateState::default();
                };
            });
        } else if update_state.device_ready && update_state.file_ready {
            if update_state.preflight_checks_passed {
                ui.vertical_centered(|ui| {
                    ui.add_space(5.0);
                    ui.add(egui::Label::new(
                        egui::RichText::new("Warning! All data on device will be erased!")
                            .color(egui::Color32::YELLOW),
                    ));
                    ui.add_space(10.0);

                    ui.checkbox(&mut update_state.confirmed, "Confirm to proceed.");

                    ui.add_space(10.0);

                    ui.scope(|ui| {
                        ui.set_enabled(update_state.confirmed);
                        let update_button = ui.add(
                            egui::widgets::Button::new("Start update").fill(egui::Color32::BLUE),
                        );

                        if update_button.clicked() {
                            message_sender.send(Message::StartUpdate).ok();
                            update_state.confirmed = false;
                        };
                    });
                });
            } else {
                ui.centered_and_justified(|ui| {
                    ui.add(egui::Label::new(
                        egui::RichText::new(
                            "Some requirements are not met.\nPlease check your settings.",
                        )
                        .color(egui::Color32::RED),
                    ));
                });
            }
        } else {
            ui.centered_and_justified(|ui| {
                ui.add(egui::Label::new(
                    egui::RichText::new("Please select a device and open a file.")
                        .color(egui::Color32::YELLOW),
                ));
            });
        }
    });
}
/// Show update button and additional messages
Show update button and additional messages
Show update button and additional messages
pub fn update_controls(
    ui: &mut egui::Ui,
    update_state: &mut DeviceUpdateState,
    message_sender: &std::sync::mpsc::Sender<Message>,
) {
    ui.vertical(|ui| {
        ui.set_width(ui.available_width() / 3.0);
        ui.set_height(ui.available_height());
        if update_state.error.is_some() {
            ui.vertical_centered(|ui| {
                ui.add_space(10.0);
                ui.add(egui::Label::new(
                    egui::RichText::new("Error:").color(egui::Color32::RED),
                ));
                ui.add(egui::Label::new(
                    egui::RichText::new(update_state.error.as_ref().unwrap())
                        .color(egui::Color32::RED),
                ));
                ui.add_space(10.0);
                let continue_button =
                    ui.add(egui::widgets::Button::new("Continue").fill(egui::Color32::BLUE));
                if continue_button.clicked() {
                    update_state.error = None;
                };
            });
        } else if update_state.running {
            ui.centered_and_justified(|ui| {
                ui.label("Update in progress...");
            });
        } else if update_state.finished {
            ui.vertical_centered(|ui| {
                ui.add_space(10.0);
                ui.add(egui::Label::new(
                    egui::RichText::new("Update finished successfully.")
                        .color(egui::Color32::GREEN),
                ));
                ui.add_space(10.0);
                let continue_button =
                    ui.add(egui::widgets::Button::new("Continue").fill(egui::Color32::BLUE));
                if continue_button.clicked() {
                    *update_state = DeviceUpdateState::default();
                };
            });
        } else if update_state.device_ready && update_state.file_ready {
            if update_state.preflight_checks_passed {
                ui.vertical_centered(|ui| {
                    ui.add_space(5.0);
                    ui.add(egui::Label::new(
                        egui::RichText::new("Warning! All data on device will be erased!")
                            .color(egui::Color32::YELLOW),
                    ));
                    ui.add_space(10.0);
                    ui.checkbox(&mut update_state.confirmed, "Confirm to proceed.");
                    ui.add_space(10.0);
                    ui.scope(|ui| {
                        ui.set_enabled(update_state.confirmed);
                        let update_button = ui.add(
                            egui::widgets::Button::new("Start update").fill(egui::Color32::BLUE),
                        );
                        if update_button.clicked() {
                            message_sender.send(Message::StartUpdate).ok();
                            update_state.confirmed = false;
                        };
                    });
                });
            } else {
                ui.centered_and_justified(|ui| {
                    ui.add(egui::Label::new(
                        egui::RichText::new(
                            "Some requirements are not met.\nPlease check your settings.",
                        )
                        .color(egui::Color32::RED),
                    ));
                });
            }
        } else {
            ui.centered_and_justified(|ui| {
                ui.add(egui::Label::new(
                    egui::RichText::new("Please select a device and open a file.")
                        .color(egui::Color32::YELLOW),
                ));
            });
        }
    });
}
pub fn update_controls ( ui : & mut egui :: Ui , update_state : & mut DeviceUpdateState , message_sender : & std :: sync :: mpsc :: Sender < Message > , ) { ui . vertical ( | ui | { ui . set_width ( ui . available_width ( ) / 3.0 ) ; ui . set_height ( ui . available_height ( ) ) ; if update_state . error . is_some ( ) { ui . vertical_centered ( | ui | { ui . add_space ( 10.0 ) ; ui . add ( egui :: Label :: new ( egui :: RichText :: new ( " " ) . color ( egui :: Color32 :: RED ) , ) ) ; ui . add ( egui :: Label :: new ( egui :: RichText :: new ( update_state . error . as_ref ( ) . unwrap ( ) ) . color ( egui :: Color32 :: RED ) , ) ) ; ui . add_space ( 10.0 ) ; let continue_button = ui . add ( egui :: widgets :: Button :: new ( " " ) . fill ( egui :: Color32 :: BLUE ) ) ; if continue_button . clicked ( ) { update_state . error = None ; } ; } ) ; } else if update_state . running { ui . centered_and_justified ( | ui | { ui . label ( " " ) ; } ) ; } else if update_state . finished { ui . vertical_centered ( | ui | { ui . add_space ( 10.0 ) ; ui . add ( egui :: Label :: new ( egui :: RichText :: new ( " " ) . color ( egui :: Color32 :: GREEN ) , ) ) ; ui . add_space ( 10.0 ) ; let continue_button = ui . add ( egui :: widgets :: Button :: new ( " " ) . fill ( egui :: Color32 :: BLUE ) ) ; if continue_button . clicked ( ) { * update_state = DeviceUpdateState :: default ( ) ; } ; } ) ; } else if update_state . device_ready && update_state . file_ready { if update_state . preflight_checks_passed { ui . vertical_centered ( | ui | { ui . add_space ( 5.0 ) ; ui . add ( egui :: Label :: new ( egui :: RichText :: new ( " " ) . color ( egui :: Color32 :: YELLOW ) , ) ) ; ui . add_space ( 10.0 ) ; ui . checkbox ( & mut update_state . confirmed , " " ) ; ui . add_space ( 10.0 ) ; ui . scope ( | ui | { ui . set_enabled ( update_state . confirmed ) ; let update_button = ui . add ( egui :: widgets :: Button :: new ( " " ) . fill ( egui :: Color32 :: BLUE ) , ) ; if update_button . clicked ( ) { message_sender . send ( Message :: StartUpdate ) . ok ( ) ; update_state . confirmed = false ; } ; } ) ; } ) ; } else { ui . centered_and_justified ( | ui | { ui . add ( egui :: Label :: new ( egui :: RichText :: new ( " \n " , ) . color ( egui :: Color32 :: RED ) , ) ) ; } ) ; } } else { ui . centered_and_justified ( | ui | { ui . add ( egui :: Label :: new ( egui :: RichText :: new ( " " ) . color ( egui :: Color32 :: YELLOW ) , ) ) ; } ) ; } } ) ; }
Show update button and additional messages
Show update button and additional messages
ui
&mut egui::Ui
update_state
&mut DeviceUpdateState
message_sender
&std::sync::mpsc::Sender<Message>