Skip to content

Commit

Permalink
fixed input example, added widget crate skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
Lommix committed Dec 1, 2024
1 parent eaa1847 commit 5b293c1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["crates/bevy_hui", "example"]
members = ["crates/bevy_hui", "crates/bevy_hui_widgets", "example"]
default-members = ["crates/bevy_hui"]

[profile.dev]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ to have common components and system for a general reusable widget toolkit like
sliders, drop downs, draggable and so on.

Checkout the examples, if you come up with some really cool widgets, I would be happy
to merge them into a
to include them into the upcoming `bevy_hui_widgets` crate.

### More examples

Expand Down
6 changes: 6 additions & 0 deletions crates/bevy_hui_widgets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "bevy_hui_widgets"
version = "0.1.0"
edition = "2021"

[dependencies]
3 changes: 3 additions & 0 deletions crates/bevy_hui_widgets/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// crate skeletong for the upcoming widget
// crate
pub struct HuiWidgetPlugin;
16 changes: 4 additions & 12 deletions example/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub fn main() {
TextInputPlugin,
))
.add_systems(Startup, setup_scene)
.add_systems(Update, write_input)
.run();
}

Expand Down Expand Up @@ -128,21 +127,16 @@ fn unfocus(

fn write_input(
mut cmd: Commands,
key_events: Res<Events<KeyboardInput>>,
mut reader: Local<EventCursor<KeyboardInput>>,
mut events: EventReader<KeyboardInput>,
mut text_inputs: Query<(Entity, &mut TextInput), With<Focused>>,
) {
if text_inputs.is_empty() {
return;
}

if reader.clone().read(&key_events).next().is_none() {
return;
}

for input in reader.clone().read(&key_events) {
for input in events.read() {
if !input.state.is_pressed() {
return;
continue;
}

match input.logical_key {
Expand All @@ -164,13 +158,11 @@ fn write_input(
Key::Space => {
text_inputs
.iter_mut()
.for_each(|(_, mut txt)| txt.0.push_str(" "));
.for_each(|(_, mut txt)| txt.0.push(' '));
}
_ => (),
}
}

reader.clear(&key_events);
}

fn sync_display_text(
Expand Down

0 comments on commit 5b293c1

Please sign in to comment.