@@ -56,19 +56,25 @@ const NEW_SO: KeyboardShortcut = KeyboardShortcut::new(
5656
5757const UI_ZOOM_FACTORS : [ f32 ; 5 ] = [ 1.0 , 1.25 , 1.50 , 1.75 , 2.0 ] ;
5858
59+ /// Top-level application state.
5960#[ derive( Serialize , Deserialize , Default ) ]
6061#[ serde( default ) ]
6162pub struct Deduct {
63+ /// The current proof, if any.
6264 #[ serde( skip) ]
6365 proof : Option < proof:: ProofUi > ,
66+ /// Popup window visibilities.
6467 #[ serde( skip) ]
6568 vis : popups:: Visibility ,
69+ /// New proof popup state.
6670 #[ serde( skip) ]
6771 new : popups:: NewProof ,
72+ /// Preferences popup state.
6873 prefs : popups:: Preferences ,
6974}
7075
7176impl Deduct {
77+ /// Called once on startup.
7278 pub fn new ( cc : & eframe:: CreationContext < ' _ > ) -> Self {
7379 egui_extras:: install_image_loaders ( & cc. egui_ctx ) ;
7480
@@ -90,6 +96,8 @@ impl Deduct {
9096 Default :: default ( )
9197 }
9298
99+ /// Try and use the input from the new proof popup
100+ /// to start a new proof.
93101 pub fn try_new_proof ( & mut self ) {
94102 if let Some ( ui) = self . new . try_create ( ) {
95103 self . proof = Some ( ui) ;
@@ -98,6 +106,7 @@ impl Deduct {
98106 self . new . ready = false ;
99107 }
100108
109+ /// Handle keyboard shortcuts.
101110 fn handle_shortcuts ( & mut self , ctx : & Context ) {
102111 let mut op = None ;
103112
@@ -153,6 +162,7 @@ impl eframe::App for Deduct {
153162
154163 self . handle_shortcuts ( ctx) ;
155164
165+ // Render top menu bar.
156166 egui:: TopBottomPanel :: top ( "top_panel" ) . show ( ctx, |ui| {
157167 egui:: menu:: bar ( ui, |ui| {
158168 ui. menu_button ( "Proof" , |ui| {
@@ -207,6 +217,7 @@ impl eframe::App for Deduct {
207217
208218 } ) ;
209219
220+ // Render quick reference side bar.
210221 egui:: SidePanel :: right ( "proof_rules" )
211222 . resizable ( false )
212223 . min_width ( w * 0.25 )
@@ -303,8 +314,10 @@ impl eframe::App for Deduct {
303314 } ) ;
304315 } ) ;
305316
317+ // Render central panel.
306318 egui:: CentralPanel :: default ( )
307319 . show ( ctx, |ui| {
320+ // If we don't have a proof, display a placeholder message.
308321 let Some ( proof) = & mut self . proof else {
309322 ui. with_layout (
310323 Layout :: centered_and_justified ( Direction :: TopDown ) ,
@@ -337,6 +350,7 @@ impl eframe::App for Deduct {
337350 }
338351}
339352
353+ /// Render the about window.
340354fn about ( ui : & mut Ui ) {
341355 let title_font = FontId :: new (
342356 40.0 ,
@@ -353,7 +367,7 @@ fn about(ui: &mut Ui) {
353367 ui. label ( "A Fitch-style natural deduction proof checker." ) ;
354368
355369 ui. label (
356- RichText :: new ( "Built with love by Colonial, using Rust and egui!" ) . weak ( ) . italics ( )
370+ RichText :: new ( "Built with love by Colonial using Rust and egui!" ) . weak ( ) . italics ( )
357371 ) ;
358372
359373 ui. separator ( ) ;
@@ -385,6 +399,7 @@ fn about(ui: &mut Ui) {
385399 } ) ;
386400}
387401
402+ /// Render the shortcut info window.
388403fn shortcuts ( ui : & mut Ui ) {
389404 ui. label ( "All shortcuts act on the currently selected line or (if no line is selected) the last line." ) ;
390405 ui. separator ( ) ;
@@ -438,6 +453,7 @@ fn shortcuts(ui: &mut Ui) {
438453 } ) ;
439454}
440455
456+ /// Load LaTeX `Latin Modern Math` font into memory under the name `math`.
441457fn fonts_init ( cc : & eframe:: CreationContext < ' _ > ) {
442458 let mut fonts = FontDefinitions :: default ( ) ;
443459
@@ -454,6 +470,7 @@ fn fonts_init(cc: &eframe::CreationContext<'_>) {
454470 cc. egui_ctx . set_fonts ( fonts) ;
455471}
456472
473+ /// Return the current width and height of the window.
457474fn window_size ( ui : & Ui ) -> ( f32 , f32 ) {
458475 let w = ui. ctx ( ) . input ( |i| {
459476 let r = i. screen_rect ( ) . x_range ( ) ;
@@ -468,13 +485,15 @@ fn window_size(ui: &Ui) -> (f32, f32) {
468485 ( w, h)
469486}
470487
488+ /// Generate a dummy [`Response`] that does not influence the UI.
471489fn dummy_response ( ui : & mut Ui ) -> Response {
472490 ui. allocate_response (
473491 Vec2 :: ZERO ,
474492 Sense :: click ( )
475493 )
476494}
477495
496+ /// Create a new popup window with the given title and open flag.
478497fn new_window < ' a > ( title : & ' static str , open : & ' a mut bool ) -> Window < ' a > {
479498 egui:: Window :: new ( title)
480499 . default_open ( true )
0 commit comments