33use crate :: { DirectoryEntry , FileDialog } ;
44use chrono:: { DateTime , Local } ;
55use egui:: ahash:: { HashMap , HashMapExt } ;
6- use egui:: Ui ;
6+ use egui:: { Direction , Layout , Ui , Vec2 } ;
77use indexmap:: { IndexMap , IndexSet } ;
88use std:: fs:: File ;
99use std:: io:: { self , Read } ;
@@ -139,47 +139,23 @@ impl Default for InformationPanel {
139139 "jpg" . to_string ( ) ,
140140 Box :: new (
141141 |ui : & mut Ui , item : & InfoPanelEntry , stored_images : & mut IndexSet < String > | {
142- ui. label ( "Image" ) ;
143- stored_images. insert ( format ! ( "{}" , item. directory_entry. as_path( ) . display( ) ) ) ;
144- let image = egui:: Image :: new ( format ! (
145- "file://{}" ,
146- item. directory_entry. as_path( ) . display( )
147- ) ) ;
148- ui. vertical_centered ( |ui| {
149- ui. add ( image. max_height ( ui. available_width ( ) ) ) ;
150- } ) ;
142+ Self :: show_image_preview ( ui, item, stored_images) ;
151143 } ,
152144 ) as Box < dyn FnMut ( & mut Ui , & InfoPanelEntry , & mut IndexSet < String > ) > ,
153145 ) ;
154146 supported_images. insert (
155147 "jpeg" . to_string ( ) ,
156148 Box :: new (
157149 |ui : & mut Ui , item : & InfoPanelEntry , stored_images : & mut IndexSet < String > | {
158- ui. label ( "Image" ) ;
159- stored_images. insert ( format ! ( "{}" , item. directory_entry. as_path( ) . display( ) ) ) ;
160- let image = egui:: Image :: new ( format ! (
161- "file://{}" ,
162- item. directory_entry. as_path( ) . display( )
163- ) ) ;
164- ui. vertical_centered ( |ui| {
165- ui. add ( image. max_height ( ui. available_width ( ) ) ) ;
166- } ) ;
150+ Self :: show_image_preview ( ui, item, stored_images) ;
167151 } ,
168152 ) as Box < dyn FnMut ( & mut Ui , & InfoPanelEntry , & mut IndexSet < String > ) > ,
169153 ) ;
170154 supported_images. insert (
171155 "png" . to_string ( ) ,
172156 Box :: new (
173157 |ui : & mut Ui , item : & InfoPanelEntry , stored_images : & mut IndexSet < String > | {
174- ui. label ( "Image" ) ;
175- stored_images. insert ( format ! ( "{}" , item. directory_entry. as_path( ) . display( ) ) ) ;
176- let image = egui:: Image :: new ( format ! (
177- "file://{}" ,
178- item. directory_entry. as_path( ) . display( )
179- ) ) ;
180- ui. vertical_centered ( |ui| {
181- ui. add ( image. max_height ( ui. available_width ( ) ) ) ;
182- } ) ;
158+ Self :: show_image_preview ( ui, item, stored_images) ;
183159 } ,
184160 ) as Box < dyn FnMut ( & mut Ui , & InfoPanelEntry , & mut IndexSet < String > ) > ,
185161 ) ;
@@ -199,6 +175,30 @@ impl Default for InformationPanel {
199175}
200176
201177impl InformationPanel {
178+ fn show_image_preview (
179+ ui : & mut Ui ,
180+ item : & InfoPanelEntry ,
181+ stored_images : & mut IndexSet < String > ,
182+ ) {
183+ ui. label ( "Image" ) ;
184+ stored_images. insert ( format ! ( "{}" , item. directory_entry. as_path( ) . display( ) ) ) ;
185+ let image = egui:: Image :: new ( format ! (
186+ "file://{}" ,
187+ item. directory_entry. as_path( ) . display( )
188+ ) ) ;
189+ let size = Vec2 {
190+ x : ui. available_width ( ) ,
191+ y : ui. available_width ( ) / 4.0 * 3.0 ,
192+ } ;
193+ ui. allocate_ui_with_layout (
194+ size,
195+ Layout :: centered_and_justified ( Direction :: TopDown ) ,
196+ |ui| {
197+ ui. add ( image) ;
198+ } ,
199+ ) ;
200+ }
201+
202202 /// Adds support for previewing a custom file type.
203203 ///
204204 /// # Arguments
@@ -294,15 +294,15 @@ impl InformationPanel {
294294 ui. add_space ( spacing) ;
295295
296296 // show all metadata
297- self . display_meta_data ( ui, width, item) ;
297+ self . display_meta_data ( ui, file_dialog . get_window_id ( ) , width, item) ;
298298 }
299299 }
300300
301301 fn display_preview ( & mut self , ui : & mut Ui , item : & DirectoryEntry ) {
302302 if item. is_dir ( ) {
303303 // show folder icon
304304 ui. vertical_centered ( |ui| {
305- ui. label ( egui:: RichText :: from ( item. icon ( ) ) . size ( 120 .0) ) ;
305+ ui. label ( egui:: RichText :: from ( item. icon ( ) ) . size ( ui . available_width ( ) / 3 .0) ) ;
306306 } ) ;
307307 } else {
308308 // Display file content preview based on its extension
@@ -322,21 +322,23 @@ impl InformationPanel {
322322 }
323323 } else if let Some ( mut content) = panel_entry. content ( ) {
324324 egui:: ScrollArea :: vertical ( )
325- . max_height ( 100 .0)
325+ . max_height ( ui . available_width ( ) / 3 .0)
326326 . show ( ui, |ui| {
327327 ui. add ( egui:: TextEdit :: multiline ( & mut content) . code_editor ( ) ) ;
328328 } ) ;
329329 } else {
330330 // if now preview is available, show icon
331331 ui. vertical_centered ( |ui| {
332- ui. label ( egui:: RichText :: from ( item. icon ( ) ) . size ( 120.0 ) ) ;
332+ ui. label (
333+ egui:: RichText :: from ( item. icon ( ) ) . size ( ui. available_width ( ) / 3.0 ) ,
334+ ) ;
333335 } ) ;
334336 }
335337 }
336338 } else {
337339 // if now ext is available, show icon anyway
338340 ui. vertical_centered ( |ui| {
339- ui. label ( egui:: RichText :: from ( item. icon ( ) ) . size ( 120 .0) ) ;
341+ ui. label ( egui:: RichText :: from ( item. icon ( ) ) . size ( ui . available_width ( ) / 3 .0) ) ;
340342 } ) ;
341343 }
342344 }
@@ -383,11 +385,11 @@ impl InformationPanel {
383385 }
384386 }
385387
386- fn display_meta_data ( & self , ui : & mut Ui , width : f32 , item : & DirectoryEntry ) {
388+ fn display_meta_data ( & self , ui : & mut Ui , id : egui :: Id , width : f32 , item : & DirectoryEntry ) {
387389 egui:: ScrollArea :: vertical ( )
388- . id_salt ( "meta_data_scroll" )
390+ . id_salt ( id . with ( "meta_data_scroll" ) )
389391 . show ( ui, |ui| {
390- egui:: Grid :: new ( "meta_data" )
392+ egui:: Grid :: new ( id . with ( "meta_data_grid" ) )
391393 . num_columns ( 2 )
392394 . striped ( true )
393395 . min_col_width ( width)
0 commit comments