Skip to content

Commit

Permalink
fixup! fix(core/mercury): improve handling and visual of swipes when …
Browse files Browse the repository at this point in the history
…displaying words
  • Loading branch information
matejcik committed Jun 30, 2024
1 parent 78c0252 commit d1d64f2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
24 changes: 12 additions & 12 deletions core/embed/rust/src/ui/model_mercury/component/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use crate::{
},
};

use heapless::String;

/// Component showing a task instruction, e.g. "Swipe up", and an optional
/// content consisting of one of these:
/// - a task description e.g. "Confirm transaction", or
Expand Down Expand Up @@ -94,6 +92,8 @@ impl<'a> Footer<'a> {
if let Some(ref mut content) = self.content {
if let Some(counter) = content.as_page_counter_mut() {
counter.update_current_page(n);
self.swipe_allow_down = counter.is_first_page();
self.swipe_allow_up = counter.is_last_page();
ctx.request_paint();
} else {
#[cfg(feature = "ui_debug")]
Expand Down Expand Up @@ -122,14 +122,6 @@ impl<'a> Footer<'a> {
..self
}
}

pub fn set_swipe_up(&mut self, allow: bool) {
self.swipe_allow_up = allow;
}

pub fn set_swipe_down(&mut self, allow: bool) {
self.swipe_allow_down = allow;
}
}

impl<'a> Component for Footer<'a> {
Expand Down Expand Up @@ -292,9 +284,9 @@ impl<'a> FooterContent<'a> {
#[derive(Clone)]
struct PageCounter {
area: Rect,
font: Font,
page_curr: u8,
page_max: u8,
font: Font,
}

impl PageCounter {
Expand All @@ -308,7 +300,15 @@ impl PageCounter {
}

fn update_current_page(&mut self, new_value: u8) {
self.page_curr = new_value;
self.page_curr = new_value.clamp(1, self.page_max);
}

fn is_first_page(&self) -> bool {
self.page_curr == 1
}

fn is_last_page(&self) -> bool {
self.page_curr == self.page_max
}
}

Expand Down
10 changes: 2 additions & 8 deletions core/embed/rust/src/ui/model_mercury/component/share_words.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,16 @@ impl<'a> Component for ShareWordsInner<'a> {
match event {
Event::Attach(_) => {
self.progress = 0;
self.footer.set_swipe_up(self.is_final_page());
self.footer.set_swipe_down(self.is_first_page());
}
Event::Swipe(SwipeEvent::End(dir)) => match dir {
SwipeDirection::Up if !self.is_final_page() => {
self.progress = 0;
self.page_index = (self.page_index + 1).min(self.share_words.len() as i16 - 1);
self.footer.set_swipe_up(self.is_final_page());
ctx.request_paint();
}
SwipeDirection::Down if !self.is_first_page() => {
self.progress = 0;
self.page_index = self.page_index.saturating_sub(1);
self.footer.set_swipe_down(self.is_first_page());
ctx.request_paint();
}
_ => {}
Expand All @@ -235,8 +231,6 @@ impl<'a> Component for ShareWordsInner<'a> {
_ => {}
}

self.footer.event(ctx, event);

None
}

Expand Down Expand Up @@ -303,11 +297,11 @@ impl<'a> Component for ShareWordsInner<'a> {

impl InternallySwipable for ShareWords<'_> {
fn current_page(&self) -> usize {
self.page_index as usize
self.frame.inner().page_index as usize
}

fn num_pages(&self) -> usize {
self.share_words.len()
self.frame.inner().share_words.len()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ use crate::{
text::paragraphs::{Paragraph, ParagraphSource, ParagraphVecShort, Paragraphs, VecExt},
ButtonRequestExt, ComponentExt, SwipeDirection,
},
constant::screen,
flow::{base::Decision, flow_store, FlowMsg, FlowState, FlowStore, SwipeFlow},
layout::obj::LayoutObj,
model_mercury::component::{Footer, InternallySwipableContent, SwipeContent},
model_mercury::component::SwipeContent,
},
};
use heapless::Vec;
Expand Down

0 comments on commit d1d64f2

Please sign in to comment.