diff options
author | Silas Bartha <[email protected]> | 2024-06-04 15:00:16 -0400 |
---|---|---|
committer | Silas Bartha <[email protected]> | 2024-06-04 15:00:16 -0400 |
commit | a002e4d738535e6ca779c71231f7b84864b9a8d0 (patch) | |
tree | 8ec521b535f3820328f9ea6f2511ca29c630b82f /src/widgets/systems.rs | |
parent | 56aafda8495243fa939bdce01f36d4adbf4ec556 (diff) |
Refactored + Renamed + Added Docs
Diffstat (limited to 'src/widgets/systems.rs')
-rw-r--r-- | src/widgets/systems.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/widgets/systems.rs b/src/widgets/systems.rs new file mode 100644 index 0000000..69a84e3 --- /dev/null +++ b/src/widgets/systems.rs @@ -0,0 +1,35 @@ +use bevy::prelude::*; + +use crate::{display::resources::Terminal, input::events::TerminalInputEvent}; + +use super::components::Widget; + +/// Invokes every enabled widget's `render` method +pub fn draw_widgets(mut terminal: ResMut<Terminal>, mut widgets: Query<&mut Widget>) { + terminal + .0 + .draw(|frame| { + let mut active_widgets = widgets + .iter_mut() + .filter(|widget| widget.enabled) + .collect::<Vec<_>>(); + active_widgets.sort_by(|a, b| a.depth.cmp(&b.depth)); + for mut widget in active_widgets { + widget.widget.render(frame, frame.size()); + } + }) + .unwrap(); +} + +/// Invokes every enabled 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, +) { + for event in event_reader.read() { + for mut widget in widgets.iter_mut().filter(|widget| widget.enabled) { + widget.widget.handle_events(event, &mut commands); + } + } +} |