@@ -15,10 +15,14 @@ use std::{
1515 time:: Duration ,
1616} ;
1717
18- use self :: file_view:: { FileEntry , FileView , Message } ;
18+ use self :: {
19+ file_view:: { FileEntry , FileView , Message } ,
20+ options:: { Options , ScrollSpeed } ,
21+ } ;
1922
2023mod file_view;
2124mod help_dialog;
25+ pub mod options;
2226mod sauce_dialog;
2327
2428pub struct MainWindow < ' a > {
@@ -45,11 +49,10 @@ pub struct MainWindow<'a> {
4549 toasts : egui_notify:: Toasts ,
4650 is_closed : bool ,
4751 pub opened_file : Option < FileEntry > ,
48-
52+ pub store_options : bool ,
4953 // animations
5054 animation : Option < Arc < Mutex < Animator > > > ,
5155}
52- const SCROLL_SPEED : [ f32 ; 3 ] = [ 80.0 , 160.0 , 320.0 ] ;
5356const EXT_WHITE_LIST : [ & str ; 5 ] = [ "seq" , "diz" , "nfo" , "ice" , "bbs" ] ;
5457
5558const EXT_BLACK_LIST : [ & str ; 8 ] = [ "zip" , "rar" , "gz" , "tar" , "7z" , "pdf" , "exe" , "com" ] ;
@@ -73,7 +76,7 @@ impl<'a> App for MainWindow<'a> {
7376 ui. set_enabled ( self . sauce_dialog . is_none ( ) && self . help_dialog . is_none ( ) ) ;
7477 self . paint_main_area ( ui)
7578 } ) ;
76- self . in_scroll &= self . file_view . auto_scroll_enabled ;
79+ self . in_scroll &= self . file_view . options . auto_scroll_enabled ;
7780 if self . in_scroll {
7881 // ctx.request_repaint_after(Duration::from_millis(10));
7982 ctx. request_repaint ( ) ;
@@ -121,10 +124,17 @@ impl<'a> App for MainWindow<'a> {
121124 }
122125 }
123126 }
127+
128+ fn on_exit ( & mut self , _gl : Option < & glow:: Context > ) {
129+ println ! ( "store options: {}" , self . store_options) ;
130+ if self . store_options {
131+ self . file_view . options . store_options ( ) ;
132+ }
133+ }
124134}
125135
126136impl < ' a > MainWindow < ' a > {
127- pub fn new ( gl : & Arc < glow:: Context > , mut initial_path : Option < PathBuf > ) -> Self {
137+ pub fn new ( gl : & Arc < glow:: Context > , mut initial_path : Option < PathBuf > , options : Options ) -> Self {
128138 let mut view = BufferView :: new ( gl) ;
129139 view. interactive = false ;
130140
@@ -137,9 +147,10 @@ impl<'a> MainWindow<'a> {
137147 }
138148 }
139149 }
150+
140151 Self {
141152 buffer_view : Arc :: new ( eframe:: epaint:: mutex:: Mutex :: new ( view) ) ,
142- file_view : FileView :: new ( initial_path) ,
153+ file_view : FileView :: new ( initial_path, options ) ,
143154 in_scroll : false ,
144155 retained_image : None ,
145156 texture_handle : None ,
@@ -157,6 +168,7 @@ impl<'a> MainWindow<'a> {
157168 opened_file : None ,
158169 is_closed : false ,
159170 animation : None ,
171+ store_options : false ,
160172 }
161173 }
162174
@@ -193,7 +205,7 @@ impl<'a> MainWindow<'a> {
193205 . inner_margin ( egui:: style:: Margin :: same ( 0.0 ) )
194206 . fill ( Color32 :: BLACK ) ;
195207 egui:: CentralPanel :: default ( ) . frame ( frame_no_margins) . show ( ctx, |ui| self . paint_main_area ( ui) ) ;
196- self . in_scroll &= self . file_view . auto_scroll_enabled ;
208+ self . in_scroll &= self . file_view . options . auto_scroll_enabled ;
197209 if self . in_scroll {
198210 // ctx.request_repaint_after(Duration::from_millis(10));
199211 ctx. request_repaint ( ) ;
@@ -389,7 +401,7 @@ impl<'a> MainWindow<'a> {
389401
390402 let dt = ui. input ( |i| i. unstable_dt ) ;
391403 let sp = if self . in_scroll {
392- ( self . cur_scroll_pos + SCROLL_SPEED [ self . file_view . scroll_speed ] * dt) . round ( )
404+ ( self . cur_scroll_pos + self . file_view . options . scroll_speed . get_speed ( ) * dt) . round ( )
393405 } else {
394406 self . cur_scroll_pos . round ( )
395407 } ;
@@ -514,9 +526,7 @@ impl<'a> MainWindow<'a> {
514526 result. buffer_type = icy_engine:: BufferType :: Unicode ;
515527 }
516528 match parse_with_parser ( & mut result, & mut rip_parser, & text, true ) {
517- Ok ( _) => {
518- rip_parser
519- }
529+ Ok ( _) => rip_parser,
520530 Err ( err) => {
521531 log:: error!( "Error while parsing rip file: {err}" ) ;
522532 rip_parser
@@ -607,10 +617,10 @@ impl<'a> MainWindow<'a> {
607617 }
608618 }
609619 Message :: ToggleAutoScroll => {
610- self . file_view . auto_scroll_enabled = !self . in_scroll ;
611- self . in_scroll = self . file_view . auto_scroll_enabled ;
620+ self . file_view . options . auto_scroll_enabled = !self . file_view . options . auto_scroll_enabled ;
621+ self . in_scroll = self . file_view . options . auto_scroll_enabled ;
612622
613- if self . file_view . auto_scroll_enabled {
623+ if self . file_view . options . auto_scroll_enabled {
614624 self . toasts
615625 . info ( fl ! ( crate :: LANGUAGE_LOADER , "toast-auto-scroll-on" ) )
616626 . set_duration ( Some ( Duration :: from_secs ( 3 ) ) ) ;
@@ -631,25 +641,24 @@ impl<'a> MainWindow<'a> {
631641 self . help_dialog = Some ( help_dialog:: HelpDialog :: new ( ) ) ;
632642 }
633643 Message :: ChangeScrollSpeed => {
634- self . file_view . scroll_speed = ( self . file_view . scroll_speed + 1 ) % SCROLL_SPEED . len ( ) ;
644+ self . file_view . options . scroll_speed = self . file_view . options . scroll_speed . next ( ) ;
635645
636- match self . file_view . scroll_speed {
637- 0 => {
646+ match self . file_view . options . scroll_speed {
647+ ScrollSpeed :: Slow => {
638648 self . toasts
639649 . info ( fl ! ( crate :: LANGUAGE_LOADER , "toast-scroll-slow" ) )
640650 . set_duration ( Some ( Duration :: from_secs ( 3 ) ) ) ;
641651 }
642- 1 => {
652+ ScrollSpeed :: Medium => {
643653 self . toasts
644654 . info ( fl ! ( crate :: LANGUAGE_LOADER , "toast-scroll-medium" ) )
645655 . set_duration ( Some ( Duration :: from_secs ( 3 ) ) ) ;
646656 }
647- 2 => {
657+ ScrollSpeed :: Fast => {
648658 self . toasts
649659 . info ( fl ! ( crate :: LANGUAGE_LOADER , "toast-scroll-fast" ) )
650660 . set_duration ( Some ( Duration :: from_secs ( 3 ) ) ) ;
651661 }
652- _ => { }
653662 }
654663 }
655664 }
0 commit comments