Skip to content

Commit ab3358c

Browse files
Lbqdsyogh333
authored andcommitted
Update the MultiFieldReview to align with app-bitcoin
1 parent 64dbbab commit ab3358c

File tree

1 file changed

+51
-22
lines changed

1 file changed

+51
-22
lines changed

ledger_device_sdk/src/ui/gadgets.rs

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ pub struct Field<'a> {
730730
}
731731

732732
impl<'a> Field<'a> {
733-
pub fn event_loop(&self, incoming_direction: ButtonEvent) -> ButtonEvent {
733+
pub fn event_loop(&self, incoming_direction: ButtonEvent, is_first_field: bool) -> ButtonEvent {
734734
let mut buttons = ButtonsState::new();
735735
let chunk_max_lines = layout::MAX_LINES - 1;
736736
let page_count = 1 + self.value.len() / (chunk_max_lines * MAX_CHAR_PER_LINE);
@@ -778,8 +778,10 @@ impl<'a> Field<'a> {
778778
.trim_end_matches(' ');
779779
chunks[0] = Label::from(header).bold();
780780

781-
LEFT_ARROW.display();
782-
RIGHT_ARROW.display();
781+
if !is_first_field {
782+
bagls::LEFT_ARROW.display();
783+
}
784+
bagls::RIGHT_ARROW.display();
783785

784786
chunks.place(Location::Middle, Layout::Centered, false);
785787

@@ -824,7 +826,7 @@ pub struct MultiFieldReview<'a> {
824826
fields: &'a [Field<'a>],
825827
review_message: &'a [&'a str],
826828
review_glyph: Option<&'a Glyph<'a>>,
827-
validation_message: &'a str,
829+
validation_message: [&'a str; 2],
828830
validation_glyph: Option<&'a Glyph<'a>>,
829831
cancel_message: &'a str,
830832
cancel_glyph: Option<&'a Glyph<'a>>,
@@ -853,7 +855,7 @@ impl<'a> MultiFieldReview<'a> {
853855
fields: &'a [Field<'a>],
854856
review_message: &'a [&'a str],
855857
review_glyph: Option<&'a Glyph<'a>>,
856-
validation_message: &'a str,
858+
validation_message: [&'a str; 2],
857859
validation_glyph: Option<&'a Glyph<'a>>,
858860
cancel_message: &'a str,
859861
cancel_glyph: Option<&'a Glyph<'a>>,
@@ -870,27 +872,25 @@ impl<'a> MultiFieldReview<'a> {
870872
}
871873

872874
pub fn show(&self) -> bool {
873-
let first_page = match self.review_message.len() {
874-
0 => Page::new(PageStyle::PictureNormal, ["", ""], self.review_glyph),
875-
1 => Page::new(
875+
let first_page_opt = match self.review_message.len() {
876+
0 => None,
877+
1 => Some(Page::new(
876878
PageStyle::PictureBold,
877879
[self.review_message[0], ""],
878880
self.review_glyph,
879-
),
880-
_ => Page::new(
881+
)),
882+
_ => Some(Page::new(
881883
PageStyle::PictureNormal,
882884
[self.review_message[0], self.review_message[1]],
883885
self.review_glyph,
884-
),
886+
)),
885887
};
886888

887-
clear_screen();
888-
first_page.place_and_wait();
889-
crate::ui::screen_util::screen_update();
889+
display_first_page(&first_page_opt);
890890

891891
let validation_page = Page::new(
892892
PageStyle::PictureBold,
893-
[self.validation_message, ""],
893+
self.validation_message,
894894
self.validation_glyph,
895895
);
896896
let cancel_page = Page::new(
@@ -904,9 +904,10 @@ impl<'a> MultiFieldReview<'a> {
904904

905905
loop {
906906
match cur_page {
907-
cancel if cancel == self.fields.len() => {
907+
cancel if cancel == self.fields.len() + 1 => {
908908
let mut buttons = ButtonsState::new();
909909
clear_screen();
910+
bagls::LEFT_ARROW.display();
910911
cancel_page.place();
911912
crate::ui::screen_util::screen_update();
912913
loop {
@@ -915,24 +916,31 @@ impl<'a> MultiFieldReview<'a> {
915916
cur_page = cur_page.saturating_sub(1);
916917
break;
917918
}
918-
Some(ButtonEvent::RightButtonRelease) => {
919-
cur_page += 1;
920-
break;
921-
}
922919
Some(ButtonEvent::BothButtonsRelease) => return false,
923920
_ => (),
924921
}
925922
}
926923
}
927-
validation if validation == self.fields.len() + 1 => {
924+
validation if validation == self.fields.len() => {
928925
let mut buttons = ButtonsState::new();
929926
clear_screen();
927+
bagls::LEFT_ARROW.display();
928+
bagls::RIGHT_ARROW.display();
930929
validation_page.place();
931930
crate::ui::screen_util::screen_update();
932931
loop {
933932
match get_event(&mut buttons) {
934933
Some(ButtonEvent::LeftButtonRelease) => {
935934
cur_page = cur_page.saturating_sub(1);
935+
if cur_page == 0 && self.fields.is_empty() {
936+
display_first_page(&first_page_opt);
937+
} else {
938+
direction = ButtonEvent::LeftButtonRelease;
939+
}
940+
break;
941+
}
942+
Some(ButtonEvent::RightButtonRelease) => {
943+
cur_page += 1;
936944
break;
937945
}
938946
Some(ButtonEvent::BothButtonsRelease) => return true,
@@ -941,10 +949,12 @@ impl<'a> MultiFieldReview<'a> {
941949
}
942950
}
943951
_ => {
944-
direction = self.fields[cur_page].event_loop(direction);
952+
direction = self.fields[cur_page]
953+
.event_loop(direction, cur_page == 0 && first_page_opt.is_none());
945954
match direction {
946955
ButtonEvent::LeftButtonRelease => {
947956
if cur_page == 0 {
957+
display_first_page(&first_page_opt);
948958
direction = ButtonEvent::RightButtonRelease;
949959
} else {
950960
cur_page -= 1;
@@ -960,3 +970,22 @@ impl<'a> MultiFieldReview<'a> {
960970
}
961971
}
962972
}
973+
974+
fn display_first_page(page_opt: &Option<Page>) {
975+
match page_opt {
976+
Some(page) => {
977+
clear_screen();
978+
bagls::RIGHT_ARROW.display();
979+
page.place();
980+
crate::ui::screen_util::screen_update();
981+
982+
let mut buttons = ButtonsState::new();
983+
loop {
984+
if let Some(ButtonEvent::RightButtonRelease) = get_event(&mut buttons) {
985+
return;
986+
}
987+
}
988+
}
989+
None => (),
990+
}
991+
}

0 commit comments

Comments
 (0)