@@ -711,7 +711,7 @@ pub struct Field<'a> {
711
711
}
712
712
713
713
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 {
715
715
let mut buttons = ButtonsState :: new ( ) ;
716
716
let chunk_max_lines = layout:: MAX_LINES - 1 ;
717
717
let page_count = 1 + self . value . len ( ) / ( chunk_max_lines * MAX_CHAR_PER_LINE ) ;
@@ -759,8 +759,10 @@ impl<'a> Field<'a> {
759
759
. trim_end_matches ( ' ' ) ;
760
760
chunks[ 0 ] = Label :: from ( header) . bold ( ) ;
761
761
762
- LEFT_ARROW . display ( ) ;
763
- RIGHT_ARROW . display ( ) ;
762
+ if !is_first_field {
763
+ bagls:: LEFT_ARROW . display ( ) ;
764
+ }
765
+ bagls:: RIGHT_ARROW . display ( ) ;
764
766
765
767
chunks. place ( Location :: Middle , Layout :: Centered , false ) ;
766
768
@@ -805,7 +807,7 @@ pub struct MultiFieldReview<'a> {
805
807
fields : & ' a [ Field < ' a > ] ,
806
808
review_message : & ' a [ & ' a str ] ,
807
809
review_glyph : Option < & ' a Glyph < ' a > > ,
808
- validation_message : & ' a str ,
810
+ validation_message : [ & ' a str ; 2 ] ,
809
811
validation_glyph : Option < & ' a Glyph < ' a > > ,
810
812
cancel_message : & ' a str ,
811
813
cancel_glyph : Option < & ' a Glyph < ' a > > ,
@@ -834,7 +836,7 @@ impl<'a> MultiFieldReview<'a> {
834
836
fields : & ' a [ Field < ' a > ] ,
835
837
review_message : & ' a [ & ' a str ] ,
836
838
review_glyph : Option < & ' a Glyph < ' a > > ,
837
- validation_message : & ' a str ,
839
+ validation_message : [ & ' a str ; 2 ] ,
838
840
validation_glyph : Option < & ' a Glyph < ' a > > ,
839
841
cancel_message : & ' a str ,
840
842
cancel_glyph : Option < & ' a Glyph < ' a > > ,
@@ -851,27 +853,25 @@ impl<'a> MultiFieldReview<'a> {
851
853
}
852
854
853
855
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 (
857
859
PageStyle :: PictureBold ,
858
860
[ self . review_message [ 0 ] , "" ] ,
859
861
self . review_glyph ,
860
- ) ,
861
- _ => Page :: new (
862
+ ) ) ,
863
+ _ => Some ( Page :: new (
862
864
PageStyle :: PictureNormal ,
863
865
[ self . review_message [ 0 ] , self . review_message [ 1 ] ] ,
864
866
self . review_glyph ,
865
- ) ,
867
+ ) ) ,
866
868
} ;
867
869
868
- clear_screen ( ) ;
869
- first_page. place_and_wait ( ) ;
870
- crate :: ui:: screen_util:: screen_update ( ) ;
870
+ display_first_page ( & first_page_opt) ;
871
871
872
872
let validation_page = Page :: new (
873
873
PageStyle :: PictureBold ,
874
- [ self . validation_message , "" ] ,
874
+ self . validation_message ,
875
875
self . validation_glyph ,
876
876
) ;
877
877
let cancel_page = Page :: new (
@@ -885,9 +885,10 @@ impl<'a> MultiFieldReview<'a> {
885
885
886
886
loop {
887
887
match cur_page {
888
- cancel if cancel == self . fields . len ( ) => {
888
+ cancel if cancel == self . fields . len ( ) + 1 => {
889
889
let mut buttons = ButtonsState :: new ( ) ;
890
890
clear_screen ( ) ;
891
+ bagls:: LEFT_ARROW . display ( ) ;
891
892
cancel_page. place ( ) ;
892
893
crate :: ui:: screen_util:: screen_update ( ) ;
893
894
loop {
@@ -896,24 +897,31 @@ impl<'a> MultiFieldReview<'a> {
896
897
cur_page = cur_page. saturating_sub ( 1 ) ;
897
898
break ;
898
899
}
899
- Some ( ButtonEvent :: RightButtonRelease ) => {
900
- cur_page += 1 ;
901
- break ;
902
- }
903
900
Some ( ButtonEvent :: BothButtonsRelease ) => return false ,
904
901
_ => ( ) ,
905
902
}
906
903
}
907
904
}
908
- validation if validation == self . fields . len ( ) + 1 => {
905
+ validation if validation == self . fields . len ( ) => {
909
906
let mut buttons = ButtonsState :: new ( ) ;
910
907
clear_screen ( ) ;
908
+ bagls:: LEFT_ARROW . display ( ) ;
909
+ bagls:: RIGHT_ARROW . display ( ) ;
911
910
validation_page. place ( ) ;
912
911
crate :: ui:: screen_util:: screen_update ( ) ;
913
912
loop {
914
913
match get_event ( & mut buttons) {
915
914
Some ( ButtonEvent :: LeftButtonRelease ) => {
916
915
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 ;
917
925
break ;
918
926
}
919
927
Some ( ButtonEvent :: BothButtonsRelease ) => return true ,
@@ -922,10 +930,12 @@ impl<'a> MultiFieldReview<'a> {
922
930
}
923
931
}
924
932
_ => {
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 ( ) ) ;
926
935
match direction {
927
936
ButtonEvent :: LeftButtonRelease => {
928
937
if cur_page == 0 {
938
+ display_first_page ( & first_page_opt) ;
929
939
direction = ButtonEvent :: RightButtonRelease ;
930
940
} else {
931
941
cur_page -= 1 ;
@@ -941,3 +951,22 @@ impl<'a> MultiFieldReview<'a> {
941
951
}
942
952
}
943
953
}
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