fn update(&mut self, ctx: &egui::CtxRef, frame: &mut epi::Frame<'_>) {
        egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
            // The top panel is often a good place for a menu bar:
            egui::menu::bar(ui, |ui| {
                egui::menu::menu(ui, "File", |ui| {
                    if ui.button("Save").clicked() {
                        // Option a popup to save the file to a given directory
                        if let Some(path) = self.state.file_dialog(
                            StylistFileDialog::Save,
                            Some(("eguitheme", &["ron", "eguitheme"])),
                        ) {
                            let theme = self.state.export_theme();
                            match ron::to_string(&theme) {
                                Ok(value) => match File::create(path) {
                                    Ok(mut f) => {
                                        if let Err(err) = f.write_all(value.as_bytes()) {
                                            self.error_msg = format!("Saving failed with {}", err);
                                            self.show_error_window = true;
                                        }
                                    }
                                    Err(err) => {
                                        self.error_msg =
                                            format!("Creating file failed with {}", err);
                                        self.show_error_window = true;
                                    }
                                },
                                Err(err) => {
                                    self.error_msg =
                                        format!("Opening file path failed with {}", err);
                                    self.show_error_window = true;
                                }
                            }
                        }
                    }
                    if ui.button("Load").clicked() {
                        if let Some(path) = self.state.file_dialog(
                            StylistFileDialog::Open,
                            Some(("eguitheme", &["ron", "eguitheme"])),
                        ) {
                            match File::open(path) {
                                Ok(mut f) => {
                                    let mut buf = String::new();
                                    f.read_to_string(&mut buf).expect("this should work");
                                    match ron::from_str(&buf) {
                                        Ok(theme) => self.state.import_theme(theme),
                                        Err(err) => {
                                            self.error_msg = format!(
                                                "Loading theme failed with the following error {}",
                                                err
                                            );
                                            self.show_error_window = true;
                                        }
                                    }
                                }
                                Err(err) => {
                                    self.error_msg = format!(
                                        "Loading theme failed with the following error {}",
                                        err
                                    );
                                    self.error_msg = format!("Failed to open file due to: {}", err);
                                    self.show_error_window = true;
                                }
                            }
                        }
                    }
                    if ui.button("Quit").clicked() {
                        frame.quit();
                    }
                });
                egui::menu::menu(ui, "Options", |ui| {
                    if ui.button("Set current theme as app theme").clicked() {
                        let theme = self.state.export_theme();
                        // The font_data is only used for serialization
                        let (style, font_definitions) = theme.extract();
                        ctx.set_style(style);
                        ctx.set_fonts(font_definitions);
                    }
                    if ui.button("Clear settings").clicked() {
                        self.state = StylistState::default();
                        ctx.set_fonts(egui::FontDefinitions::default());
                    }
                    if ui.button("Reset App Theme Theme").clicked() {
                        ctx.set_style(egui::Style::default());
                        ctx.set_fonts(egui::FontDefinitions::default())
                    }
                });
            });
        });

        egui::CentralPanel::default().show(ctx, |ui| self.state.ui(ui));
    }
/// Called each time the UI needs repainting, which may be many times per second.
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
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: &mut epi::Frame<'_>) {
        egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
            // The top panel is often a good place for a menu bar:
            egui::menu::bar(ui, |ui| {
                egui::menu::menu(ui, "File", |ui| {
                    if ui.button("Save").clicked() {
                        // Option a popup to save the file to a given directory
                        if let Some(path) = self.state.file_dialog(
                            StylistFileDialog::Save,
                            Some(("eguitheme", &["ron", "eguitheme"])),
                        ) {
                            let theme = self.state.export_theme();
                            match ron::to_string(&theme) {
                                Ok(value) => match File::create(path) {
                                    Ok(mut f) => {
                                        if let Err(err) = f.write_all(value.as_bytes()) {
                                            self.error_msg = format!("Saving failed with {}", err);
                                            self.show_error_window = true;
                                        }
                                    }
                                    Err(err) => {
                                        self.error_msg =
                                            format!("Creating file failed with {}", err);
                                        self.show_error_window = true;
                                    }
                                },
                                Err(err) => {
                                    self.error_msg =
                                        format!("Opening file path failed with {}", err);
                                    self.show_error_window = true;
                                }
                            }
                        }
                    }
                    if ui.button("Load").clicked() {
                        if let Some(path) = self.state.file_dialog(
                            StylistFileDialog::Open,
                            Some(("eguitheme", &["ron", "eguitheme"])),
                        ) {
                            match File::open(path) {
                                Ok(mut f) => {
                                    let mut buf = String::new();
                                    f.read_to_string(&mut buf).expect("this should work");
                                    match ron::from_str(&buf) {
                                        Ok(theme) => self.state.import_theme(theme),
                                        Err(err) => {
                                            self.error_msg = format!(
                                                "Loading theme failed with the following error {}",
                                                err
                                            );
                                            self.show_error_window = true;
                                        }
                                    }
                                }
                                Err(err) => {
                                    self.error_msg = format!(
                                        "Loading theme failed with the following error {}",
                                        err
                                    );
                                    self.error_msg = format!("Failed to open file due to: {}", err);
                                    self.show_error_window = true;
                                }
                            }
                        }
                    }
                    if ui.button("Quit").clicked() {
                        frame.quit();
                    }
                });
                egui::menu::menu(ui, "Options", |ui| {
                    if ui.button("Set current theme as app theme").clicked() {
                        let theme = self.state.export_theme();
                        // The font_data is only used for serialization
                        let (style, font_definitions) = theme.extract();
                        ctx.set_style(style);
                        ctx.set_fonts(font_definitions);
                    }
                    if ui.button("Clear settings").clicked() {
                        self.state = StylistState::default();
                        ctx.set_fonts(egui::FontDefinitions::default());
                    }
                    if ui.button("Reset App Theme Theme").clicked() {
                        ctx.set_style(egui::Style::default());
                        ctx.set_fonts(egui::FontDefinitions::default())
                    }
                });
            });
        });
        egui::CentralPanel::default().show(ctx, |ui| self.state.ui(ui));
    }
fn update ( & mut self , ctx : & egui :: CtxRef , frame : & mut epi :: Frame < ' _ > ) { egui :: TopBottomPanel :: top ( " " ) . show ( ctx , | ui | { // The top panel is often a good place for a menu bar: egui :: menu :: bar ( ui , | ui | { egui :: menu :: menu ( ui , " " , | ui | { if ui . button ( " " ) . clicked ( ) { // Option a popup to save the file to a given directory if let Some ( path ) = self . state . file_dialog ( StylistFileDialog :: Save , Some ( ( " " , & [ " " , " " ] ) ) , ) { let theme = self . state . export_theme ( ) ; match ron :: to_string ( & theme ) { Ok ( value ) => match File :: create ( path ) { Ok ( mut f ) => { if let Err ( err ) = f . write_all ( value . as_bytes ( ) ) { self . error_msg = format ! ( " " err ) ; self . show_error_window = true ; } } Err ( err ) => { self . error_msg = format ! ( " " err ) ; self . show_error_window = true ; } } , Err ( err ) => { self . error_msg = format ! ( " " err ) ; self . show_error_window = true ; } } } } if ui . button ( " " ) . clicked ( ) { if let Some ( path ) = self . state . file_dialog ( StylistFileDialog :: Open , Some ( ( " " , & [ " " , " " ] ) ) , ) { match File :: open ( path ) { Ok ( mut f ) => { let mut buf = String :: new ( ) ; f . read_to_string ( & mut buf ) . expect ( " " ) ; match ron :: from_str ( & buf ) { Ok ( theme ) => self . state . import_theme ( theme ) , Err ( err ) => { self . error_msg = format ! ( " " err ) ; self . show_error_window = true ; } } } Err ( err ) => { self . error_msg = format ! ( " " err ) ; self . error_msg = format ! ( " " err ) ; self . show_error_window = true ; } } } } if ui . button ( " " ) . clicked ( ) { frame . quit ( ) ; } } ) ; egui :: menu :: menu ( ui , " " , | ui | { if ui . button ( " " ) . clicked ( ) { let theme = self . state . export_theme ( ) ; // The font_data is only used for serialization let ( style , font_definitions ) = theme . extract ( ) ; ctx . set_style ( style ) ; ctx . set_fonts ( font_definitions ) ; } if ui . button ( " " ) . clicked ( ) { self . state = StylistState :: default ( ) ; ctx . set_fonts ( egui :: FontDefinitions :: default ( ) ) ; } if ui . button ( " " ) . clicked ( ) { ctx . set_style ( egui :: Style :: default ( ) ) ; ctx . set_fonts ( egui :: FontDefinitions :: default ( ) ) } } ) ; } ) ; } ) ; egui :: CentralPanel :: default ( ) . show ( ctx , | ui | self . state . ui ( ui ) ) ; }
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
&mut epi::Frame<'_>