@@ -4,7 +4,6 @@ use bevy::prelude::*;
44use bevy:: text:: { FontFeatureTag , FontFeatures } ;
55use bevy_ui_text_input:: actions:: { TextInputAction , TextInputEdit } ;
66use bevy_ui_text_input:: * ;
7-
87// Re-export key types from bevy_ui_text_input for consumers
98pub use bevy_ui_text_input:: { TextInputBuffer , TextInputQueue } ;
109
@@ -130,6 +129,7 @@ pub struct TextEditConfig {
130129 default_value : Option < String > ,
131130 min : f64 ,
132131 max : f64 ,
132+ auto_focus : bool ,
133133 allow_empty : bool ,
134134 drag_bottom : bool ,
135135 pub initialized : bool ,
@@ -145,6 +145,7 @@ pub struct TextEditProps {
145145 pub suffix : Option < String > ,
146146 pub min : f64 ,
147147 pub max : f64 ,
148+ pub auto_focus : bool ,
148149 pub allow_empty : bool ,
149150 pub drag_bottom : bool ,
150151 pub grow : bool ,
@@ -162,6 +163,7 @@ impl Default for TextEditProps {
162163 suffix : None ,
163164 min : f64:: MIN ,
164165 max : f64:: MAX ,
166+ auto_focus : false ,
165167 allow_empty : false ,
166168 drag_bottom : false ,
167169 grow : false ,
@@ -210,6 +212,10 @@ impl TextEditProps {
210212 self . grow = true ;
211213 self
212214 }
215+ pub fn auto_focus ( mut self ) -> Self {
216+ self . auto_focus = true ;
217+ self
218+ }
213219 pub fn numeric_f32 ( mut self ) -> Self {
214220 self . variant = TextEditVariant :: NumericF32 ;
215221 self . filter = Some ( FilterType :: Decimal ) ;
@@ -247,6 +253,7 @@ pub fn text_edit(props: TextEditProps) -> impl Bundle {
247253 suffix,
248254 min,
249255 max,
256+ auto_focus,
250257 allow_empty,
251258 drag_bottom,
252259 grow : _,
@@ -271,6 +278,7 @@ pub fn text_edit(props: TextEditProps) -> impl Bundle {
271278 default_value,
272279 min,
273280 max,
281+ auto_focus,
274282 allow_empty,
275283 drag_bottom,
276284 initialized : false ,
@@ -283,6 +291,7 @@ fn setup_text_edit_input(
283291 mut commands : Commands ,
284292 editor_font : Res < EditorFont > ,
285293 mut configs : Query < ( Entity , & mut TextEditConfig ) > ,
294+ mut focus : ResMut < InputFocus > ,
286295) {
287296 let font = editor_font. 0 . clone ( ) ;
288297 let tabular_figures: FontFeatures = [ FontFeatureTag :: TABULAR_FIGURES ] . into ( ) ;
@@ -500,6 +509,10 @@ fn setup_text_edit_input(
500509 } ,
501510 ) ) ;
502511
512+ if config. auto_focus {
513+ focus. 0 = Some ( text_input. id ( ) ) ;
514+ }
515+
503516 if let Some ( filter) = filter {
504517 text_input. insert ( filter) ;
505518 }
0 commit comments