@@ -4,7 +4,8 @@ use std::{
44} ;
55
66use egui:: {
7- Align , Context , Id , IdMap , NumExt as _, Rangef , Rect , Ui , UiBuilder , Vec2 , Vec2b , vec2,
7+ Align , Context , Id , IdMap , NumExt as _, Rangef , Rect , Response , Ui , UiBuilder , Vec2 , Vec2b ,
8+ vec2,
89} ;
910use vec1:: Vec1 ;
1011
@@ -349,7 +350,7 @@ impl Table {
349350 . saturating_sub ( 1 )
350351 }
351352
352- pub fn show ( mut self , ui : & mut Ui , table_delegate : & mut dyn TableDelegate ) {
353+ pub fn show ( mut self , ui : & mut Ui , table_delegate : & mut dyn TableDelegate ) -> Response {
353354 self . num_sticky_cols = self . num_sticky_cols . at_most ( self . columns . len ( ) ) ;
354355
355356 let id = TableState :: id ( ui, self . id_salt ) ;
@@ -414,57 +415,60 @@ impl Table {
414415 ui_builder = ui_builder. sizing_pass ( ) . invisible ( ) ;
415416 ui. ctx ( ) . request_discard ( "Full egui_table sizing" ) ;
416417 }
417- ui. scope_builder ( ui_builder, |ui| {
418- // Don't wrap text in the table cells.
419- ui. style_mut ( ) . wrap_mode = Some ( egui:: TextWrapMode :: Extend ) ; // TODO: I think this is default for horizontal layouts anyway?
420-
421- let num_columns = self . columns . len ( ) ;
422-
423- for ( col_nr, column) in self . columns . iter_mut ( ) . enumerate ( ) {
424- if column. resizable {
425- let column_resize_id = id. with ( column. id_for ( col_nr) ) . with ( "resize" ) ;
426- if let Some ( response) = ui. ctx ( ) . read_response ( column_resize_id) {
427- if response. double_clicked ( ) {
428- column. auto_size_this_frame = true ;
418+ let response = ui
419+ . scope_builder ( ui_builder, |ui| {
420+ // Don't wrap text in the table cells.
421+ ui. style_mut ( ) . wrap_mode = Some ( egui:: TextWrapMode :: Extend ) ; // TODO: I think this is default for horizontal layouts anyway?
422+
423+ let num_columns = self . columns . len ( ) ;
424+
425+ for ( col_nr, column) in self . columns . iter_mut ( ) . enumerate ( ) {
426+ if column. resizable {
427+ let column_resize_id = id. with ( column. id_for ( col_nr) ) . with ( "resize" ) ;
428+ if let Some ( response) = ui. ctx ( ) . read_response ( column_resize_id) {
429+ if response. double_clicked ( ) {
430+ column. auto_size_this_frame = true ;
431+ }
429432 }
430433 }
434+ if column. auto_size_this_frame {
435+ ui. ctx ( ) . request_discard ( "egui_table column sizing" ) ;
436+ }
431437 }
432- if column. auto_size_this_frame {
433- ui. ctx ( ) . request_discard ( "egui_table column sizing" ) ;
434- }
435- }
436438
437- SplitScroll {
438- scroll_enabled : Vec2b :: new ( true , true ) ,
439- fixed_size : sticky_size,
440- scroll_outer_size : ( ui. available_size ( ) - sticky_size) . at_least ( Vec2 :: ZERO ) ,
441- scroll_content_size : Vec2 :: new (
442- self . columns [ self . num_sticky_cols ..]
443- . iter ( )
444- . map ( |c| c. current )
445- . sum ( ) ,
446- self . get_row_top_offset ( ui. ctx ( ) , id, table_delegate, self . num_rows ) ,
447- ) ,
448- }
449- . show (
450- ui,
451- & mut TableSplitScrollDelegate {
452- id,
453- table_delegate,
454- state : & mut state,
455- table : & mut self ,
456- col_x,
457- header_row_y,
458- max_column_widths : vec ! [ 0.0 ; num_columns] ,
459- visible_column_lines : Default :: default ( ) ,
460- do_full_sizing_pass,
461- has_prefetched : false ,
462- egui_ctx : ui. ctx ( ) . clone ( ) ,
463- } ,
464- ) ;
465- } ) ;
439+ SplitScroll {
440+ scroll_enabled : Vec2b :: new ( true , true ) ,
441+ fixed_size : sticky_size,
442+ scroll_outer_size : ( ui. available_size ( ) - sticky_size) . at_least ( Vec2 :: ZERO ) ,
443+ scroll_content_size : Vec2 :: new (
444+ self . columns [ self . num_sticky_cols ..]
445+ . iter ( )
446+ . map ( |c| c. current )
447+ . sum ( ) ,
448+ self . get_row_top_offset ( ui. ctx ( ) , id, table_delegate, self . num_rows ) ,
449+ ) ,
450+ }
451+ . show (
452+ ui,
453+ & mut TableSplitScrollDelegate {
454+ id,
455+ table_delegate,
456+ state : & mut state,
457+ table : & mut self ,
458+ col_x,
459+ header_row_y,
460+ max_column_widths : vec ! [ 0.0 ; num_columns] ,
461+ visible_column_lines : Default :: default ( ) ,
462+ do_full_sizing_pass,
463+ has_prefetched : false ,
464+ egui_ctx : ui. ctx ( ) . clone ( ) ,
465+ } ,
466+ ) ;
467+ } )
468+ . response ;
466469
467470 state. store ( ui. ctx ( ) , id) ;
471+ response
468472 }
469473}
470474
0 commit comments