@@ -45,44 +45,38 @@ fn main() {
4545struct TextOutput ;
4646
4747fn setup ( mut commands : Commands , asset_server : Res < AssetServer > ) {
48- // Set up a camera
49- // We need a camera to see the UI
5048 commands. spawn ( Camera2d ) ;
5149
52- // Create a root UI node, so we can place the input above the output in a column
5350 let root = commands
5451 . spawn ( Node {
55- display : Display :: Block ,
52+ display : Display :: Flex ,
53+ flex_direction : FlexDirection :: Column ,
54+ padding : px ( 20 ) . all ( ) ,
55+ row_gap : px ( 16 ) ,
5656 ..default ( )
5757 } )
5858 . id ( ) ;
5959
6060 let text_instructions = commands
6161 . spawn ( (
62- Node {
63- width : px ( 400 ) ,
64- height : px ( 100 ) ,
65- ..Default :: default ( )
66- } ,
67- BorderColor :: from ( Color :: from ( SLATE_300 ) ) ,
6862 Text :: new ( "Ctrl+Enter to submit text" ) ,
6963 TextFont {
7064 font : asset_server. load ( "fonts/FiraSans-Bold.ttf" ) . into ( ) ,
7165 font_size : FontSize :: Px ( 30.0 ) ,
7266 ..default ( )
7367 } ,
74- UiTransform :: from_translation ( Val2 :: ZERO ) ,
7568 ) )
7669 . id ( ) ;
7770
78- let text_input_left = build_input_text ( & mut commands, true , 30 .0) ;
79- let text_input_right = build_input_text ( & mut commands, false , 50 .0) ;
71+ let text_input_left = build_input_text ( & mut commands, true , 24 .0) ;
72+ let text_input_right = build_input_text ( & mut commands, false , 24 .0) ;
8073
8174 let input_container = commands
8275 . spawn ( (
8376 Node {
8477 display : Display :: Flex ,
8578 align_items : AlignItems :: Start ,
79+ column_gap : px ( 16 ) ,
8680 ..default ( )
8781 } ,
8882 AutoFocus ,
@@ -94,23 +88,21 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
9488 let text_output = commands
9589 . spawn ( (
9690 Node {
97- width : px ( 400 ) ,
98- height : px ( 100 ) ,
99- border : px ( 5 ) . all ( ) ,
91+ width : px ( 416 ) ,
92+ border : px ( 2 ) . all ( ) ,
93+ padding : px ( 8 ) . all ( ) ,
10094 ..Default :: default ( )
10195 } ,
10296 BorderColor :: from ( Color :: from ( SLATE_300 ) ) ,
103- Text :: new ( "testing " ) ,
97+ Text :: new ( "" ) ,
10498 TextOutput ,
10599 TextFont {
106- font_size : FontSize :: Px ( 70 .0) ,
100+ font_size : FontSize :: Px ( 24 .0) ,
107101 ..default ( )
108102 } ,
109- UiTransform :: from_translation ( Val2 :: px ( 5.0 , 200.0 ) ) ,
110103 ) )
111104 . id ( ) ;
112105
113- // Assemble our hierarchy
114106 commands
115107 . entity ( input_container)
116108 . add_children ( & [ text_input_left, text_input_right] ) ;
@@ -125,8 +117,8 @@ fn build_input_text(commands: &mut Commands, is_left: bool, font_size: f32) -> E
125117 . spawn ( (
126118 Node {
127119 width : px ( 200 ) ,
128- border : px ( 5 ) . all ( ) ,
129- padding : px ( 5 ) . all ( ) ,
120+ border : px ( 2 ) . all ( ) ,
121+ padding : px ( 8 ) . all ( ) ,
130122 ..Default :: default ( )
131123 } ,
132124 BorderColor :: from ( Color :: from ( SLATE_300 ) ) ,
@@ -142,7 +134,6 @@ fn build_input_text(commands: &mut Commands, is_left: bool, font_size: f32) -> E
142134 TextCursorStyle :: default ( ) ,
143135 TabIndex ( if is_left { 0 } else { 1 } ) ,
144136 BackgroundColor ( DARK_GREY . into ( ) ) ,
145- UiTransform :: from_translation ( Val2 :: px ( if is_left { 0.0 } else { 300.0 } , 50.0 ) ) ,
146137 ) )
147138 . id ( )
148139}
0 commit comments