@@ -36,10 +36,14 @@ pub struct App {
36
36
pub ( crate ) current_page : Page ,
37
37
pub ( crate ) search_query : String ,
38
38
pub ( crate ) focus : Focus ,
39
- pub ( crate ) popup_text : String ,
40
- pub ( crate ) popup_action : PopupAction ,
41
- pub ( crate ) popup_percent_x : u16 ,
42
- pub ( crate ) popup_percent_y : u16 ,
39
+ pub ( crate ) popup : Popup ,
40
+ }
41
+
42
+ pub struct Popup {
43
+ pub ( crate ) text : String ,
44
+ pub ( crate ) action : PopupAction ,
45
+ pub ( crate ) percent_x : u16 ,
46
+ pub ( crate ) percent_y : u16 ,
43
47
}
44
48
45
49
impl App {
@@ -59,10 +63,12 @@ impl App {
59
63
current_page : Main ,
60
64
search_query : String :: from ( "" ) ,
61
65
focus : Focus :: MainPage ,
62
- popup_text : String :: from ( "" ) ,
63
- popup_action : PopupAction :: EditOtp ,
64
- popup_percent_x : 60 ,
65
- popup_percent_y : 20 ,
66
+ popup : Popup {
67
+ text : String :: from ( "" ) ,
68
+ action : PopupAction :: EditOtp ,
69
+ percent_x : 60 ,
70
+ percent_y : 20 ,
71
+ } ,
66
72
}
67
73
}
68
74
@@ -178,19 +184,23 @@ impl App {
178
184
self . render_table_box ( frame, rects[ 1 ] ) ;
179
185
frame. render_widget ( progress_bar, rects[ 2 ] ) ;
180
186
if self . focus == Focus :: Popup {
181
- let block = Block :: default ( ) . title ( "Alert" ) . borders ( Borders :: ALL ) ;
182
- let paragraph = Paragraph :: new ( & * self . popup_text )
183
- . block ( block)
184
- . alignment ( Alignment :: Center )
185
- . wrap ( Wrap { trim : true } ) ;
186
- let area = centered_rect ( self . popup_percent_x , self . popup_percent_y , frame. size ( ) ) ;
187
- frame. render_widget ( Clear , area) ; //this clears out the background
188
- frame. render_widget ( paragraph, area) ;
187
+ self . render_alert ( frame) ;
189
188
}
190
189
}
191
190
191
+ fn render_alert < B : Backend > ( & mut self , frame : & mut Frame < ' _ , B > ) {
192
+ let block = Block :: default ( ) . title ( "Alert" ) . borders ( Borders :: ALL ) ;
193
+ let paragraph = Paragraph :: new ( & * self . popup . text )
194
+ . block ( block)
195
+ . alignment ( Alignment :: Center )
196
+ . wrap ( Wrap { trim : true } ) ;
197
+ let area = centered_rect ( self . popup . percent_x , self . popup . percent_y , frame. size ( ) ) ;
198
+ frame. render_widget ( Clear , area) ;
199
+ //this clears out the background
200
+ frame. render_widget ( paragraph, area) ;
201
+ }
202
+
192
203
fn render_table_box < B : Backend > ( & mut self , frame : & mut Frame < ' _ , B > , area : Rect ) {
193
- // TODO If terminal is too little do not show info box
194
204
let constraints = if self . is_large_application ( frame) {
195
205
vec ! [ Constraint :: Percentage ( 80 ) , Constraint :: Percentage ( 20 ) ]
196
206
} else {
0 commit comments