@@ -2,7 +2,7 @@ use crate::{
2
2
strutil:: TString ,
3
3
ui:: {
4
4
component:: {
5
- maybe:: paint_overlapping, Child , Component , Event , EventCtx , Label , Maybe , Swipe ,
5
+ maybe:: paint_overlapping, Component , Event , EventCtx , Label , Maybe , Swipe ,
6
6
SwipeDirection ,
7
7
} ,
8
8
geometry:: { Alignment , Grid , Insets , Rect } ,
@@ -24,17 +24,17 @@ pub enum MnemonicKeyboardMsg {
24
24
25
25
pub struct MnemonicKeyboard < T > {
26
26
/// Initial prompt, displayed on empty input.
27
- prompt : Child < Maybe < Label < ' static > > > ,
27
+ prompt : Maybe < Label < ' static > > ,
28
28
/// Delete a char button.
29
- erase : Child < Maybe < Button > > ,
29
+ erase : Maybe < Button > ,
30
30
/// Go to previous word button
31
- back : Child < Maybe < Button > > ,
31
+ back : Maybe < Button > ,
32
32
/// Input area, acting as the auto-complete and confirm button.
33
- input : Child < Maybe < T > > ,
33
+ input : Maybe < T > ,
34
34
/// Area with keypads - used for rounded overlay
35
35
keypad_area : Rect ,
36
36
/// Key buttons.
37
- keys : [ Child < Button > ; MNEMONIC_KEY_COUNT ] ,
37
+ keys : [ Button ; MNEMONIC_KEY_COUNT ] ,
38
38
/// Swipe controller - allowing for going to the previous word.
39
39
swipe : Swipe ,
40
40
/// Whether going back is allowed (is not on the very first word).
@@ -56,26 +56,20 @@ where
56
56
. styled ( theme:: button_default ( ) )
57
57
. with_expanded_touch_area ( Insets :: right ( BACK_BUTTON_RIGHT_EXPAND ) ) ;
58
58
Self {
59
- prompt : Child :: new ( Maybe :: new (
59
+ prompt : Maybe :: new (
60
60
theme:: BG ,
61
61
Label :: centered ( prompt, theme:: TEXT_MAIN_GREY_LIGHT ) . vertically_centered ( ) ,
62
62
prompt_visible,
63
- ) ) ,
64
- erase : Child :: new ( Maybe :: new ( theme:: BG , erase_btn, !prompt_visible) ) ,
65
- back : Child :: new ( Maybe :: new (
66
- theme:: BG ,
67
- back_btn,
68
- prompt_visible && can_go_back,
69
- ) ) ,
70
- input : Child :: new ( Maybe :: new ( theme:: BG , input, !prompt_visible) ) ,
63
+ ) ,
64
+ erase : Maybe :: new ( theme:: BG , erase_btn, !prompt_visible) ,
65
+ back : Maybe :: new ( theme:: BG , back_btn, prompt_visible && can_go_back) ,
66
+ input : Maybe :: new ( theme:: BG , input, !prompt_visible) ,
71
67
keypad_area : Rect :: zero ( ) ,
72
- keys : T :: keys ( )
73
- . map ( |t| {
74
- Button :: with_text ( t. into ( ) )
75
- . styled ( theme:: button_keyboard ( ) )
76
- . with_text_align ( Alignment :: Center )
77
- } )
78
- . map ( Child :: new) ,
68
+ keys : T :: keys ( ) . map ( |t| {
69
+ Button :: with_text ( t. into ( ) )
70
+ . styled ( theme:: button_keyboard ( ) )
71
+ . with_text_align ( Alignment :: Center )
72
+ } ) ,
79
73
swipe : Swipe :: new ( ) . right ( ) ,
80
74
can_go_back,
81
75
}
@@ -90,32 +84,23 @@ where
90
84
/// completion mask and the pending key.
91
85
fn toggle_key_buttons ( & mut self , ctx : & mut EventCtx ) {
92
86
for ( key, btn) in self . keys . iter_mut ( ) . enumerate ( ) {
93
- let enabled = self
94
- . input
95
- . inner ( )
96
- . inner ( )
97
- . can_key_press_lead_to_a_valid_word ( key) ;
98
- btn. mutate ( ctx, |ctx, b| b. enable_if ( ctx, enabled) ) ;
87
+ let enabled = self . input . inner ( ) . can_key_press_lead_to_a_valid_word ( key) ;
88
+ btn. enable_if ( ctx, enabled) ;
99
89
}
100
90
}
101
91
102
92
/// After edit operations, we need to either show or hide the prompt, the
103
93
/// input, the erase button and the back button.
104
94
fn toggle_prompt_or_input ( & mut self , ctx : & mut EventCtx ) {
105
- let prompt_visible = self . input . inner ( ) . inner ( ) . is_empty ( ) ;
106
- self . prompt
107
- . mutate ( ctx, |ctx, p| p. show_if ( ctx, prompt_visible) ) ;
108
- self . input
109
- . mutate ( ctx, |ctx, i| i. show_if ( ctx, !prompt_visible) ) ;
110
- self . erase
111
- . mutate ( ctx, |ctx, b| b. show_if ( ctx, !prompt_visible) ) ;
112
- self . back . mutate ( ctx, |ctx, b| {
113
- b. show_if ( ctx, prompt_visible && self . can_go_back )
114
- } ) ;
95
+ let prompt_visible = self . input . inner ( ) . is_empty ( ) ;
96
+ self . prompt . show_if ( ctx, prompt_visible) ;
97
+ self . input . show_if ( ctx, !prompt_visible) ;
98
+ self . erase . show_if ( ctx, !prompt_visible) ;
99
+ self . back . show_if ( ctx, prompt_visible && self . can_go_back ) ;
115
100
}
116
101
117
102
pub fn mnemonic ( & self ) -> Option < & ' static str > {
118
- self . input . inner ( ) . inner ( ) . mnemonic ( )
103
+ self . input . inner ( ) . mnemonic ( )
119
104
}
120
105
}
121
106
@@ -181,23 +166,20 @@ where
181
166
182
167
match self . erase . event ( ctx, event) {
183
168
Some ( ButtonMsg :: Clicked ) => {
184
- self . input
185
- . mutate ( ctx, |ctx, i| i. inner_mut ( ) . on_backspace_click ( ctx) ) ;
169
+ self . input . inner_mut ( ) . on_backspace_click ( ctx) ;
186
170
self . on_input_change ( ctx) ;
187
171
return None ;
188
172
}
189
173
Some ( ButtonMsg :: LongPressed ) => {
190
- self . input
191
- . mutate ( ctx, |ctx, i| i. inner_mut ( ) . on_backspace_long_press ( ctx) ) ;
174
+ self . input . inner_mut ( ) . on_backspace_long_press ( ctx) ;
192
175
self . on_input_change ( ctx) ;
193
176
return None ;
194
177
}
195
178
_ => { }
196
179
}
197
180
for ( key, btn) in self . keys . iter_mut ( ) . enumerate ( ) {
198
181
if let Some ( ButtonMsg :: Clicked ) = btn. event ( ctx, event) {
199
- self . input
200
- . mutate ( ctx, |ctx, i| i. inner_mut ( ) . on_key_click ( ctx, key) ) ;
182
+ self . input . inner_mut ( ) . on_key_click ( ctx, key) ;
201
183
self . on_input_change ( ctx) ;
202
184
return None ;
203
185
}
@@ -213,7 +195,7 @@ where
213
195
}
214
196
215
197
fn render < ' s > ( & ' s self , target : & mut impl Renderer < ' s > ) {
216
- if self . input . inner ( ) . inner ( ) . is_empty ( ) {
198
+ if self . input . inner ( ) . is_empty ( ) {
217
199
self . prompt . render ( target) ;
218
200
if self . can_go_back {
219
201
self . back . render ( target) ;
0 commit comments