using middle button evaluated in C for all screens that are using it. other screens might have problem with middle button - show pressed button with no unrelease on middle click. experimental

tychovrahe/double_btn
tychovrahe 2 years ago
parent 2cfe0c8f6e
commit 793ca7cfd9

@ -8,8 +8,9 @@ use crate::{
};
use core::ops::Deref;
use super::{theme, BothButtonPressHandler, Button, ButtonMsg, ButtonPos};
use super::{theme, Button, ButtonMsg, ButtonPos};
use heapless::{String, Vec};
use crate::ui::event::{ButtonEvent, PhysicalButton};
pub enum Bip39PageMsg {
Confirmed,
@ -24,7 +25,6 @@ const WORD_THRESHOLD: usize = 10;
pub struct Bip39Page<T> {
prompt: T,
letter_choices: Vec<char, 26>,
both_button_press: BothButtonPressHandler,
pad: Pad,
delete: Button<&'static str>,
prev: Button<&'static str>,
@ -48,7 +48,6 @@ where
Self {
prompt,
letter_choices,
both_button_press: BothButtonPressHandler::new(),
pad: Pad::with_background(theme::BG),
delete: Button::with_text(ButtonPos::Left, "BIN", theme::button_default()),
prev: Button::with_text(ButtonPos::Left, "BACK", theme::button_default()),
@ -239,13 +238,10 @@ where
}
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
// Possibly replacing or skipping an event because of both-button-press
// aggregation
let event = self.both_button_press.possibly_replace_event(event)?;
// In case of both-button-press, changing all other buttons to released
// state
if self.both_button_press.are_both_buttons_pressed(event) {
if let Event::Button(ButtonEvent::ButtonPressed(PhysicalButton::Both)) = event{
self.set_right_and_left_buttons_as_released(ctx);
}

@ -5,8 +5,9 @@ use crate::ui::{
};
use core::ops::Deref;
use super::{theme, BothButtonPressHandler, Button, ButtonMsg, ButtonPos};
use super::{theme, Button, ButtonMsg, ButtonPos};
use heapless::Vec;
use crate::ui::event::{ButtonEvent, PhysicalButton};
pub enum ChoicePageMsg {
Confirmed,
@ -18,7 +19,6 @@ pub struct ChoicePage<T, const N: usize> {
major_prompt: T,
minor_prompt: T,
choices: Vec<T, N>,
both_button_press: BothButtonPressHandler,
pad: Pad,
prev: Button<&'static str>,
next: Button<&'static str>,
@ -35,7 +35,6 @@ where
major_prompt,
minor_prompt,
choices,
both_button_press: BothButtonPressHandler::new(),
pad: Pad::with_background(theme::BG),
prev: Button::with_text(ButtonPos::Left, "BACK", theme::button_default()),
next: Button::with_text(ButtonPos::Right, "NEXT", theme::button_default()),
@ -139,13 +138,10 @@ where
}
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
// Possibly replacing or skipping an event because of both-button-press
// aggregation
let event = self.both_button_press.possibly_replace_event(event)?;
// In case of both-button-press, changing all other buttons to released
// state
if self.both_button_press.are_both_buttons_pressed(event) {
if let Event::Button(ButtonEvent::ButtonPressed(PhysicalButton::Both)) = event{
self.set_right_and_left_buttons_as_released(ctx);
}

@ -8,8 +8,9 @@ use crate::{
};
use core::ops::Deref;
use super::{theme, BothButtonPressHandler, Button, ButtonMsg, ButtonPos};
use super::{theme, Button, ButtonMsg, ButtonPos};
use heapless::String;
use crate::ui::event::{ButtonEvent, PhysicalButton};
pub enum PassphrasePageMsg {
Confirmed,
@ -61,7 +62,6 @@ pub struct PassphrasePage<T> {
digits_choices: [&'static str; 10],
special_choices: [&'static str; 30],
menu_choices: [&'static str; 4],
both_button_press: BothButtonPressHandler,
pad: Pad,
menu_left: Button<&'static str>,
menu_right: Button<&'static str>,
@ -91,7 +91,6 @@ where
digits_choices: DIGITS,
special_choices: SPECIAL_SYMBOLS,
menu_choices: MENU,
both_button_press: BothButtonPressHandler::new(),
pad: Pad::with_background(theme::BG),
menu_left: Button::with_text(ButtonPos::Left, "MENU", theme::button_default()),
menu_right: Button::with_text(ButtonPos::Right, "MENU", theme::button_default()),
@ -498,13 +497,10 @@ where
}
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
// Possibly replacing or skipping an event because of both-button-press
// aggregation
let event = self.both_button_press.possibly_replace_event(event)?;
// In case of both-button-press, changing all other buttons to released
// state
if self.both_button_press.are_both_buttons_pressed(event) {
if let Event::Button(ButtonEvent::ButtonPressed(PhysicalButton::Both)) = event{
self.set_right_and_left_buttons_as_released(ctx);
}

Loading…
Cancel
Save