diff options
author | Silas Bartha <[email protected]> | 2024-06-05 10:53:49 -0400 |
---|---|---|
committer | Silas Bartha <[email protected]> | 2024-06-05 10:53:49 -0400 |
commit | 10b09a1748a89800f8febec3f7ef1ab773101a05 (patch) | |
tree | 12bff04a347f8f2389fd518d62da2643bec8af88 | |
parent | 8fe2406277eb11719a03122b82199c06e0f54ed0 (diff) |
Moved widget rendering back into display system
-rw-r--r-- | src/display/systems.rs | 14 | ||||
-rw-r--r-- | src/lib.rs | 6 | ||||
-rw-r--r-- | src/widgets/systems.rs | 19 |
3 files changed, 14 insertions, 25 deletions
diff --git a/src/display/systems.rs b/src/display/systems.rs index a768af5..037f72d 100644 --- a/src/display/systems.rs +++ b/src/display/systems.rs @@ -2,16 +2,16 @@ use bevy::{ prelude::*, render::render_resource::{Extent3d, TextureFormat}, }; -use crossterm::event::Event; use bevy_framebuffer_extract::{ components::FramebufferExtractDestination, render_assets::FramebufferExtractSource, }; +use crossterm::event::Event; use ratatui::{ style::Stylize, widgets::{Paragraph, Wrap}, }; -use crate::input::events::TerminalInputEvent; +use crate::{input::events::TerminalInputEvent, widgets::components::Widget}; use super::resources::Terminal; @@ -28,6 +28,7 @@ const BRAILLE_DOT_BIT_POSITIONS: [u8; 8] = [0, 1, 2, 6, 3, 4, 5, 7]; pub fn print_to_terminal( mut terminal: ResMut<Terminal>, image_exports: Query<&FramebufferExtractDestination>, + mut widgets: Query<&mut Widget>, ) { for image_export in image_exports.iter() { let mut image = image_export @@ -77,6 +78,15 @@ pub fn print_to_terminal( .wrap(Wrap { trim: true }), frame.size(), ); + + 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()); + } }) .expect("Failed to draw terminal frame"); } @@ -83,11 +83,7 @@ impl Plugin for TerminalDisplayPlugin { ( input::systems::input_handling, display::systems::resize_handling, - ( - display::systems::print_to_terminal, - widgets::systems::draw_widgets, - ) - .chain(), + display::systems::print_to_terminal, widgets::systems::widget_input_handling, ), ) diff --git a/src/widgets/systems.rs b/src/widgets/systems.rs index 69a84e3..2626ec6 100644 --- a/src/widgets/systems.rs +++ b/src/widgets/systems.rs @@ -1,26 +1,9 @@ use bevy::prelude::*; -use crate::{display::resources::Terminal, input::events::TerminalInputEvent}; +use crate::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>, |