mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
feat(core): add disable haptic option to tt ui button
[no changelog]
This commit is contained in:
parent
04d5017228
commit
c680187b0e
@ -1,5 +1,5 @@
|
||||
#[cfg(feature = "haptic")]
|
||||
use crate::trezorhal::haptic::{play, HapticEffect};
|
||||
use crate::trezorhal::haptic::{self, HapticEffect};
|
||||
use crate::{
|
||||
strutil::TString,
|
||||
time::Duration,
|
||||
@ -30,6 +30,7 @@ pub struct Button {
|
||||
state: State,
|
||||
long_press: Option<Duration>,
|
||||
long_timer: Option<TimerToken>,
|
||||
haptics: bool,
|
||||
}
|
||||
|
||||
impl Button {
|
||||
@ -46,6 +47,7 @@ impl Button {
|
||||
state: State::Initial,
|
||||
long_press: None,
|
||||
long_timer: None,
|
||||
haptics: true,
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,6 +86,11 @@ impl Button {
|
||||
self
|
||||
}
|
||||
|
||||
pub const fn without_haptics(mut self) -> Self {
|
||||
self.haptics = false;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn enable_if(&mut self, ctx: &mut EventCtx, enabled: bool) {
|
||||
if enabled {
|
||||
self.enable(ctx);
|
||||
@ -252,7 +259,9 @@ impl Component for Button {
|
||||
// Touch started in our area, transform to `Pressed` state.
|
||||
if touch_area.contains(pos) {
|
||||
#[cfg(feature = "haptic")]
|
||||
play(HapticEffect::ButtonPress);
|
||||
if self.haptics {
|
||||
haptic::play(HapticEffect::ButtonPress);
|
||||
}
|
||||
self.set(ctx, State::Pressed);
|
||||
if let Some(duration) = self.long_press {
|
||||
self.long_timer = Some(ctx.request_timer(duration));
|
||||
@ -296,7 +305,9 @@ impl Component for Button {
|
||||
self.long_timer = None;
|
||||
if matches!(self.state, State::Pressed) {
|
||||
#[cfg(feature = "haptic")]
|
||||
play(HapticEffect::ButtonPress);
|
||||
if self.haptics {
|
||||
haptic::play(HapticEffect::ButtonPress);
|
||||
}
|
||||
self.set(ctx, State::Initial);
|
||||
return Some(ButtonMsg::LongPressed);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user