fix loader, flickering

tychovrahe/trezor_r_passphrase_input
tychovrahe 2 years ago
parent 30e0934089
commit 0dd7e283b8

@ -278,7 +278,7 @@ impl<T: Clone + AsRef<str>> ButtonContainer<T> {
fn send_htc_event(&mut self, ctx: &mut EventCtx, event: Event) {
if matches!(self.button_type, ButtonType::HoldToConfirm) {
if let Some(hold_to_confirm) = &mut self.hold_to_confirm {
hold_to_confirm.inner_mut().event(ctx, event);
hold_to_confirm.event(ctx, event);
}
}
}
@ -390,7 +390,6 @@ impl<T: Clone + AsRef<str>> Component for ButtonController<T> {
type Msg = ButtonControllerMsg;
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
self.handle_hold_to_confirms(ctx, event);
// State machine for the ButtonController
match event {
Event::Button(button) => {
@ -485,7 +484,10 @@ impl<T: Clone + AsRef<str>> Component for ButtonController<T> {
self.state = new_state;
event
}
_ => None,
_ => {
self.handle_hold_to_confirms(ctx, event);
None
}
}
}

@ -190,9 +190,11 @@ impl<T: AsRef<str>> Component for Loader<T> {
if self.is_animating() {
if self.is_completely_grown(now) {
self.state = State::Grown;
ctx.request_paint();
return Some(LoaderMsg::GrownCompletely);
} else if self.is_completely_shrunk(now) {
self.state = State::Initial;
ctx.request_paint();
return Some(LoaderMsg::ShrunkCompletely);
} else {
// There is further progress in the animation, request an animation frame event.

@ -12,8 +12,8 @@ use super::{
};
pub struct ButtonPage<S, T> {
content: T,
scrollbar: ScrollBar,
content: Child<T>,
scrollbar: Child<ScrollBar>,
pad: Pad,
cancel_btn_details: Option<ButtonDetails<S>>,
confirm_btn_details: Option<ButtonDetails<S>>,
@ -30,8 +30,8 @@ where
/// Constructor for `&'static str` button-text type.
pub fn new_str(content: T, background: Color) -> Self {
Self {
content,
scrollbar: ScrollBar::vertical_to_be_filled_later(),
content: Child::new(content),
scrollbar: Child::new(ScrollBar::vertical_to_be_filled_later()),
pad: Pad::with_background(background),
cancel_btn_details: Some(ButtonDetails::cancel_icon()),
confirm_btn_details: Some(ButtonDetails::text("CONFIRM")),
@ -53,8 +53,8 @@ where
/// Constructor for `StrBuffer` button-text type.
pub fn new_str_buf(content: T, background: Color) -> Self {
Self {
content,
scrollbar: ScrollBar::vertical_to_be_filled_later(),
content: Child::new(content),
scrollbar: Child::new(ScrollBar::vertical_to_be_filled_later()),
pad: Pad::with_background(background),
cancel_btn_details: Some(ButtonDetails::cancel_icon()),
confirm_btn_details: Some(ButtonDetails::text("CONFIRM".into())),
@ -107,7 +107,7 @@ where
/// Change the page in the content, clear the background under it and make
/// sure it gets completely repainted. Also updating the buttons.
fn change_page(&mut self, ctx: &mut EventCtx, page: usize) {
self.content.change_page(page);
self.content.inner_mut().change_page(page);
self.content.request_complete_repaint(ctx);
self.update_buttons(ctx);
self.pad.clear();
@ -116,8 +116,8 @@ where
/// Reflecting the current page in the buttons.
fn update_buttons(&mut self, ctx: &mut EventCtx) {
let btn_layout = self.get_button_layout(
self.scrollbar.has_previous_page(),
self.scrollbar.has_next_page(),
self.scrollbar.inner().has_previous_page(),
self.scrollbar.inner().has_next_page(),
);
self.buttons.mutate(ctx, |ctx, buttons| {
buttons.set(ctx, btn_layout);
@ -166,8 +166,8 @@ where
self.content.place(content_area);
// Need to be called here, only after content is placed
// and we can calculate the page count
let page_count = self.content.page_count();
self.scrollbar.set_page_count(page_count);
let page_count = self.content.inner_mut().page_count();
self.scrollbar.inner_mut().set_page_count(page_count);
self.scrollbar.place(scrollbar_area);
self.set_buttons_for_initial_page(page_count);
self.buttons.place(button_area);
@ -175,26 +175,26 @@ where
}
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
ctx.set_page_count(self.scrollbar.page_count);
ctx.set_page_count(self.scrollbar.inner().page_count);
let button_event = self.buttons.event(ctx, event);
if let Some(ButtonControllerMsg::Triggered(pos)) = button_event {
match pos {
ButtonPos::Left => {
if self.scrollbar.has_previous_page() {
if self.scrollbar.inner().has_previous_page() {
// Clicked BACK. Scroll up.
self.scrollbar.go_to_previous_page();
self.change_page(ctx, self.scrollbar.active_page);
self.scrollbar.inner_mut().go_to_previous_page();
self.change_page(ctx, self.scrollbar.inner().active_page);
} else {
// Clicked CANCEL. Send result.
return Some(PageMsg::Controls(false));
}
}
ButtonPos::Right => {
if self.scrollbar.has_next_page() {
if self.scrollbar.inner().has_next_page() {
// Clicked NEXT. Scroll down.
self.scrollbar.go_to_next_page();
self.change_page(ctx, self.scrollbar.active_page);
self.scrollbar.inner_mut().go_to_next_page();
self.change_page(ctx, self.scrollbar.inner().active_page);
} else {
// Clicked CONFIRM. Send result.
return Some(PageMsg::Controls(true));
@ -232,7 +232,7 @@ where
fn get_btn_action(&self, pos: ButtonPos) -> String<25> {
match pos {
ButtonPos::Left => {
if self.scrollbar.has_previous_page() {
if self.scrollbar.inner().has_previous_page() {
ButtonAction::PrevPage.string()
} else if self.cancel_btn_details.is_some() {
ButtonAction::Cancel.string()
@ -241,7 +241,7 @@ where
}
}
ButtonPos::Right => {
if self.scrollbar.has_next_page() {
if self.scrollbar.inner().has_next_page() {
ButtonAction::NextPage.string()
} else if self.confirm_btn_details.is_some() {
ButtonAction::Confirm.string()
@ -255,8 +255,14 @@ where
fn trace(&self, t: &mut dyn crate::trace::Tracer) {
t.open("ButtonPage");
t.kw_pair("active_page", inttostr!(self.scrollbar.active_page as u8));
t.kw_pair("page_count", inttostr!(self.scrollbar.page_count as u8));
t.kw_pair(
"active_page",
inttostr!(self.scrollbar.inner().active_page as u8),
);
t.kw_pair(
"page_count",
inttostr!(self.scrollbar.inner().page_count as u8),
);
self.report_btn_actions(t);
// TODO: it seems the button text is not updated when paginating (but actions
// above are)

@ -13,6 +13,7 @@ use super::{
ButtonDetails, ButtonLayout, ChoiceFactory, ChoiceItem, ChoicePage, ChoicePageMsg,
MultilineTextChoiceItem,
};
use crate::ui::{component::Pad, model_tr::theme};
use heapless::String;
pub enum PinEntryMsg {
@ -97,6 +98,7 @@ impl ChoiceFactory for ChoiceFactoryPIN {
/// Component for entering a PIN.
pub struct PinEntry {
choice_page: ChoicePage<ChoiceFactoryPIN>,
pad: Pad,
show_real_pin: bool,
textbox: TextBox<MAX_PIN_LENGTH>,
}
@ -106,6 +108,7 @@ impl PinEntry {
let choices = ChoiceFactoryPIN::new(prompt);
Self {
pad: Pad::with_background(theme::BG),
choice_page: ChoicePage::new(choices)
.with_initial_page_counter(3)
.with_carousel(),
@ -157,7 +160,10 @@ impl Component for PinEntry {
type Msg = PinEntryMsg;
fn place(&mut self, bounds: Rect) -> Rect {
self.choice_page.place(bounds)
let split = bounds.split_top(7);
self.pad.place(split.0);
self.choice_page.place(split.1);
bounds
}
fn event(&mut self, ctx: &mut EventCtx, event: Event) -> Option<Self::Msg> {
@ -168,16 +174,19 @@ impl Component for PinEntry {
EXIT_INDEX => return Some(PinEntryMsg::Cancelled),
DELETE_INDEX => {
self.delete_last_digit(ctx);
self.pad.clear();
ctx.request_paint();
}
SHOW_INDEX => {
self.show_real_pin = true;
self.pad.clear();
ctx.request_paint();
}
PROMPT_INDEX => return Some(PinEntryMsg::Confirmed),
_ => {
if !self.is_full() {
self.append_new_digit(ctx, page_counter);
self.pad.clear();
// Choosing any random digit to be shown next
let new_page_counter =
random::uniform_between(4, (CHOICE_LENGTH - 1) as u32);
@ -192,6 +201,7 @@ impl Component for PinEntry {
}
fn paint(&mut self) {
self.pad.paint();
self.choice_page.paint();
self.update_situation();
}

Loading…
Cancel
Save