Skip to content

Commit e3e71c6

Browse files
committed
Update the MultiFieldReview to align with app-bitcoin
1 parent 661b3b6 commit e3e71c6

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
@@ -711,7 +711,7 @@ pub struct Field<'a> {
711711
}
712712

713713
impl<'a> Field<'a> {
714-
pub fn event_loop(&self, incoming_direction: ButtonEvent) -> ButtonEvent {
714+
pub fn event_loop(&self, incoming_direction: ButtonEvent, is_first_field: bool) -> ButtonEvent {
715715
let mut buttons = ButtonsState::new();
716716
let chunk_max_lines = layout::MAX_LINES - 1;
717717
let page_count = 1 + self.value.len() / (chunk_max_lines * MAX_CHAR_PER_LINE);
@@ -759,8 +759,10 @@ impl<'a> Field<'a> {
759759
.trim_end_matches(' ');
760760
chunks[0] = Label::from(header).bold();
761761

762-
LEFT_ARROW.display();
763-
RIGHT_ARROW.display();
762+
if !is_first_field {
763+
bagls::LEFT_ARROW.display();
764+
}
765+
bagls::RIGHT_ARROW.display();
764766

765767
chunks.place(Location::Middle, Layout::Centered, false);
766768

@@ -805,7 +807,7 @@ pub struct MultiFieldReview<'a> {
805807
fields: &'a [Field<'a>],
806808
review_message: &'a [&'a str],
807809
review_glyph: Option<&'a Glyph<'a>>,
808-
validation_message: &'a str,
810+
validation_message: [&'a str; 2],
809811
validation_glyph: Option<&'a Glyph<'a>>,
810812
cancel_message: &'a str,
811813
cancel_glyph: Option<&'a Glyph<'a>>,
@@ -834,7 +836,7 @@ impl<'a> MultiFieldReview<'a> {
834836
fields: &'a [Field<'a>],
835837
review_message: &'a [&'a str],
836838
review_glyph: Option<&'a Glyph<'a>>,
837-
validation_message: &'a str,
839+
validation_message: [&'a str; 2],
838840
validation_glyph: Option<&'a Glyph<'a>>,
839841
cancel_message: &'a str,
840842
cancel_glyph: Option<&'a Glyph<'a>>,
@@ -851,27 +853,25 @@ impl<'a> MultiFieldReview<'a> {
851853
}
852854

853855
pub fn show(&self) -> bool {
854-
let first_page = match self.review_message.len() {
855-
0 => Page::new(PageStyle::PictureNormal, ["", ""], self.review_glyph),
856-
1 => Page::new(
856+
let first_page_opt = match self.review_message.len() {
857+
0 => None,
858+
1 => Some(Page::new(
857859
PageStyle::PictureBold,
858860
[self.review_message[0], ""],
859861
self.review_glyph,
860-
),
861-
_ => Page::new(
862+
)),
863+
_ => Some(Page::new(
862864
PageStyle::PictureNormal,
863865
[self.review_message[0], self.review_message[1]],
864866
self.review_glyph,
865-
),
867+
)),
866868
};
867869

868-
clear_screen();
869-
first_page.place_and_wait();
870-
crate::ui::screen_util::screen_update();
870+
display_first_page(&first_page_opt);
871871

872872
let validation_page = Page::new(
873873
PageStyle::PictureBold,
874-
[self.validation_message, ""],
874+
self.validation_message,
875875
self.validation_glyph,
876876
);
877877
let cancel_page = Page::new(
@@ -885,9 +885,10 @@ impl<'a> MultiFieldReview<'a> {
885885

886886
loop {
887887
match cur_page {
888-
cancel if cancel == self.fields.len() => {
888+
cancel if cancel == self.fields.len() + 1 => {
889889
let mut buttons = ButtonsState::new();
890890
clear_screen();
891+
bagls::LEFT_ARROW.display();
891892
cancel_page.place();
892893
crate::ui::screen_util::screen_update();
893894
loop {
@@ -896,24 +897,31 @@ impl<'a> MultiFieldReview<'a> {
896897
cur_page = cur_page.saturating_sub(1);
897898
break;
898899
}
899-
Some(ButtonEvent::RightButtonRelease) => {
900-
cur_page += 1;
901-
break;
902-
}
903900
Some(ButtonEvent::BothButtonsRelease) => return false,
904901
_ => (),
905902
}
906903
}
907904
}
908-
validation if validation == self.fields.len() + 1 => {
905+
validation if validation == self.fields.len() => {
909906
let mut buttons = ButtonsState::new();
910907
clear_screen();
908+
bagls::LEFT_ARROW.display();
909+
bagls::RIGHT_ARROW.display();
911910
validation_page.place();
912911
crate::ui::screen_util::screen_update();
913912
loop {
914913
match get_event(&mut buttons) {
915914
Some(ButtonEvent::LeftButtonRelease) => {
916915
cur_page = cur_page.saturating_sub(1);
916+
if cur_page == 0 && self.fields.is_empty() {
917+
display_first_page(&first_page_opt);
918+
} else {
919+
direction = ButtonEvent::LeftButtonRelease;
920+
}
921+
break;
922+
}
923+
Some(ButtonEvent::RightButtonRelease) => {
924+
cur_page += 1;
917925
break;
918926
}
919927
Some(ButtonEvent::BothButtonsRelease) => return true,
@@ -922,10 +930,12 @@ impl<'a> MultiFieldReview<'a> {
922930
}
923931
}
924932
_ => {
925-
direction = self.fields[cur_page].event_loop(direction);
933+
direction = self.fields[cur_page]
934+
.event_loop(direction, cur_page == 0 && first_page_opt.is_none());
926935
match direction {
927936
ButtonEvent::LeftButtonRelease => {
928937
if cur_page == 0 {
938+
display_first_page(&first_page_opt);
929939
direction = ButtonEvent::RightButtonRelease;
930940
} else {
931941
cur_page -= 1;
@@ -941,3 +951,22 @@ impl<'a> MultiFieldReview<'a> {
941951
}
942952
}
943953
}
954+
955+
fn display_first_page(page_opt: &Option<Page>) {
956+
match page_opt {
957+
Some(page) => {
958+
clear_screen();
959+
bagls::RIGHT_ARROW.display();
960+
page.place();
961+
crate::ui::screen_util::screen_update();
962+
963+
let mut buttons = ButtonsState::new();
964+
loop {
965+
if let Some(ButtonEvent::RightButtonRelease) = get_event(&mut buttons) {
966+
return;
967+
}
968+
}
969+
}
970+
None => (),
971+
}
972+
}

0 commit comments

Comments
 (0)