1
1
use crate :: app:: EguiApp ;
2
2
use egui:: containers:: PopupCloseBehavior ;
3
- use egui:: { popup_below_widget, Context , Ui } ;
3
+ use egui:: { popup_below_widget, Context , Id , Response , TextEdit , Ui } ;
4
4
use java_asm_server:: AsmServer ;
5
5
use std:: ops:: Deref ;
6
6
@@ -38,16 +38,23 @@ impl EguiApp {
38
38
fn file_path_input ( & mut self , ui : & mut Ui ) {
39
39
let mut locked_top = self . server_app . top ( ) . lock ( ) ;
40
40
let Some ( file_path) = & mut locked_top. file_path else { return ; } ;
41
- let edit_path_ui = ui. text_edit_singleline ( file_path) ;
42
41
43
- let popup_id = ui. make_persistent_id ( "file_path_popup" ) ;
42
+ let edit_path_ui = Self :: file_path_input_area ( ui, file_path) ;
43
+
44
+ let popup_id = Id :: new ( "file_path_popup" ) ;
44
45
if edit_path_ui. gained_focus ( ) {
45
46
let server_locked = self . server . lock ( ) ;
46
47
let Some ( server) = server_locked. deref ( ) else { return ; } ;
47
48
server. search ( & mut locked_top) ;
48
49
ui. memory_mut ( |m| m. open_popup ( popup_id) ) ;
49
50
}
50
51
52
+ if edit_path_ui. changed ( ) {
53
+ let server_locked = self . server . lock ( ) ;
54
+ let Some ( server) = server_locked. deref ( ) else { return ; } ;
55
+ server. search ( & mut locked_top) ;
56
+ }
57
+
51
58
let search_results = locked_top. search_result . clone ( ) ;
52
59
drop ( locked_top) ;
53
60
@@ -56,20 +63,38 @@ impl EguiApp {
56
63
ui, popup_id, & edit_path_ui,
57
64
PopupCloseBehavior :: CloseOnClickOutside , |ui| {
58
65
ui. vertical ( |ui| {
59
- for result in search_results {
60
- if ui. label ( result. to_string ( ) ) . clicked ( ) {
61
- let server_locked = self . server . lock ( ) ;
62
- let Some ( server) = server_locked. deref ( ) else { return ; } ;
63
- let mut content_locked = self . server_app . content ( ) . lock ( ) ;
64
- let mut locked_top = self . server_app . top ( ) . lock ( ) ;
65
- let accessor = server. accessor . lock ( ) ;
66
- let Some ( accessor) = accessor. deref ( ) else { return ; } ;
67
- server. switch_or_open_lock_free (
68
- & result, accessor, & mut content_locked, & mut locked_top,
69
- ) ;
70
- }
71
- }
66
+ Self :: popup_file_path_ui ( self , ui) ;
72
67
} )
73
68
} ) ;
74
69
}
70
+
71
+ fn file_path_input_area ( ui : & mut Ui , file_path : & mut String ) -> Response {
72
+ let id_for_input_remaining = Id :: new ( "file_path_input_area_remaining" ) ;
73
+ let max_width = ui. max_rect ( ) . width ( ) ;
74
+ let last_time_remaining = ui
75
+ . data ( |data| data. get_temp ( id_for_input_remaining)
76
+ . unwrap_or ( max_width) ) ;
77
+ let target_width_for_content = max_width - last_time_remaining;
78
+
79
+ let edit_path_ui = TextEdit :: singleline ( file_path)
80
+ . desired_width ( target_width_for_content) . show ( ui) . response ;
81
+
82
+ let remaining_width = ui. min_rect ( ) . width ( ) - target_width_for_content;
83
+ ui. data_mut ( |data| {
84
+ data. insert_temp ( id_for_input_remaining, remaining_width) ;
85
+ } ) ;
86
+ edit_path_ui
87
+ }
88
+
89
+ fn popup_file_path_ui ( & mut self , ui : & mut Ui ) {
90
+ let search_results = self . server_app . top ( ) . lock ( ) . search_result . clone ( ) ;
91
+ for result in search_results {
92
+ let selectable_label = ui. selectable_label ( false , result. to_string ( ) ) ;
93
+ if selectable_label. clicked ( ) {
94
+ let server_locked = self . server . lock ( ) ;
95
+ let Some ( server) = server_locked. deref ( ) else { return ; } ;
96
+ server. switch_or_open ( & result, & self . server_app ) ;
97
+ }
98
+ }
99
+ }
75
100
}
0 commit comments