@@ -730,7 +730,7 @@ pub struct Field<'a> {
730
730
}
731
731
732
732
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 {
734
734
let mut buttons = ButtonsState :: new ( ) ;
735
735
let chunk_max_lines = layout:: MAX_LINES - 1 ;
736
736
let page_count = 1 + self . value . len ( ) / ( chunk_max_lines * MAX_CHAR_PER_LINE ) ;
@@ -778,8 +778,10 @@ impl<'a> Field<'a> {
778
778
. trim_end_matches ( ' ' ) ;
779
779
chunks[ 0 ] = Label :: from ( header) . bold ( ) ;
780
780
781
- LEFT_ARROW . display ( ) ;
782
- RIGHT_ARROW . display ( ) ;
781
+ if !is_first_field {
782
+ bagls:: LEFT_ARROW . display ( ) ;
783
+ }
784
+ bagls:: RIGHT_ARROW . display ( ) ;
783
785
784
786
chunks. place ( Location :: Middle , Layout :: Centered , false ) ;
785
787
@@ -824,7 +826,7 @@ pub struct MultiFieldReview<'a> {
824
826
fields : & ' a [ Field < ' a > ] ,
825
827
review_message : & ' a [ & ' a str ] ,
826
828
review_glyph : Option < & ' a Glyph < ' a > > ,
827
- validation_message : & ' a str ,
829
+ validation_message : [ & ' a str ; 2 ] ,
828
830
validation_glyph : Option < & ' a Glyph < ' a > > ,
829
831
cancel_message : & ' a str ,
830
832
cancel_glyph : Option < & ' a Glyph < ' a > > ,
@@ -853,7 +855,7 @@ impl<'a> MultiFieldReview<'a> {
853
855
fields : & ' a [ Field < ' a > ] ,
854
856
review_message : & ' a [ & ' a str ] ,
855
857
review_glyph : Option < & ' a Glyph < ' a > > ,
856
- validation_message : & ' a str ,
858
+ validation_message : [ & ' a str ; 2 ] ,
857
859
validation_glyph : Option < & ' a Glyph < ' a > > ,
858
860
cancel_message : & ' a str ,
859
861
cancel_glyph : Option < & ' a Glyph < ' a > > ,
@@ -870,27 +872,25 @@ impl<'a> MultiFieldReview<'a> {
870
872
}
871
873
872
874
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 (
876
878
PageStyle :: PictureBold ,
877
879
[ self . review_message [ 0 ] , "" ] ,
878
880
self . review_glyph ,
879
- ) ,
880
- _ => Page :: new (
881
+ ) ) ,
882
+ _ => Some ( Page :: new (
881
883
PageStyle :: PictureNormal ,
882
884
[ self . review_message [ 0 ] , self . review_message [ 1 ] ] ,
883
885
self . review_glyph ,
884
- ) ,
886
+ ) ) ,
885
887
} ;
886
888
887
- clear_screen ( ) ;
888
- first_page. place_and_wait ( ) ;
889
- crate :: ui:: screen_util:: screen_update ( ) ;
889
+ display_first_page ( & first_page_opt) ;
890
890
891
891
let validation_page = Page :: new (
892
892
PageStyle :: PictureBold ,
893
- [ self . validation_message , "" ] ,
893
+ self . validation_message ,
894
894
self . validation_glyph ,
895
895
) ;
896
896
let cancel_page = Page :: new (
@@ -904,9 +904,10 @@ impl<'a> MultiFieldReview<'a> {
904
904
905
905
loop {
906
906
match cur_page {
907
- cancel if cancel == self . fields . len ( ) => {
907
+ cancel if cancel == self . fields . len ( ) + 1 => {
908
908
let mut buttons = ButtonsState :: new ( ) ;
909
909
clear_screen ( ) ;
910
+ bagls:: LEFT_ARROW . display ( ) ;
910
911
cancel_page. place ( ) ;
911
912
crate :: ui:: screen_util:: screen_update ( ) ;
912
913
loop {
@@ -915,24 +916,31 @@ impl<'a> MultiFieldReview<'a> {
915
916
cur_page = cur_page. saturating_sub ( 1 ) ;
916
917
break ;
917
918
}
918
- Some ( ButtonEvent :: RightButtonRelease ) => {
919
- cur_page += 1 ;
920
- break ;
921
- }
922
919
Some ( ButtonEvent :: BothButtonsRelease ) => return false ,
923
920
_ => ( ) ,
924
921
}
925
922
}
926
923
}
927
- validation if validation == self . fields . len ( ) + 1 => {
924
+ validation if validation == self . fields . len ( ) => {
928
925
let mut buttons = ButtonsState :: new ( ) ;
929
926
clear_screen ( ) ;
927
+ bagls:: LEFT_ARROW . display ( ) ;
928
+ bagls:: RIGHT_ARROW . display ( ) ;
930
929
validation_page. place ( ) ;
931
930
crate :: ui:: screen_util:: screen_update ( ) ;
932
931
loop {
933
932
match get_event ( & mut buttons) {
934
933
Some ( ButtonEvent :: LeftButtonRelease ) => {
935
934
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 ;
936
944
break ;
937
945
}
938
946
Some ( ButtonEvent :: BothButtonsRelease ) => return true ,
@@ -941,10 +949,12 @@ impl<'a> MultiFieldReview<'a> {
941
949
}
942
950
}
943
951
_ => {
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 ( ) ) ;
945
954
match direction {
946
955
ButtonEvent :: LeftButtonRelease => {
947
956
if cur_page == 0 {
957
+ display_first_page ( & first_page_opt) ;
948
958
direction = ButtonEvent :: RightButtonRelease ;
949
959
} else {
950
960
cur_page -= 1 ;
@@ -960,3 +970,22 @@ impl<'a> MultiFieldReview<'a> {
960
970
}
961
971
}
962
972
}
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