use bevy::prelude::*; use bevy_iced::iced::widget::text; use bevy_iced::{IcedContext, IcedPlugin}; use bevy_input::keyboard::KeyboardInput; use bevy_input::ButtonState; #[derive(Event)] pub enum UiMessage {} #[derive(Resource, PartialEq, Eq)] pub struct UiActive(bool); pub fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugins(IcedPlugin::default()) .add_event::() .insert_resource(UiActive(true)) .add_systems(Update, toggle_system) .add_systems(Update, ui_system.run_if(resource_equals(UiActive(true)))) .run(); } fn toggle_system(mut keyboard: EventReader, mut active: ResMut) { for event in keyboard.read() { if event.key_code == KeyCode::Space && event.state == ButtonState::Pressed { active.0 = !active.0; } } } fn ui_system(mut ctx: IcedContext) { ctx.display(text("Press space to toggle GUI.")); }