This commit is contained in:
parent
9bcb260cca
commit
8514c007d5
@ -1,4 +1,7 @@
|
||||
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)]
|
||||
pub struct FocusedWidget(pub Option<Entity>);
|
||||
|
@ -2,17 +2,22 @@ use bevy::prelude::*;
|
||||
|
||||
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(
|
||||
mut widgets: Query<&mut Widget>,
|
||||
mut event_reader: EventReader<TerminalInputEvent>,
|
||||
mut commands: Commands,
|
||||
focused_widget: Res<FocusedWidget>,
|
||||
) {
|
||||
for event in event_reader.read() {
|
||||
for mut widget in widgets.iter_mut().filter(|widget| widget.enabled) {
|
||||
widget.widget.handle_events(event, &mut commands);
|
||||
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() {
|
||||
widget.widget.handle_events(event, &mut commands);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user