Skip to content

Commit f5a1037

Browse files
authored
Merge pull request #138 from cookie1170/auto-focus-text-edit
2 parents 7721c44 + 97085be commit f5a1037

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/jackdaw_feathers/src/text_edit.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use bevy::prelude::*;
44
use bevy::text::{FontFeatureTag, FontFeatures};
55
use bevy_ui_text_input::actions::{TextInputAction, TextInputEdit};
66
use bevy_ui_text_input::*;
7-
87
// Re-export key types from bevy_ui_text_input for consumers
98
pub 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
}

src/inspector/component_picker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ pub(crate) fn on_add_component_button_click(
233233
text_edit::text_edit(
234234
TextEditProps::default()
235235
.with_placeholder("Search components...")
236+
.auto_focus()
236237
.allow_empty(),
237238
),
238239
ChildOf(picker),

0 commit comments

Comments
 (0)