@@ -41,15 +41,19 @@ pub struct ButtonHandler {
4141}
4242
4343pub struct ButtonsHandler {
44+ default_handler : Option < HandlersDerive > ,
45+
4446 handlers : Vec < ButtonHandler > ,
4547 press_time : Instant ,
4648 last_hold_execute : Instant ,
4749 current_handler_down : Option < usize > ,
4850}
4951
5052impl ButtonsHandler {
51- pub fn new ( ) -> Self {
53+ pub fn new ( default_handler : Option < HandlersDerive > ) -> Self {
5254 Self {
55+ default_handler,
56+
5357 handlers : Vec :: new ( ) ,
5458 press_time : Instant :: now ( ) ,
5559 last_hold_execute : Instant :: now ( ) ,
@@ -139,6 +143,12 @@ impl ButtonsHandler {
139143 . enumerate ( )
140144 . find ( |( _, h) | h. button == button) ;
141145
146+ if let Some ( ref default_handler) = self . default_handler {
147+ _ = default_handler
148+ . execute ( & ButtonTrigger :: Down , 0 , state)
149+ . await ;
150+ }
151+
142152 if let Some ( ( i, handler) ) = & mut handler {
143153 self . current_handler_down = Some ( * i) ;
144154
@@ -225,10 +235,16 @@ impl ButtonsHandler {
225235 return ;
226236 }
227237
238+ let hold_time = ( Instant :: now ( ) - self . press_time ) . as_millis ( ) ;
239+ if let Some ( ref default_handler) = self . default_handler {
240+ _ = default_handler
241+ . execute ( & ButtonTrigger :: Up , hold_time, state)
242+ . await ;
243+ }
244+
228245 let handler = & self . handlers [ self . current_handler_down . expect ( "Cant fail" ) ] ;
229246 let handlers = handler. handlers . iter ( ) . filter ( |h| h. 0 == ButtonTrigger :: Up ) ;
230247 for handler in handlers {
231- let hold_time = ( Instant :: now ( ) - self . press_time ) . as_millis ( ) ;
232248 let res = handler. 2 . execute ( & handler. 0 , hold_time, state) . await ;
233249 if let Err ( e) = res {
234250 log:: error!( "buttons_handler:up_err: {e:?}" ) ;
0 commit comments