1- //! Simple key press counter, showcasing map reactivity.
1+ //! Key press counter with swappable save states , showcasing map reactivity.
22mod utils;
33use utils:: * ;
44
@@ -87,7 +87,6 @@ fn ui_root() -> JonmoBuilder {
8787 . child (
8888 JonmoBuilder :: from ( Node {
8989 align_self : AlignSelf :: Center ,
90- justify_content : JustifyContent :: SpaceBetween ,
9190 width : Val :: Percent ( 100. ) ,
9291 ..default ( )
9392 } )
@@ -102,22 +101,25 @@ fn ui_root() -> JonmoBuilder {
102101 } ) ) ) ,
103102 )
104103 . child (
105- text_node ( )
106- . insert ( ( TextColor ( BLUE ) , TextFont :: from_font_size ( LETTER_SIZE ) ) )
107- . with_component :: < Node > ( |mut node| node. height = Val :: Px ( 100. ) )
108- . component_signal (
109- active_save_signal
110- . clone ( )
111- . switch_signal_vec ( move |In ( active_save) : In < ActiveSave > , save_states : Res < SaveStates > | {
112- get_active_map ( & save_states, active_save) . signal_vec_entries ( )
113- } )
114- . map_in ( |( _, LetterData { count, .. } ) | count)
115- . sum ( )
116- . dedupe ( )
117- . map_in_ref ( ToString :: to_string)
118- . map_in ( Text )
119- . map_in ( Some ) ,
120- ) ,
104+ sum_container ( )
105+ . child (
106+ text_node ( )
107+ . insert ( ( TextColor ( BLUE ) , TextFont :: from_font_size ( LETTER_SIZE ) ) )
108+ . with_component :: < Node > ( |mut node| node. height = Val :: Px ( 100. ) )
109+ . component_signal (
110+ active_save_signal
111+ . clone ( )
112+ . switch_signal_vec ( move |In ( active_save) : In < ActiveSave > , save_states : Res < SaveStates > | {
113+ get_active_map ( & save_states, active_save) . signal_vec_entries ( )
114+ } )
115+ . map_in ( |( _, LetterData { count, .. } ) | count)
116+ . sum ( )
117+ . dedupe ( )
118+ . map_in_ref ( ToString :: to_string)
119+ . map_in ( Text )
120+ . map_in ( Some ) ,
121+ )
122+ ) ,
121123 ) ,
122124 )
123125 . children ( ROWS . into_iter ( ) . map ( clone ! ( ( active_save_signal) move |row| {
@@ -139,13 +141,7 @@ fn ui_root() -> JonmoBuilder {
139141 } ) ,
140142 ) )
141143 . child(
142- JonmoBuilder :: from( Node {
143- align_self: AlignSelf :: Center ,
144- justify_content: JustifyContent :: FlexEnd ,
145- flex_grow: 1. ,
146- padding: UiRect :: all( Val :: Px ( GAP * 2. ) ) ,
147- ..default ( )
148- } )
144+ sum_container( )
149145 . child(
150146 text_node( )
151147 . insert( ( TextColor ( BLUE ) , TextFont :: from_font_size( LETTER_SIZE ) ) )
@@ -171,6 +167,16 @@ fn ui_root() -> JonmoBuilder {
171167
172168const GAP : f32 = 5. ;
173169
170+ fn sum_container ( ) -> JonmoBuilder {
171+ JonmoBuilder :: from ( Node {
172+ align_self : AlignSelf :: Center ,
173+ justify_content : JustifyContent :: FlexEnd ,
174+ flex_grow : 1. ,
175+ padding : UiRect :: all ( Val :: Px ( GAP * 2. ) ) ,
176+ ..default ( )
177+ } )
178+ }
179+
174180fn save_card ( save_char : char , active_save_signal : impl Signal < Item = ActiveSave > + Clone ) -> JonmoBuilder {
175181 JonmoBuilder :: from ( (
176182 Node {
0 commit comments