@@ -461,8 +461,9 @@ impl<'a> Page<'a> {
461
461
self . label [ 0 ] . place ( Location :: Bottom , Layout :: Centered , true ) ;
462
462
} else {
463
463
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 ) ;
466
467
}
467
468
if let Some ( glyph) = self . glyph {
468
469
let icon = Icon :: from ( glyph) ;
@@ -729,7 +730,7 @@ pub struct Field<'a> {
729
730
}
730
731
731
732
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 {
733
734
let mut buttons = ButtonsState :: new ( ) ;
734
735
let chunk_max_lines = layout:: MAX_LINES - 1 ;
735
736
let page_count = 1 + self . value . len ( ) / ( chunk_max_lines * MAX_CHAR_PER_LINE ) ;
@@ -777,7 +778,9 @@ impl<'a> Field<'a> {
777
778
. trim_end_matches ( ' ' ) ;
778
779
chunks[ 0 ] = Label :: from ( header) . bold ( ) ;
779
780
780
- LEFT_ARROW . display ( ) ;
781
+ if !is_first_field {
782
+ LEFT_ARROW . display ( ) ;
783
+ }
781
784
RIGHT_ARROW . display ( ) ;
782
785
783
786
chunks. place ( Location :: Middle , Layout :: Centered , false ) ;
@@ -823,7 +826,7 @@ pub struct MultiFieldReview<'a> {
823
826
fields : & ' a [ Field < ' a > ] ,
824
827
review_message : & ' a [ & ' a str ] ,
825
828
review_glyph : Option < & ' a Glyph < ' a > > ,
826
- validation_message : & ' a str ,
829
+ validation_message : [ & ' a str ; 2 ] ,
827
830
validation_glyph : Option < & ' a Glyph < ' a > > ,
828
831
cancel_message : & ' a str ,
829
832
cancel_glyph : Option < & ' a Glyph < ' a > > ,
@@ -856,6 +859,26 @@ impl<'a> MultiFieldReview<'a> {
856
859
validation_glyph : Option < & ' a Glyph < ' a > > ,
857
860
cancel_message : & ' a str ,
858
861
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 > > ,
859
882
) -> Self {
860
883
MultiFieldReview {
861
884
fields,
@@ -869,27 +892,25 @@ impl<'a> MultiFieldReview<'a> {
869
892
}
870
893
871
894
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 (
875
898
PageStyle :: PictureBold ,
876
899
[ self . review_message [ 0 ] , "" ] ,
877
900
self . review_glyph ,
878
- ) ,
879
- _ => Page :: new (
901
+ ) ) ,
902
+ _ => Some ( Page :: new (
880
903
PageStyle :: PictureNormal ,
881
904
[ self . review_message [ 0 ] , self . review_message [ 1 ] ] ,
882
905
self . review_glyph ,
883
- ) ,
906
+ ) ) ,
884
907
} ;
885
908
886
- clear_screen ( ) ;
887
- first_page. place_and_wait ( ) ;
888
- crate :: ui:: screen_util:: screen_update ( ) ;
909
+ display_first_page ( & first_page_opt) ;
889
910
890
911
let validation_page = Page :: new (
891
912
PageStyle :: PictureBold ,
892
- [ self . validation_message , "" ] ,
913
+ self . validation_message ,
893
914
self . validation_glyph ,
894
915
) ;
895
916
let cancel_page = Page :: new (
@@ -903,9 +924,10 @@ impl<'a> MultiFieldReview<'a> {
903
924
904
925
loop {
905
926
match cur_page {
906
- cancel if cancel == self . fields . len ( ) => {
927
+ cancel if cancel == self . fields . len ( ) + 1 => {
907
928
let mut buttons = ButtonsState :: new ( ) ;
908
929
clear_screen ( ) ;
930
+ LEFT_ARROW . display ( ) ;
909
931
cancel_page. place ( ) ;
910
932
crate :: ui:: screen_util:: screen_update ( ) ;
911
933
loop {
@@ -914,24 +936,31 @@ impl<'a> MultiFieldReview<'a> {
914
936
cur_page = cur_page. saturating_sub ( 1 ) ;
915
937
break ;
916
938
}
917
- Some ( ButtonEvent :: RightButtonRelease ) => {
918
- cur_page += 1 ;
919
- break ;
920
- }
921
939
Some ( ButtonEvent :: BothButtonsRelease ) => return false ,
922
940
_ => ( ) ,
923
941
}
924
942
}
925
943
}
926
- validation if validation == self . fields . len ( ) + 1 => {
944
+ validation if validation == self . fields . len ( ) => {
927
945
let mut buttons = ButtonsState :: new ( ) ;
928
946
clear_screen ( ) ;
947
+ LEFT_ARROW . display ( ) ;
948
+ RIGHT_ARROW . display ( ) ;
929
949
validation_page. place ( ) ;
930
950
crate :: ui:: screen_util:: screen_update ( ) ;
931
951
loop {
932
952
match get_event ( & mut buttons) {
933
953
Some ( ButtonEvent :: LeftButtonRelease ) => {
934
954
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 ;
935
964
break ;
936
965
}
937
966
Some ( ButtonEvent :: BothButtonsRelease ) => return true ,
@@ -940,10 +969,12 @@ impl<'a> MultiFieldReview<'a> {
940
969
}
941
970
}
942
971
_ => {
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 ( ) ) ;
944
974
match direction {
945
975
ButtonEvent :: LeftButtonRelease => {
946
976
if cur_page == 0 {
977
+ display_first_page ( & first_page_opt) ;
947
978
direction = ButtonEvent :: RightButtonRelease ;
948
979
} else {
949
980
cur_page -= 1 ;
@@ -959,3 +990,22 @@ impl<'a> MultiFieldReview<'a> {
959
990
}
960
991
}
961
992
}
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