Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
//! Prints out all chars as they are inputted.
use bevy::{
input::keyboard::{Key, KeyboardInput},
prelude::*,
};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, print_char_event_system)
.run();
}
/// This system prints out all char events as they come in.
fn print_char_event_system(mut char_input_events: EventReader<KeyboardInput>) {
for event in char_input_events.read() {
// Only check for characters when the key is pressed.
if !event.state.is_pressed() {
continue;
}
if let Key::Character(character) = &event.logical_key {
info!("{:?}: '{}'", event, character);
}
}
}

View File

@@ -0,0 +1,30 @@
//! Shows handling of gamepad input, connections, and disconnections.
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, gamepad_system)
.run();
}
fn gamepad_system(gamepads: Query<(Entity, &Gamepad)>) {
for (entity, gamepad) in &gamepads {
if gamepad.just_pressed(GamepadButton::South) {
info!("{} just pressed South", entity);
} else if gamepad.just_released(GamepadButton::South) {
info!("{} just released South", entity);
}
let right_trigger = gamepad.get(GamepadButton::RightTrigger2).unwrap();
if right_trigger.abs() > 0.01 {
info!("{} RightTrigger2 value is {}", entity, right_trigger);
}
let left_stick_x = gamepad.get(GamepadAxis::LeftStickX).unwrap();
if left_stick_x.abs() > 0.01 {
info!("{} LeftStickX value is {}", entity, left_stick_x);
}
}
}

View File

@@ -0,0 +1,60 @@
//! Iterates and prints gamepad input and connection events.
use bevy::{
input::gamepad::{
GamepadAxisChangedEvent, GamepadButtonChangedEvent, GamepadButtonStateChangedEvent,
GamepadConnectionEvent, GamepadEvent,
},
prelude::*,
};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, (gamepad_events, gamepad_ordered_events))
.run();
}
fn gamepad_events(
mut connection_events: EventReader<GamepadConnectionEvent>,
// Handles the continuous measure of an axis, equivalent to GamepadAxes::get.
mut axis_changed_events: EventReader<GamepadAxisChangedEvent>,
// Handles the continuous measure of how far a button has been pressed down, equivalent to `GamepadButtons::get`.
mut button_changed_events: EventReader<GamepadButtonChangedEvent>,
// Handles the boolean measure of whether a button is considered pressed or unpressed, as
// defined by the thresholds in `GamepadSettings::button_settings`.
// When the threshold is crossed and the button state changes, this event is emitted.
mut button_input_events: EventReader<GamepadButtonStateChangedEvent>,
) {
for connection_event in connection_events.read() {
info!("{:?}", connection_event);
}
for axis_changed_event in axis_changed_events.read() {
info!(
"{:?} of {} is changed to {}",
axis_changed_event.axis, axis_changed_event.entity, axis_changed_event.value
);
}
for button_changed_event in button_changed_events.read() {
info!(
"{:?} of {} is changed to {}",
button_changed_event.button, button_changed_event.entity, button_changed_event.value
);
}
for button_input_event in button_input_events.read() {
info!("{:?}", button_input_event);
}
}
// If you require in-frame relative event ordering, you can also read the `Gamepad` event
// stream directly. For standard use-cases, reading the events individually or using the
// `Input<T>` or `Axis<T>` resources is preferable.
fn gamepad_ordered_events(mut gamepad_events: EventReader<GamepadEvent>) {
for gamepad_event in gamepad_events.read() {
match gamepad_event {
GamepadEvent::Connection(connection_event) => info!("{:?}", connection_event),
GamepadEvent::Button(button_event) => info!("{:?}", button_event),
GamepadEvent::Axis(axis_event) => info!("{:?}", axis_event),
}
}
}

View File

@@ -0,0 +1,70 @@
//! Shows how to trigger force-feedback, making gamepads rumble when buttons are
//! pressed.
use bevy::{
input::gamepad::{Gamepad, GamepadRumbleIntensity, GamepadRumbleRequest},
prelude::*,
};
use core::time::Duration;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, gamepad_system)
.run();
}
fn gamepad_system(
gamepads: Query<(Entity, &Gamepad)>,
mut rumble_requests: EventWriter<GamepadRumbleRequest>,
) {
for (entity, gamepad) in &gamepads {
if gamepad.just_pressed(GamepadButton::North) {
info!(
"North face button: strong (low-frequency) with low intensity for rumble for 5 seconds. Press multiple times to increase intensity."
);
rumble_requests.write(GamepadRumbleRequest::Add {
gamepad: entity,
intensity: GamepadRumbleIntensity::strong_motor(0.1),
duration: Duration::from_secs(5),
});
}
if gamepad.just_pressed(GamepadButton::East) {
info!("East face button: maximum rumble on both motors for 5 seconds");
rumble_requests.write(GamepadRumbleRequest::Add {
gamepad: entity,
duration: Duration::from_secs(5),
intensity: GamepadRumbleIntensity::MAX,
});
}
if gamepad.just_pressed(GamepadButton::South) {
info!("South face button: low-intensity rumble on the weak motor for 0.5 seconds");
rumble_requests.write(GamepadRumbleRequest::Add {
gamepad: entity,
duration: Duration::from_secs_f32(0.5),
intensity: GamepadRumbleIntensity::weak_motor(0.25),
});
}
if gamepad.just_pressed(GamepadButton::West) {
info!("West face button: custom rumble intensity for 5 second");
rumble_requests.write(GamepadRumbleRequest::Add {
gamepad: entity,
intensity: GamepadRumbleIntensity {
// intensity low-frequency motor, usually on the left-hand side
strong_motor: 0.5,
// intensity of high-frequency motor, usually on the right-hand side
weak_motor: 0.25,
},
duration: Duration::from_secs(5),
});
}
if gamepad.just_pressed(GamepadButton::Start) {
info!("Start button: Interrupt the current rumble");
rumble_requests.write(GamepadRumbleRequest::Stop { gamepad: entity });
}
}
}

View File

@@ -0,0 +1,24 @@
//! Demonstrates handling a key press/release.
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, keyboard_input_system)
.run();
}
/// This system prints 'A' key state
fn keyboard_input_system(keyboard_input: Res<ButtonInput<KeyCode>>) {
if keyboard_input.pressed(KeyCode::KeyA) {
info!("'A' currently pressed");
}
if keyboard_input.just_pressed(KeyCode::KeyA) {
info!("'A' just pressed");
}
if keyboard_input.just_released(KeyCode::KeyA) {
info!("'A' just released");
}
}

View File

@@ -0,0 +1,17 @@
//! Prints out all keyboard events.
use bevy::{input::keyboard::KeyboardInput, prelude::*};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, print_keyboard_event_system)
.run();
}
/// This system prints out all keyboard events as they come in
fn print_keyboard_event_system(mut keyboard_input_events: EventReader<KeyboardInput>) {
for event in keyboard_input_events.read() {
info!("{:?}", event);
}
}

View File

@@ -0,0 +1,20 @@
//! Demonstrates using key modifiers (ctrl, shift).
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, keyboard_input_system)
.run();
}
/// This system prints when `Ctrl + Shift + A` is pressed
fn keyboard_input_system(input: Res<ButtonInput<KeyCode>>) {
let shift = input.any_pressed([KeyCode::ShiftLeft, KeyCode::ShiftRight]);
let ctrl = input.any_pressed([KeyCode::ControlLeft, KeyCode::ControlRight]);
if ctrl && shift && input.just_pressed(KeyCode::KeyA) {
info!("Just pressed Ctrl + Shift + A!");
}
}

View File

@@ -0,0 +1,28 @@
//! Demonstrates how to grab and hide the mouse cursor.
use bevy::{prelude::*, window::CursorGrabMode};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, grab_mouse)
.run();
}
// This system grabs the mouse when the left mouse button is pressed
// and releases it when the escape key is pressed
fn grab_mouse(
mut window: Single<&mut Window>,
mouse: Res<ButtonInput<MouseButton>>,
key: Res<ButtonInput<KeyCode>>,
) {
if mouse.just_pressed(MouseButton::Left) {
window.cursor_options.visible = false;
window.cursor_options.grab_mode = CursorGrabMode::Locked;
}
if key.just_pressed(KeyCode::Escape) {
window.cursor_options.visible = true;
window.cursor_options.grab_mode = CursorGrabMode::None;
}
}

View File

@@ -0,0 +1,43 @@
//! Prints mouse button events.
use bevy::{
input::mouse::{AccumulatedMouseMotion, AccumulatedMouseScroll},
prelude::*,
};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, (mouse_click_system, mouse_move_system))
.run();
}
// This system prints messages when you press or release the left mouse button:
fn mouse_click_system(mouse_button_input: Res<ButtonInput<MouseButton>>) {
if mouse_button_input.pressed(MouseButton::Left) {
info!("left mouse currently pressed");
}
if mouse_button_input.just_pressed(MouseButton::Left) {
info!("left mouse just pressed");
}
if mouse_button_input.just_released(MouseButton::Left) {
info!("left mouse just released");
}
}
// This system prints messages when you finish dragging or scrolling with your mouse
fn mouse_move_system(
accumulated_mouse_motion: Res<AccumulatedMouseMotion>,
accumulated_mouse_scroll: Res<AccumulatedMouseScroll>,
) {
if accumulated_mouse_motion.delta != Vec2::ZERO {
let delta = accumulated_mouse_motion.delta;
info!("mouse moved ({}, {})", delta.x, delta.y);
}
if accumulated_mouse_scroll.delta != Vec2::ZERO {
let delta = accumulated_mouse_scroll.delta;
info!("mouse scrolled ({}, {})", delta.x, delta.y);
}
}

View File

@@ -0,0 +1,58 @@
//! Prints all mouse events to the console.
use bevy::{
input::{
gestures::*,
mouse::{MouseButtonInput, MouseMotion, MouseWheel},
},
prelude::*,
};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, print_mouse_events_system)
.run();
}
/// This system prints out all mouse events as they come in
fn print_mouse_events_system(
mut mouse_button_input_events: EventReader<MouseButtonInput>,
mut mouse_motion_events: EventReader<MouseMotion>,
mut cursor_moved_events: EventReader<CursorMoved>,
mut mouse_wheel_events: EventReader<MouseWheel>,
mut pinch_gesture_events: EventReader<PinchGesture>,
mut rotation_gesture_events: EventReader<RotationGesture>,
mut double_tap_gesture_events: EventReader<DoubleTapGesture>,
) {
for event in mouse_button_input_events.read() {
info!("{:?}", event);
}
for event in mouse_motion_events.read() {
info!("{:?}", event);
}
for event in cursor_moved_events.read() {
info!("{:?}", event);
}
for event in mouse_wheel_events.read() {
info!("{:?}", event);
}
// This event will only fire on macOS
for event in pinch_gesture_events.read() {
info!("{:?}", event);
}
// This event will only fire on macOS
for event in rotation_gesture_events.read() {
info!("{:?}", event);
}
// This event will only fire on macOS
for event in double_tap_gesture_events.read() {
info!("{:?}", event);
}
}

182
vendor/bevy/examples/input/text_input.rs vendored Normal file
View File

@@ -0,0 +1,182 @@
//! Simple text input support
//!
//! Return creates a new line, backspace removes the last character.
//! Clicking toggle IME (Input Method Editor) support, but the font used as limited support of characters.
//! You should change the provided font with another one to test other languages input.
use std::mem;
use bevy::{
input::keyboard::{Key, KeyboardInput},
prelude::*,
};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup_scene)
.add_systems(
Update,
(
toggle_ime,
listen_ime_events,
listen_keyboard_input_events,
bubbling_text,
),
)
.run();
}
fn setup_scene(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2d);
// The default font has a limited number of glyphs, so use the full version for
// sections that will hold text input.
let font = asset_server.load("fonts/FiraMono-Medium.ttf");
commands.spawn((
Text::default(),
Node {
position_type: PositionType::Absolute,
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
},
children![
TextSpan::new("Click to toggle IME. Press return to start a new line.\n\n",),
TextSpan::new("IME Enabled: "),
TextSpan::new("false\n"),
TextSpan::new("IME Active: "),
TextSpan::new("false\n"),
TextSpan::new("IME Buffer: "),
(
TextSpan::new("\n"),
TextFont {
font: font.clone(),
..default()
},
),
],
));
commands.spawn((
Text2d::new(""),
TextFont {
font,
font_size: 100.0,
..default()
},
));
}
fn toggle_ime(
input: Res<ButtonInput<MouseButton>>,
mut window: Single<&mut Window>,
status_text: Single<Entity, (With<Node>, With<Text>)>,
mut ui_writer: TextUiWriter,
) {
if input.just_pressed(MouseButton::Left) {
window.ime_position = window.cursor_position().unwrap();
window.ime_enabled = !window.ime_enabled;
*ui_writer.text(*status_text, 3) = format!("{}\n", window.ime_enabled);
}
}
#[derive(Component)]
struct Bubble {
timer: Timer,
}
fn bubbling_text(
mut commands: Commands,
mut bubbles: Query<(Entity, &mut Transform, &mut Bubble)>,
time: Res<Time>,
) {
for (entity, mut transform, mut bubble) in bubbles.iter_mut() {
if bubble.timer.tick(time.delta()).just_finished() {
commands.entity(entity).despawn();
}
transform.translation.y += time.delta_secs() * 100.0;
}
}
fn listen_ime_events(
mut events: EventReader<Ime>,
status_text: Single<Entity, (With<Node>, With<Text>)>,
mut edit_text: Single<&mut Text2d, (Without<Node>, Without<Bubble>)>,
mut ui_writer: TextUiWriter,
) {
for event in events.read() {
match event {
Ime::Preedit { value, cursor, .. } if !cursor.is_none() => {
*ui_writer.text(*status_text, 7) = format!("{value}\n");
}
Ime::Preedit { cursor, .. } if cursor.is_none() => {
*ui_writer.text(*status_text, 7) = "\n".to_string();
}
Ime::Commit { value, .. } => {
edit_text.push_str(value);
}
Ime::Enabled { .. } => {
*ui_writer.text(*status_text, 5) = "true\n".to_string();
}
Ime::Disabled { .. } => {
*ui_writer.text(*status_text, 5) = "false\n".to_string();
}
_ => (),
}
}
}
fn listen_keyboard_input_events(
mut commands: Commands,
mut events: EventReader<KeyboardInput>,
edit_text: Single<(&mut Text2d, &TextFont), (Without<Node>, Without<Bubble>)>,
) {
let (mut text, style) = edit_text.into_inner();
for event in events.read() {
// Only trigger changes when the key is first pressed.
if !event.state.is_pressed() {
continue;
}
match (&event.logical_key, &event.text) {
(Key::Enter, _) => {
if text.is_empty() {
continue;
}
let old_value = mem::take(&mut **text);
commands.spawn((
Text2d::new(old_value),
style.clone(),
Bubble {
timer: Timer::from_seconds(5.0, TimerMode::Once),
},
));
}
(Key::Backspace, _) => {
text.pop();
}
(_, Some(inserted_text)) => {
// Make sure the text doesn't have any control characters,
// which can happen when keys like Escape are pressed
if inserted_text.chars().all(is_printable_char) {
text.push_str(inserted_text);
}
}
_ => continue,
}
}
}
// this logic is taken from egui-winit:
// https://github.com/emilk/egui/blob/adfc0bebfc6be14cee2068dee758412a5e0648dc/crates/egui-winit/src/lib.rs#L1014-L1024
fn is_printable_char(chr: char) -> bool {
let is_in_private_use_area = ('\u{e000}'..='\u{f8ff}').contains(&chr)
|| ('\u{f0000}'..='\u{ffffd}').contains(&chr)
|| ('\u{100000}'..='\u{10fffd}').contains(&chr);
!is_in_private_use_area && !chr.is_ascii_control()
}

View File

@@ -0,0 +1,38 @@
//! Displays touch presses, releases, and cancels.
use bevy::{input::touch::*, prelude::*};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, touch_system)
.run();
}
fn touch_system(touches: Res<Touches>) {
for touch in touches.iter_just_pressed() {
info!(
"just pressed touch with id: {}, at: {}",
touch.id(),
touch.position()
);
}
for touch in touches.iter_just_released() {
info!(
"just released touch with id: {}, at: {}",
touch.id(),
touch.position()
);
}
for touch in touches.iter_just_canceled() {
info!("canceled touch with id: {}", touch.id());
}
// you can also iterate all current touches and retrieve their state like this:
for touch in touches.iter() {
info!("active touch: {touch:?}");
info!(" just_pressed: {}", touches.just_pressed(touch.id()));
}
}

View File

@@ -0,0 +1,16 @@
//! Prints out all touch inputs.
use bevy::{input::touch::*, prelude::*};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, touch_event_system)
.run();
}
fn touch_event_system(mut touch_events: EventReader<TouchInput>) {
for event in touch_events.read() {
info!("{:?}", event);
}
}