fn update(&mut self, ctx: &egui::CtxRef, frame: &epi::Frame) {
        // Continuous run mode is required for message processing
        ctx.request_repaint();

        while let Ok(message) = self.message_channel.1.try_recv() {
            self.process_message(&message);
        }

        if self.frame_count == 0 {
            // Set window size on first frame
            frame.set_window_size(WINDOW_SIZE);
        }

        self.device_update_state.device_ready = self.device_id.is_some();
        self.device_update_state.file_ready = self.dfu_file.is_some();
        self.device_update_state.preflight_checks_passed = self.preflight_checks();

        // Top panel with menu
        egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
            egui::menu::bar(ui, |ui| {
                egui::menu::menu_button(ui, "File", |ui| {
                    if ui.button("Open...").clicked() {
                        self.message_channel.0.send(Message::OpenFileDialog).ok();
                    }
                    if ui.button("Quit").clicked() {
                        frame.quit();
                    }
                });
            });
        });

        // Bottom panel with app version
        egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
            ui.horizontal(|ui| {
                ui.label(format!("v{}", &env!("CARGO_PKG_VERSION")));
                egui::warn_if_debug_build(ui);
                ui.with_layout(egui::Layout::right_to_left(), |ui| {
                    ui.hyperlink_to("Project homepage", env!("CARGO_PKG_HOMEPAGE"));
                });
            });
        });

        egui::CentralPanel::default().show(ctx, |ui| {
            ui.scope(|ui| {
                ui.set_enabled(!self.device_update_state.running);

                ui::device::selection(
                    ui,
                    &self.devices,
                    &self.get_selected_device(),
                    &self.message_channel.0,
                );

                ui.add_space(5.0);

                ui.horizontal(|ui| {
                    ui.set_height(140.0);

                    let device_info = self.get_selected_device().map(|device| &device.info);

                    device::common_info(ui, device_info);
                    device::memory_info(ui, device_info);
                });

                ui.add_space(5.0);

                ui::file::selection(ui, &self.dfu_file, &self.message_channel.0);

                ui.add_space(5.0);

                ui.horizontal(|ui| {
                    ui.set_height(140.0);

                    file::common_info(
                        ui,
                        &self.dfu_file,
                        &mut self.dfu_file_checks,
                        self.device_id.is_some(),
                    );

                    let device_info = self.get_selected_device().map(|device| &device.info);

                    file::content_info(ui, &self.dfu_file, device_info);
                });
            });

            ui.add_space(5.0);

            ui.horizontal(|ui| {
                ui.set_height(85.0);
                device::update_controls(ui, &mut self.device_update_state, &self.message_channel.0);
                ui.add_space(10.0);
                device::update_progress(ui, &self.device_update_state);
            });
        });

        // File drag-and-drop
        if !self.device_update_state.running {
            if !ctx.input().raw.hovered_files.is_empty() {
                let painter = ctx.layer_painter(egui::LayerId::new(
                    egui::Order::Foreground,
                    egui::Id::new("file_drop_target"),
                ));

                let screen_rect = ctx.input().screen_rect();
                painter.rect_filled(screen_rect, 0.0, egui::Color32::from_black_alpha(192));
                painter.text(
                    screen_rect.center(),
                    egui::Align2::CENTER_CENTER,
                    "Drop DFU file top open.",
                    egui::TextStyle::Heading,
                    egui::Color32::YELLOW,
                );
            }

            if !ctx.input().raw.dropped_files.is_empty() {
                for file in &ctx.input().raw.dropped_files {
                    if let Some(path) = &file.path {
                        self.message_channel
                            .0
                            .send(Message::OpenFile(path.clone()))
                            .ok();
                        break;
                    }
                }
            }
        }

        self.frame_count += 1;
    }
/// Called each time the UI needs repainting, which may be many times per second.
Called each time the UI needs repainting, which may be many times per second.
Called each time the UI needs repainting which may be many times per second .
fn update(&mut self, ctx: &egui::CtxRef, frame: &epi::Frame) {
        // Continuous run mode is required for message processing
        ctx.request_repaint();
        while let Ok(message) = self.message_channel.1.try_recv() {
            self.process_message(&message);
        }
        if self.frame_count == 0 {
            // Set window size on first frame
            frame.set_window_size(WINDOW_SIZE);
        }
        self.device_update_state.device_ready = self.device_id.is_some();
        self.device_update_state.file_ready = self.dfu_file.is_some();
        self.device_update_state.preflight_checks_passed = self.preflight_checks();
        // Top panel with menu
        egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
            egui::menu::bar(ui, |ui| {
                egui::menu::menu_button(ui, "File", |ui| {
                    if ui.button("Open...").clicked() {
                        self.message_channel.0.send(Message::OpenFileDialog).ok();
                    }
                    if ui.button("Quit").clicked() {
                        frame.quit();
                    }
                });
            });
        });
        // Bottom panel with app version
        egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
            ui.horizontal(|ui| {
                ui.label(format!("v{}", &env!("CARGO_PKG_VERSION")));
                egui::warn_if_debug_build(ui);
                ui.with_layout(egui::Layout::right_to_left(), |ui| {
                    ui.hyperlink_to("Project homepage", env!("CARGO_PKG_HOMEPAGE"));
                });
            });
        });
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.scope(|ui| {
                ui.set_enabled(!self.device_update_state.running);
                ui::device::selection(
                    ui,
                    &self.devices,
                    &self.get_selected_device(),
                    &self.message_channel.0,
                );
                ui.add_space(5.0);
                ui.horizontal(|ui| {
                    ui.set_height(140.0);
                    let device_info = self.get_selected_device().map(|device| &device.info);
                    device::common_info(ui, device_info);
                    device::memory_info(ui, device_info);
                });
                ui.add_space(5.0);
                ui::file::selection(ui, &self.dfu_file, &self.message_channel.0);
                ui.add_space(5.0);
                ui.horizontal(|ui| {
                    ui.set_height(140.0);
                    file::common_info(
                        ui,
                        &self.dfu_file,
                        &mut self.dfu_file_checks,
                        self.device_id.is_some(),
                    );
                    let device_info = self.get_selected_device().map(|device| &device.info);
                    file::content_info(ui, &self.dfu_file, device_info);
                });
            });
            ui.add_space(5.0);
            ui.horizontal(|ui| {
                ui.set_height(85.0);
                device::update_controls(ui, &mut self.device_update_state, &self.message_channel.0);
                ui.add_space(10.0);
                device::update_progress(ui, &self.device_update_state);
            });
        });
        // File drag-and-drop
        if !self.device_update_state.running {
            if !ctx.input().raw.hovered_files.is_empty() {
                let painter = ctx.layer_painter(egui::LayerId::new(
                    egui::Order::Foreground,
                    egui::Id::new("file_drop_target"),
                ));
                let screen_rect = ctx.input().screen_rect();
                painter.rect_filled(screen_rect, 0.0, egui::Color32::from_black_alpha(192));
                painter.text(
                    screen_rect.center(),
                    egui::Align2::CENTER_CENTER,
                    "Drop DFU file top open.",
                    egui::TextStyle::Heading,
                    egui::Color32::YELLOW,
                );
            }
            if !ctx.input().raw.dropped_files.is_empty() {
                for file in &ctx.input().raw.dropped_files {
                    if let Some(path) = &file.path {
                        self.message_channel
                            .0
                            .send(Message::OpenFile(path.clone()))
                            .ok();
                        break;
                    }
                }
            }
        }
        self.frame_count += 1;
    }
fn update ( & mut self , ctx : & egui :: CtxRef , frame : & epi :: Frame ) { // Continuous run mode is required for message processing ctx . request_repaint ( ) ; while let Ok ( message ) = self . message_channel . 1 . try_recv ( ) { self . process_message ( & message ) ; } if self . frame_count == 0 { // Set window size on first frame frame . set_window_size ( WINDOW_SIZE ) ; } self . device_update_state . device_ready = self . device_id . is_some ( ) ; self . device_update_state . file_ready = self . dfu_file . is_some ( ) ; self . device_update_state . preflight_checks_passed = self . preflight_checks ( ) ; // Top panel with menu egui :: TopBottomPanel :: top ( " " ) . show ( ctx , | ui | { egui :: menu :: bar ( ui , | ui | { egui :: menu :: menu_button ( ui , " " , | ui | { if ui . button ( " " ) . clicked ( ) { self . message_channel . 0 . send ( Message :: OpenFileDialog ) . ok ( ) ; } if ui . button ( " " ) . clicked ( ) { frame . quit ( ) ; } } ) ; } ) ; } ) ; // Bottom panel with app version egui :: TopBottomPanel :: bottom ( " " ) . show ( ctx , | ui | { ui . horizontal ( | ui | { ui . label ( format ! ( " " env ( " " ) ) ) ; egui :: warn_if_debug_build ( ui ) ; ui . with_layout ( egui :: Layout :: right_to_left ( ) , | ui | { ui . hyperlink_to ( " " , env ! ( " " ) ) ; } ) ; } ) ; } ) ; egui :: CentralPanel :: default ( ) . show ( ctx , | ui | { ui . scope ( | ui | { ui . set_enabled ( ! self . device_update_state . running ) ; ui :: device :: selection ( ui , & self . devices , & self . get_selected_device ( ) , & self . message_channel . 0 , ) ; ui . add_space ( 5.0 ) ; ui . horizontal ( | ui | { ui . set_height ( 140.0 ) ; let device_info = self . get_selected_device ( ) . map ( | device | & device . info ) ; device :: common_info ( ui , device_info ) ; device :: memory_info ( ui , device_info ) ; } ) ; ui . add_space ( 5.0 ) ; ui :: file :: selection ( ui , & self . dfu_file , & self . message_channel . 0 ) ; ui . add_space ( 5.0 ) ; ui . horizontal ( | ui | { ui . set_height ( 140.0 ) ; file :: common_info ( ui , & self . dfu_file , & mut self . dfu_file_checks , self . device_id . is_some ( ) , ) ; let device_info = self . get_selected_device ( ) . map ( | device | & device . info ) ; file :: content_info ( ui , & self . dfu_file , device_info ) ; } ) ; } ) ; ui . add_space ( 5.0 ) ; ui . horizontal ( | ui | { ui . set_height ( 85.0 ) ; device :: update_controls ( ui , & mut self . device_update_state , & self . message_channel . 0 ) ; ui . add_space ( 10.0 ) ; device :: update_progress ( ui , & self . device_update_state ) ; } ) ; } ) ; // File drag-and-drop if ! self . device_update_state . running { if ! ctx . input ( ) . raw . hovered_files . is_empty ( ) { let painter = ctx . layer_painter ( egui :: LayerId :: new ( egui :: Order :: Foreground , egui :: Id :: new ( " " ) , ) ) ; let screen_rect = ctx . input ( ) . screen_rect ( ) ; painter . rect_filled ( screen_rect , 0.0 , egui :: Color32 :: from_black_alpha ( 192 ) ) ; painter . text ( screen_rect . center ( ) , egui :: Align2 :: CENTER_CENTER , " " , egui :: TextStyle :: Heading , egui :: Color32 :: YELLOW , ) ; } if ! ctx . input ( ) . raw . dropped_files . is_empty ( ) { for file in & ctx . input ( ) . raw . dropped_files { if let Some ( path ) = & file . path { self . message_channel . 0 . send ( Message :: OpenFile ( path . clone ( ) ) ) . ok ( ) ; break ; } } } } self . frame_count += 1 ; }
Called each time the UI needs repainting, which may be many times per second.
Called each time the UI needs repainting which may be many times per second .
&mut self
ctx
&egui::CtxRef
frame
&epi::Frame