@@ -816,7 +816,10 @@ impl MyApp {
816816
817817 for ( address, subscription) in & self . subscriptions {
818818 // 1. Use a Frame to visually group each plot and its title.
819- egui:: Frame :: group ( ui. style ( ) ) . show ( ui, |ui| {
819+ let mut capture_clicked = false ;
820+ let mut plot_title = String :: new ( ) ;
821+
822+ let frame_response = egui:: Frame :: group ( ui. style ( ) ) . show ( ui, |ui| {
820823 let plot_id = format ! ( "sdo_plot_{:x}_{}" , address. index, address. sub_index) ;
821824
822825 // Get human-readable name from EDS
@@ -826,7 +829,7 @@ impl MyApp {
826829 . map ( |sub_object| sub_object. name . clone ( ) )
827830 . unwrap_or_else ( || format ! ( "0x{:04X}:{:02X}" , address. index, address. sub_index) ) ;
828831
829- let plot_title = format ! ( "SDO - {} ({:#06X}:{})" , field_name, address. index, address. sub_index) ;
832+ plot_title = format ! ( "SDO - {} ({:#06X}:{})" , field_name, address. index, address. sub_index) ;
830833
831834 // Add a title for the individual plot.
832835 ui. label ( & plot_title) ;
@@ -860,16 +863,7 @@ impl MyApp {
860863
861864 ui. horizontal ( |ui| {
862865 if ui. button ( "📸 Capture Plot" ) . clicked ( ) {
863- let now = Local :: now ( ) ;
864- let timestamp = now. format ( "%Y-%m-%d %H:%M:%S" ) ;
865- let info = ScreenshotInfo {
866- filename : format ! ( "{}_{}.png" , plot_title. replace( ":" , "_" ) , timestamp) ,
867- // rect: plot_response.response.rect,
868- rect : ui. min_rect ( ) ,
869- } ;
870-
871- let user_data = egui:: UserData :: new ( Arc :: new ( info) ) ;
872- ui. ctx ( ) . send_viewport_cmd ( egui:: ViewportCommand :: Screenshot ( user_data) ) ;
866+ capture_clicked = true ;
873867 }
874868
875869 if ui. button ( "🗑 Clear" ) . clicked ( ) {
@@ -881,6 +875,19 @@ impl MyApp {
881875 }
882876 } ) ;
883877 } ) ;
878+
879+ // Handle capture after we have the frame rect
880+ if capture_clicked {
881+ let now = Local :: now ( ) ;
882+ let timestamp = now. format ( "%Y-%m-%d %H:%M:%S" ) ;
883+ let info = ScreenshotInfo {
884+ filename : format ! ( "{}_{}.png" , plot_title. replace( ":" , "_" ) , timestamp) ,
885+ rect : frame_response. response . rect ,
886+ } ;
887+
888+ let user_data = egui:: UserData :: new ( Arc :: new ( info) ) ;
889+ ui. ctx ( ) . send_viewport_cmd ( egui:: ViewportCommand :: Screenshot ( user_data) ) ;
890+ }
884891 }
885892
886893 for address in addresses_to_clear {
@@ -899,9 +906,12 @@ impl MyApp {
899906 let mut tpdo_fields_to_export = Vec :: new ( ) ;
900907
901908 for ( field_id, subscription) in & self . tpdo_field_subscriptions {
902- egui:: Frame :: group ( ui. style ( ) ) . show ( ui, |ui| {
909+ let mut capture_clicked = false ;
910+ let mut plot_title = String :: new ( ) ;
911+
912+ let frame_response = egui:: Frame :: group ( ui. style ( ) ) . show ( ui, |ui| {
903913 let plot_id = format ! ( "tpdo_plot_{}_{}" , field_id. tpdo_number, field_id. field_name) ;
904- let plot_title = format ! ( "TPDO {} - {}" , field_id. tpdo_number, field_id. field_name) ;
914+ plot_title = format ! ( "TPDO {} - {}" , field_id. tpdo_number, field_id. field_name) ;
905915
906916 ui. label ( & plot_title) ;
907917 ui. separator ( ) ;
@@ -935,15 +945,7 @@ impl MyApp {
935945
936946 ui. horizontal ( |ui| {
937947 if ui. button ( "📸 Capture Plot" ) . clicked ( ) {
938- let now = Local :: now ( ) ;
939- let timestamp = now. format ( "%Y-%m-%d %H:%M:%S" ) ;
940- let info = ScreenshotInfo {
941- filename : format ! ( "{}_{}.png" , plot_title. replace( ":" , "_" ) . replace( " - " , "_" ) , timestamp) ,
942- rect : ui. min_rect ( ) ,
943- } ;
944-
945- let user_data = egui:: UserData :: new ( Arc :: new ( info) ) ;
946- ui. ctx ( ) . send_viewport_cmd ( egui:: ViewportCommand :: Screenshot ( user_data) ) ;
948+ capture_clicked = true ;
947949 }
948950
949951 if ui. button ( "🗑 Clear" ) . clicked ( ) {
@@ -955,6 +957,19 @@ impl MyApp {
955957 }
956958 } ) ;
957959 } ) ;
960+
961+ // Handle capture after we have the frame rect
962+ if capture_clicked {
963+ let now = Local :: now ( ) ;
964+ let timestamp = now. format ( "%Y-%m-%d %H:%M:%S" ) ;
965+ let info = ScreenshotInfo {
966+ filename : format ! ( "{}_{}.png" , plot_title. replace( ":" , "_" ) . replace( " - " , "_" ) , timestamp) ,
967+ rect : frame_response. response . rect ,
968+ } ;
969+
970+ let user_data = egui:: UserData :: new ( Arc :: new ( info) ) ;
971+ ui. ctx ( ) . send_viewport_cmd ( egui:: ViewportCommand :: Screenshot ( user_data) ) ;
972+ }
958973 }
959974
960975 // Clear TPDO field plots
0 commit comments