@@ -70,7 +70,9 @@ live_design! {
7070 }
7171
7272 pub FilePreviewer = { { FilePreviewer } } {
73+ width: Fit , height: Fit
7374 wrapper = <RoundedView > {
75+ width: Fit , height: Fit
7476 align: { x: 0.5 }
7577 flow: Down
7678 padding: { top: 30 , right: 40 , bottom: 20 , left: 40 }
@@ -82,7 +84,7 @@ live_design! {
8284 }
8385
8486 header_view = <View > {
85- width: Fill
87+ width: 400
8688 height: Fit
8789 flow: Right
8890 align: { x: 1.0 , y: 0.0 }
@@ -92,42 +94,49 @@ live_design! {
9294 draw_icon: { svg_file: ( ICON_CLOSE ) }
9395 icon_walk: { width: 21 , height: 21 }
9496 }
95-
9697 }
97-
98- // File metadata section (always visible)
99- metadata_view = < View > {
100- width : Fill
101- height : Fit
102- flow : Down
103- spacing : 5
104- padding : { bottom : 15 }
105-
106- filename_label = < Label > {
107- width : Fill
108- height : Fit
109- draw_text : {
110- text_style : < REGULAR_TEXT > { font_size : 14 } ,
111- color : # 000 ,
112- wrap : Word
98+ < View > {
99+ width : Fit , height : Fit
100+ flow : Right
101+ // Document view (visible only for non-image files)
102+ document_view = < View > {
103+ visible : false ,
104+ width : Fit
105+ height : 40
106+ flow : Down
107+ align : { x : 0.5 , y : 0.5 }
108+ file_icon = < Icon > {
109+ draw_icon : {
110+ svg_file : ( ICON_FILE ) ,
111+ color : # 999 ,
112+ }
113+ icon_walk : { width : 20 , height : 20 }
113114 }
114115 }
115-
116- filesize_label = <Label > {
117- width: Fill
116+ // File metadata section (always visible)
117+ metadata_view = <View > {
118+ width: 400
118119 height: Fit
119- draw_text: {
120- text_style: <REGULAR_TEXT >{ font_size: 12 } ,
121- color: #666 ,
120+ flow: Down
121+ spacing: 5
122+
123+ filename_text = <Label > {
124+ width: Fill
125+ height: Fit
126+ draw_text: {
127+ text_style: <REGULAR_TEXT >{ font_size: 14 } ,
128+ color: #000 ,
129+ wrap: Word
130+ }
122131 }
123132 }
124133 }
125134
126135 // Image preview (visible only for image files)
127136 image_view = <View > {
128137 visible: true ,
129- width: 400
130- height: 400
138+ width: 300
139+ height: 300
131140 flow: Down
132141 align: { x: 0.5 , y: 0.5 }
133142
@@ -137,28 +146,9 @@ live_design! {
137146 }
138147 }
139148
140- // Document view (visible only for non-image files)
141- document_view = <View > {
142- visible: false ,
143- width: Fill
144- height: Fit
145- flow: Down
146- align: { x: 0.5 , y: 0.5 }
147- padding: 20 ,
148-
149- file_icon = <Icon > {
150- draw_icon: {
151- svg_file: ( ICON_HTML_FILE ) ,
152- color: #999 ,
153- }
154- icon_walk: { width: 48 , height: 48 }
155- }
156- }
157-
158149 buttons_view = <View > {
159- width: Fill , height: Fit
150+ width: 300 , height: Fit
160151 flow: Right ,
161- padding: { top: 20 , bottom: 20 }
162152 margin: { right: -15 }
163153 align: { x: 1.0 , y: 0.5 }
164154 spacing: 20
@@ -209,14 +199,10 @@ pub enum FilePreviewerAction {
209199 /// Display the FilePreviewer widget with the given file path and room context.
210200 Show {
211201 file_path : PathBuf ,
212- room_id : ruma:: OwnedRoomId ,
213- replied_to_event_id : Option < ruma:: OwnedEventId > ,
214202 } ,
215203 /// Upload the file with the given path.
216204 Upload {
217- room_id : ruma:: OwnedRoomId ,
218205 file_path : PathBuf ,
219- replied_to_event_id : Option < ruma:: OwnedEventId > ,
220206 } ,
221207 /// Hide the FilePreviewer widget.
222208 Hide ,
@@ -230,8 +216,6 @@ pub struct FilePreviewer {
230216 #[ rust] background_task_id : u32 ,
231217 #[ rust] receiver : Option < ( u32 , std:: sync:: mpsc:: Receiver < ( FilePreviewerMetaData , Vec < u8 > ) > ) > ,
232218 #[ rust] file_path : Option < PathBuf > ,
233- #[ rust] room_id : Option < ruma:: OwnedRoomId > ,
234- #[ rust] replied_to_event_id : Option < ruma:: OwnedEventId > ,
235219}
236220
237221impl Widget for FilePreviewer {
@@ -260,7 +244,6 @@ impl Widget for FilePreviewer {
260244 self . view ( ids ! ( wrapper. document_view) ) . set_visible ( cx, false ) ;
261245 self . file_type = FileType :: Image ;
262246
263-
264247 } else {
265248 println ! ( "Failed to load image from bytes" ) ;
266249 // Failed to load image, show as document
@@ -278,7 +261,6 @@ impl Widget for FilePreviewer {
278261 Err ( std:: sync:: mpsc:: TryRecvError :: Disconnected ) => {
279262 remove_receiver = true ;
280263 }
281-
282264 }
283265 if remove_receiver {
284266 self . receiver = None ;
@@ -291,6 +273,7 @@ impl Widget for FilePreviewer {
291273 self . view . draw_walk ( cx, scope, walk)
292274 }
293275}
276+
294277impl MatchEvent for FilePreviewer {
295278 fn handle_actions ( & mut self , cx : & mut Cx , actions : & Actions ) {
296279 // Handle close button click
@@ -311,11 +294,9 @@ impl MatchEvent for FilePreviewer {
311294 }
312295 // Handle upload button click
313296 if self . view . button ( ids ! ( wrapper. buttons_view. upload_button) ) . clicked ( actions) {
314- if let ( Some ( file_path) , Some ( room_id ) ) = ( & self . file_path , & self . room_id ) {
297+ if let Some ( file_path) = & self . file_path {
315298 cx. action ( FilePreviewerAction :: Upload {
316- room_id : room_id. clone ( ) ,
317299 file_path : file_path. clone ( ) ,
318- replied_to_event_id : self . replied_to_event_id . clone ( ) ,
319300 } ) ;
320301 cx. action ( FilePreviewerAction :: Hide ) ;
321302 self . view . button ( ids ! ( wrapper. buttons_view. upload_button) ) . set_enabled ( cx, false ) ;
@@ -324,7 +305,7 @@ impl MatchEvent for FilePreviewer {
324305 }
325306 for action in actions {
326307 match action. downcast_ref ( ) {
327- Some ( FilePreviewerAction :: Show { file_path, room_id , replied_to_event_id } ) => {
308+ Some ( FilePreviewerAction :: Show { file_path } ) => {
328309 self . view . button ( ids ! ( close_button) ) . reset_hover ( cx) ;
329310 self . view . button ( ids ! ( close_button) ) . set_enabled ( cx, true ) ;
330311 // Reset button states
@@ -334,8 +315,6 @@ impl MatchEvent for FilePreviewer {
334315 self . view . button ( ids ! ( wrapper. buttons_view. upload_button) ) . set_enabled ( cx, true ) ;
335316 // Store the context for later use when upload button is clicked
336317 self . file_path = Some ( file_path. clone ( ) ) ;
337- self . room_id = Some ( room_id. clone ( ) ) ;
338- self . replied_to_event_id = replied_to_event_id. clone ( ) ;
339318 let ( sender, receiver) = std:: sync:: mpsc:: channel ( ) ;
340319 if let Some ( new_value) = self . background_task_id . checked_add ( 1 ) {
341320 self . background_task_id = new_value;
@@ -371,16 +350,16 @@ impl MatchEvent for FilePreviewer {
371350 }
372351 }
373352}
353+
374354impl FilePreviewer {
375355 /// Sets the file metadata (filename and size).
376356 ///
377357 /// ## Arguments
378358 /// * `filename`: the name of the file
379359 /// * `filesize`: the size of the file in bytes
380360 pub fn set_metadata ( & mut self , cx : & mut Cx , filename : & str , filesize : u64 ) {
381- self . view . label ( ids ! ( wrapper. metadata_view. filename_label) ) . set_text ( cx, filename) ;
382361 let size_str = format_file_size ( filesize) ;
383- self . view . label ( ids ! ( wrapper . metadata_view . filesize_label ) ) . set_text ( cx, & size_str) ;
362+ self . view . label ( ids ! ( filename_text ) ) . set_text ( cx, & format ! ( "{} - ({})" , filename , size_str) ) ;
384363 }
385364
386365 /// Displays an image preview.
0 commit comments