Widget focus
All checks were successful
Build / Build (push) Successful in 59m0s

This commit is contained in:
Silas Bartha 2025-03-27 19:06:53 -04:00
parent 9bcb260cca
commit 8514c007d5
2 changed files with 13 additions and 5 deletions

View File

@ -1,4 +1,7 @@
use bevy::prelude::*; use bevy::prelude::*;
/// Terminal widget entity currently focused and handling input
/// Can be manipulated directly or you can request an entity be focused through
/// the `focus_widget` command.
#[derive(Resource, Default, Deref, DerefMut, Debug)] #[derive(Resource, Default, Deref, DerefMut, Debug)]
pub struct FocusedWidget(pub Option<Entity>); pub struct FocusedWidget(pub Option<Entity>);

View File

@ -2,19 +2,24 @@ use bevy::prelude::*;
use crate::input::events::TerminalInputEvent; use crate::input::events::TerminalInputEvent;
use super::components::Widget; use super::{components::Widget, resources::FocusedWidget};
/// Invokes every enabled widget's `handle_events` methods for each incoming input event /// Invokes focused widget's `handle_events` methods for each incoming input event
pub fn widget_input_handling( pub fn widget_input_handling(
mut widgets: Query<&mut Widget>, mut widgets: Query<&mut Widget>,
mut event_reader: EventReader<TerminalInputEvent>, mut event_reader: EventReader<TerminalInputEvent>,
mut commands: Commands, mut commands: Commands,
focused_widget: Res<FocusedWidget>,
) { ) {
if let Some(entity) = **focused_widget {
if let Ok(mut widget) = widgets.get_mut(entity) {
if widget.enabled == true {
for event in event_reader.read() { for event in event_reader.read() {
for mut widget in widgets.iter_mut().filter(|widget| widget.enabled) {
widget.widget.handle_events(event, &mut commands); widget.widget.handle_events(event, &mut commands);
} }
} }
}
}
} }
pub fn update_widgets(mut widgets: Query<&mut Widget>, time: Res<Time>, mut commands: Commands) { pub fn update_widgets(mut widgets: Query<&mut Widget>, time: Res<Time>, mut commands: Commands) {