@@ -60,6 +60,8 @@ struct MyApp {
6060 // Managing the state of the pop-up configuration modal
6161 modal_open_for : Option < SdoAddress > ,
6262 modal_interval_str : String ,
63+
64+ sdo_search_query : String
6365}
6466
6567
@@ -83,6 +85,8 @@ impl Default for MyApp {
8385
8486 modal_open_for : None ,
8587 modal_interval_str : String :: new ( ) ,
88+
89+ sdo_search_query : String :: new ( )
8690 }
8791 }
8892}
@@ -309,26 +313,39 @@ impl MyApp {
309313 fn draw_sdo_list ( & mut self , ui : & mut egui:: Ui ) {
310314 ui. heading ( "SDO List" ) ;
311315
316+ ui. horizontal ( |ui| {
317+ ui. label ( "Search:" ) ;
318+ ui. text_edit_singleline ( & mut self . sdo_search_query ) ;
319+ } ) ;
320+ ui. separator ( ) ;
321+
312322 egui:: ScrollArea :: vertical ( ) . show ( ui, |ui| {
313323 if let Some ( sdo_data) = & self . sdo_data {
324+ let query = self . sdo_search_query . to_lowercase ( ) ;
314325 for ( index, sdo_object) in sdo_data {
315- ui. collapsing ( format ! ( "{:#06X}: {}" , index, & sdo_object. name) , |ui| {
316- for ( sub_index, sub_object) in & sdo_object. sub_objects {
317- let address = SdoAddress { index : * index, sub_index : * sub_index } ;
318- // Change the label to a button
319- let button_text = format ! ( "Sub {}: {}" , sub_index, & sub_object. name) ;
320- if ui. button ( button_text) . clicked ( ) {
321- // When clicked, open the modal for this specific SDO sub-object
322- self . modal_open_for = Some ( address. clone ( ) ) ;
323- if let Some ( sub) = self . subscriptions . get ( & address) {
324- self . modal_interval_str = sub. interval_ms . to_string ( ) ;
325- } else {
326- self . modal_interval_str = "100" . to_string ( ) ;
327- }
326+ let object_name_matches = sdo_object. name . to_lowercase ( ) . contains ( & query) ;
327+ let any_sub_object_matches = sdo_object. sub_objects . values ( )
328+ . any ( |sub| sub. name . to_lowercase ( ) . contains ( & query) ) ;
329+
330+ if query. is_empty ( ) || object_name_matches || any_sub_object_matches {
331+ ui. collapsing ( format ! ( "{:#06X}: {}" , index, & sdo_object. name) , |ui| {
332+ for ( sub_index, sub_object) in & sdo_object. sub_objects {
333+ let address = SdoAddress { index : * index, sub_index : * sub_index } ;
334+ // Change the label to a button
335+ let button_text = format ! ( "Sub {}: {}" , sub_index, & sub_object. name) ;
336+ if ui. button ( button_text) . clicked ( ) {
337+ // When clicked, open the modal for this specific SDO sub-object
338+ self . modal_open_for = Some ( address. clone ( ) ) ;
339+ if let Some ( sub) = self . subscriptions . get ( & address) {
340+ self . modal_interval_str = sub. interval_ms . to_string ( ) ;
341+ } else {
342+ self . modal_interval_str = "100" . to_string ( ) ;
343+ }
328344
345+ }
329346 }
330- }
331- } ) ;
347+ } ) ;
348+ }
332349 }
333350 } else {
334351 ui. label ( "Fetching SDO list..." ) ;
0 commit comments