@@ -131,52 +131,42 @@ fn Screen(hooks: Hooks, props: &ScreenProps) -> impl Into<AnyElement<'static>> {
131
131
}
132
132
133
133
#[ derive( Default , Props ) ]
134
- struct ButtonProps {
134
+ struct CalculatorButtonProps {
135
135
label : String ,
136
136
style : Option < ButtonStyle > ,
137
137
on_click : Handler < ' static , ( ) > ,
138
138
}
139
139
140
140
#[ component]
141
- fn Button ( props : & mut ButtonProps , mut hooks : Hooks ) -> impl Into < AnyElement < ' static > > {
141
+ fn CalculatorButton ( props : & mut CalculatorButtonProps ) -> impl Into < AnyElement < ' static > > {
142
142
let style = props. style . unwrap ( ) ;
143
143
144
- hooks. use_local_terminal_events ( {
145
- let mut on_click = std:: mem:: take ( & mut props. on_click ) ;
146
- move |event| match event {
147
- TerminalEvent :: FullscreenMouse ( FullscreenMouseEvent { kind, .. } )
148
- if matches ! ( kind, MouseEventKind :: Down ( _) ) =>
149
- {
150
- on_click ( ( ) ) ;
151
- }
152
- _ => { }
153
- }
154
- } ) ;
155
-
156
144
element ! {
157
- Box (
158
- border_style: BorderStyle :: Custom ( BorderCharacters {
159
- top: '▁' ,
160
- ..Default :: default ( )
161
- } ) ,
162
- border_edges: Edges :: Top ,
163
- border_color: style. trim_color,
164
- flex_grow: 1.0 ,
165
- margin_left: 1 ,
166
- margin_right: 1 ,
167
- ) {
145
+ Button ( handler: props. on_click. take( ) ) {
168
146
Box (
169
- background_color: style. color,
170
- justify_content: JustifyContent :: Center ,
171
- align_items: AlignItems :: Center ,
172
- height: 3 ,
147
+ border_style: BorderStyle :: Custom ( BorderCharacters {
148
+ top: '▁' ,
149
+ ..Default :: default ( )
150
+ } ) ,
151
+ border_edges: Edges :: Top ,
152
+ border_color: style. trim_color,
173
153
flex_grow: 1.0 ,
154
+ margin_left: 1 ,
155
+ margin_right: 1 ,
174
156
) {
175
- Text (
176
- content: & props. label,
177
- color: style. text_color,
178
- weight: Weight :: Bold ,
179
- )
157
+ Box (
158
+ background_color: style. color,
159
+ justify_content: JustifyContent :: Center ,
160
+ align_items: AlignItems :: Center ,
161
+ height: 3 ,
162
+ flex_grow: 1.0 ,
163
+ ) {
164
+ Text (
165
+ content: & props. label,
166
+ color: style. text_color,
167
+ weight: Weight :: Bold ,
168
+ )
169
+ }
180
170
}
181
171
}
182
172
}
@@ -313,34 +303,34 @@ fn Calculator(mut hooks: Hooks) -> impl Into<AnyElement<'static>> {
313
303
Screen ( content: expr. to_string( ) )
314
304
}
315
305
Box ( width: 100 pct) {
316
- Button ( label: "←" , style: fn_button_style, on_click: move |_| handle_backspace( ) )
317
- Button ( label: "±" , style: fn_button_style, on_click: move |_| handle_plus_minus( ) )
318
- Button ( label: "%" , style: fn_button_style, on_click: move |_| handle_percent( ) )
319
- Button ( label: "÷" , style: operator_button_style, on_click: move |_| handle_operator( '÷' ) )
306
+ CalculatorButton ( label: "←" , style: fn_button_style, on_click: move |_| handle_backspace( ) )
307
+ CalculatorButton ( label: "±" , style: fn_button_style, on_click: move |_| handle_plus_minus( ) )
308
+ CalculatorButton ( label: "%" , style: fn_button_style, on_click: move |_| handle_percent( ) )
309
+ CalculatorButton ( label: "÷" , style: operator_button_style, on_click: move |_| handle_operator( '÷' ) )
320
310
}
321
311
Box ( width: 100 pct) {
322
- Button ( label: "7" , style: numpad_button_style, on_click: move |_| handle_number( 7 ) )
323
- Button ( label: "8" , style: numpad_button_style, on_click: move |_| handle_number( 8 ) )
324
- Button ( label: "9" , style: numpad_button_style, on_click: move |_| handle_number( 9 ) )
325
- Button ( label: "×" , style: operator_button_style, on_click: move |_| handle_operator( '×' ) )
312
+ CalculatorButton ( label: "7" , style: numpad_button_style, on_click: move |_| handle_number( 7 ) )
313
+ CalculatorButton ( label: "8" , style: numpad_button_style, on_click: move |_| handle_number( 8 ) )
314
+ CalculatorButton ( label: "9" , style: numpad_button_style, on_click: move |_| handle_number( 9 ) )
315
+ CalculatorButton ( label: "×" , style: operator_button_style, on_click: move |_| handle_operator( '×' ) )
326
316
}
327
317
Box ( width: 100 pct) {
328
- Button ( label: "4" , style: numpad_button_style, on_click: move |_| handle_number( 4 ) )
329
- Button ( label: "5" , style: numpad_button_style, on_click: move |_| handle_number( 5 ) )
330
- Button ( label: "6" , style: numpad_button_style, on_click: move |_| handle_number( 6 ) )
331
- Button ( label: "-" , style: operator_button_style, on_click: move |_| handle_operator( '-' ) )
318
+ CalculatorButton ( label: "4" , style: numpad_button_style, on_click: move |_| handle_number( 4 ) )
319
+ CalculatorButton ( label: "5" , style: numpad_button_style, on_click: move |_| handle_number( 5 ) )
320
+ CalculatorButton ( label: "6" , style: numpad_button_style, on_click: move |_| handle_number( 6 ) )
321
+ CalculatorButton ( label: "-" , style: operator_button_style, on_click: move |_| handle_operator( '-' ) )
332
322
}
333
323
Box ( width: 100 pct) {
334
- Button ( label: "1" , style: numpad_button_style, on_click: move |_| handle_number( 1 ) )
335
- Button ( label: "2" , style: numpad_button_style, on_click: move |_| handle_number( 2 ) )
336
- Button ( label: "3" , style: numpad_button_style, on_click: move |_| handle_number( 3 ) )
337
- Button ( label: "+" , style: operator_button_style, on_click: move |_| handle_operator( '+' ) )
324
+ CalculatorButton ( label: "1" , style: numpad_button_style, on_click: move |_| handle_number( 1 ) )
325
+ CalculatorButton ( label: "2" , style: numpad_button_style, on_click: move |_| handle_number( 2 ) )
326
+ CalculatorButton ( label: "3" , style: numpad_button_style, on_click: move |_| handle_number( 3 ) )
327
+ CalculatorButton ( label: "+" , style: operator_button_style, on_click: move |_| handle_operator( '+' ) )
338
328
}
339
329
Box ( width: 100 pct) {
340
- Button ( label: "C" , style: theme. clear_button_style( ) , on_click: move |_| handle_clear( ) )
341
- Button ( label: "0" , style: numpad_button_style, on_click: move |_| handle_number( 0 ) )
342
- Button ( label: "." , style: numpad_button_style, on_click: move |_| handle_decimal( ) )
343
- Button ( label: "=" , style: operator_button_style, on_click: move |_| handle_equals( ) )
330
+ CalculatorButton ( label: "C" , style: theme. clear_button_style( ) , on_click: move |_| handle_clear( ) )
331
+ CalculatorButton ( label: "0" , style: numpad_button_style, on_click: move |_| handle_number( 0 ) )
332
+ CalculatorButton ( label: "." , style: numpad_button_style, on_click: move |_| handle_decimal( ) )
333
+ CalculatorButton ( label: "=" , style: operator_button_style, on_click: move |_| handle_equals( ) )
344
334
}
345
335
}
346
336
}
0 commit comments