Skip to content

Commit 9a34887

Browse files
authored
Merge pull request #194 from Lbqds/update-multi-field-review
Update the MultiFieldReview to align with app-bitcoin
2 parents 883df18 + b4fcc0f commit 9a34887

File tree

1 file changed

+72
-22
lines changed

1 file changed

+72
-22
lines changed

ledger_device_sdk/src/ui/gadgets.rs

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,9 @@ impl<'a> Page<'a> {
461461
self.label[0].place(Location::Bottom, Layout::Centered, true);
462462
} else {
463463
icon_x = 57;
464-
icon_y = 17;
465-
self.label[0].place(Location::Custom(35), Layout::Centered, true);
464+
icon_y = 10;
465+
self.label[0].place(Location::Custom(28), Layout::Centered, true);
466+
self.label[1].place(Location::Custom(42), Layout::Centered, true);
466467
}
467468
if let Some(glyph) = self.glyph {
468469
let icon = Icon::from(glyph);
@@ -729,7 +730,7 @@ pub struct Field<'a> {
729730
}
730731

731732
impl<'a> Field<'a> {
732-
pub fn event_loop(&self, incoming_direction: ButtonEvent) -> ButtonEvent {
733+
pub fn event_loop(&self, incoming_direction: ButtonEvent, is_first_field: bool) -> ButtonEvent {
733734
let mut buttons = ButtonsState::new();
734735
let chunk_max_lines = layout::MAX_LINES - 1;
735736
let page_count = 1 + self.value.len() / (chunk_max_lines * MAX_CHAR_PER_LINE);
@@ -777,7 +778,9 @@ impl<'a> Field<'a> {
777778
.trim_end_matches(' ');
778779
chunks[0] = Label::from(header).bold();
779780

780-
LEFT_ARROW.display();
781+
if !is_first_field {
782+
LEFT_ARROW.display();
783+
}
781784
RIGHT_ARROW.display();
782785

783786
chunks.place(Location::Middle, Layout::Centered, false);
@@ -823,7 +826,7 @@ pub struct MultiFieldReview<'a> {
823826
fields: &'a [Field<'a>],
824827
review_message: &'a [&'a str],
825828
review_glyph: Option<&'a Glyph<'a>>,
826-
validation_message: &'a str,
829+
validation_message: [&'a str; 2],
827830
validation_glyph: Option<&'a Glyph<'a>>,
828831
cancel_message: &'a str,
829832
cancel_glyph: Option<&'a Glyph<'a>>,
@@ -856,6 +859,26 @@ impl<'a> MultiFieldReview<'a> {
856859
validation_glyph: Option<&'a Glyph<'a>>,
857860
cancel_message: &'a str,
858861
cancel_glyph: Option<&'a Glyph<'a>>,
862+
) -> Self {
863+
Self::new_with_validation_messages(
864+
fields,
865+
review_message,
866+
review_glyph,
867+
[validation_message, ""],
868+
validation_glyph,
869+
cancel_message,
870+
cancel_glyph,
871+
)
872+
}
873+
874+
pub fn new_with_validation_messages(
875+
fields: &'a [Field<'a>],
876+
review_message: &'a [&'a str],
877+
review_glyph: Option<&'a Glyph<'a>>,
878+
validation_message: [&'a str; 2],
879+
validation_glyph: Option<&'a Glyph<'a>>,
880+
cancel_message: &'a str,
881+
cancel_glyph: Option<&'a Glyph<'a>>,
859882
) -> Self {
860883
MultiFieldReview {
861884
fields,
@@ -869,27 +892,25 @@ impl<'a> MultiFieldReview<'a> {
869892
}
870893

871894
pub fn show(&self) -> bool {
872-
let first_page = match self.review_message.len() {
873-
0 => Page::new(PageStyle::PictureNormal, ["", ""], self.review_glyph),
874-
1 => Page::new(
895+
let first_page_opt = match self.review_message.len() {
896+
0 => None,
897+
1 => Some(Page::new(
875898
PageStyle::PictureBold,
876899
[self.review_message[0], ""],
877900
self.review_glyph,
878-
),
879-
_ => Page::new(
901+
)),
902+
_ => Some(Page::new(
880903
PageStyle::PictureNormal,
881904
[self.review_message[0], self.review_message[1]],
882905
self.review_glyph,
883-
),
906+
)),
884907
};
885908

886-
clear_screen();
887-
first_page.place_and_wait();
888-
crate::ui::screen_util::screen_update();
909+
display_first_page(&first_page_opt);
889910

890911
let validation_page = Page::new(
891912
PageStyle::PictureBold,
892-
[self.validation_message, ""],
913+
self.validation_message,
893914
self.validation_glyph,
894915
);
895916
let cancel_page = Page::new(
@@ -903,9 +924,10 @@ impl<'a> MultiFieldReview<'a> {
903924

904925
loop {
905926
match cur_page {
906-
cancel if cancel == self.fields.len() => {
927+
cancel if cancel == self.fields.len() + 1 => {
907928
let mut buttons = ButtonsState::new();
908929
clear_screen();
930+
LEFT_ARROW.display();
909931
cancel_page.place();
910932
crate::ui::screen_util::screen_update();
911933
loop {
@@ -914,24 +936,31 @@ impl<'a> MultiFieldReview<'a> {
914936
cur_page = cur_page.saturating_sub(1);
915937
break;
916938
}
917-
Some(ButtonEvent::RightButtonRelease) => {
918-
cur_page += 1;
919-
break;
920-
}
921939
Some(ButtonEvent::BothButtonsRelease) => return false,
922940
_ => (),
923941
}
924942
}
925943
}
926-
validation if validation == self.fields.len() + 1 => {
944+
validation if validation == self.fields.len() => {
927945
let mut buttons = ButtonsState::new();
928946
clear_screen();
947+
LEFT_ARROW.display();
948+
RIGHT_ARROW.display();
929949
validation_page.place();
930950
crate::ui::screen_util::screen_update();
931951
loop {
932952
match get_event(&mut buttons) {
933953
Some(ButtonEvent::LeftButtonRelease) => {
934954
cur_page = cur_page.saturating_sub(1);
955+
if cur_page == 0 && self.fields.is_empty() {
956+
display_first_page(&first_page_opt);
957+
} else {
958+
direction = ButtonEvent::LeftButtonRelease;
959+
}
960+
break;
961+
}
962+
Some(ButtonEvent::RightButtonRelease) => {
963+
cur_page += 1;
935964
break;
936965
}
937966
Some(ButtonEvent::BothButtonsRelease) => return true,
@@ -940,10 +969,12 @@ impl<'a> MultiFieldReview<'a> {
940969
}
941970
}
942971
_ => {
943-
direction = self.fields[cur_page].event_loop(direction);
972+
direction = self.fields[cur_page]
973+
.event_loop(direction, cur_page == 0 && first_page_opt.is_none());
944974
match direction {
945975
ButtonEvent::LeftButtonRelease => {
946976
if cur_page == 0 {
977+
display_first_page(&first_page_opt);
947978
direction = ButtonEvent::RightButtonRelease;
948979
} else {
949980
cur_page -= 1;
@@ -959,3 +990,22 @@ impl<'a> MultiFieldReview<'a> {
959990
}
960991
}
961992
}
993+
994+
fn display_first_page(page_opt: &Option<Page>) {
995+
match page_opt {
996+
Some(page) => {
997+
clear_screen();
998+
RIGHT_ARROW.display();
999+
page.place();
1000+
crate::ui::screen_util::screen_update();
1001+
1002+
let mut buttons = ButtonsState::new();
1003+
loop {
1004+
if let Some(ButtonEvent::RightButtonRelease) = get_event(&mut buttons) {
1005+
return;
1006+
}
1007+
}
1008+
}
1009+
None => (),
1010+
}
1011+
}

0 commit comments

Comments
 (0)