diff --git a/src/app.rs b/src/app.rs index fd9fead..1573a63 100644 --- a/src/app.rs +++ b/src/app.rs @@ -143,6 +143,44 @@ impl eframe::App for App { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { if self.state.book.is_none() { self.welcome_view(ctx); + return; } + + let file_path = self.state.file_path + .as_ref() + .map(|p| p.to_string_lossy().to_string()) + .unwrap_or_default(); + + egui::CentralPanel::default().show(ctx, |ui| { + let book = self.state.book.as_mut().unwrap(); + let action = crate::reader::reading_view( + ui, + book, + &mut self.state.current_section, + &mut self.state.current_page, + &mut self.state.sidebar_open, + &mut self.settings.font_size, + &self.settings.theme, + &file_path, + ); + + if action.go_back { + self.save_reading_position(); + self.state.book = None; + self.state.current_section = 0; + self.state.current_page = 0; + } + + if action.toggle_theme { + self.settings.theme = match self.settings.theme { + theme::Theme::Light => theme::Theme::Dark, + theme::Theme::Dark => theme::Theme::Light, + }; + ctx.set_style(theme::create_style(&self.settings.theme)); + } + }); + + self.save_reading_position(); + self.save_settings(); } }