diff --git a/life/src/main.rs b/life/src/main.rs index ce923a1..9c65054 100644 --- a/life/src/main.rs +++ b/life/src/main.rs @@ -12,7 +12,14 @@ #![allow(dead_code)] use bevy::{ - feathers::{containers::*, theme::ThemeProps}, + feathers::{ + constants::{fonts, size}, + containers::*, + font_styles::InheritableFont, + theme::{InheritableThemeTextColor, ThemeProps}, + tokens, + }, + text::FontWeight, ui::{Checked, InteractionDisabled}, ui_widgets::{ ActivateOnPress, Checkbox, SliderPrecision, SliderStep, ValueChange, checkbox_self_update, @@ -77,6 +84,8 @@ fn main() { reassign_cell_pitch.run_if(resource_changed::), update_audio, update_material, + update_debug_info_cell_count, + update_debug_info_coordinates, ), ) .add_systems(Update, cell_lifecycle.run_if(on_message::)) @@ -87,6 +96,14 @@ fn main() { const SCALE: f32 = 100.0; +#[derive(Component, PartialEq, Clone, Default)] +enum DebugInfo { + CellCount, + Coordinates, + #[default] + Empty, +} + #[derive(States, Debug, Default, Hash, PartialEq, Eq, Clone, Component, FromTemplate)] enum AudioPlayback { #[default] @@ -189,7 +206,102 @@ fn update_pitch_map_resource_ui( }); } +fn text_setup() -> impl Scene { + bsn! { + // Feathers propagates text styles only through entities that themselves have + // ThemedText, so a body holding loose text must carry these itself. + InheritableThemeTextColor(tokens::TEXT_MAIN) + InheritableFont { + font: fonts::REGULAR, + font_size: size::MEDIUM_FONT, + weight: FontWeight::NORMAL, + } + } +} + fn the_ui() -> impl Scene { + bsn! { + Node { + width: Val::Percent(100.0), + top: Val::Px(0.0), + left: Val::Px(0.0), + display: Display::Flex, + flex_direction: FlexDirection::Row, + justify_content: JustifyContent::SpaceBetween, + } + Transform + Children [ + primary_ui(), + debug_ui(), + ] + } +} + +fn debug_ui() -> impl Scene { + bsn! { + Node { + justify_self: JustifySelf::End, + display: Display::Flex, + flex_direction: FlexDirection::Column, + } + // TODO: Toggle visibility when debugging disabled + pane() + Transform + Children [ + pane_header() + Children [ + Text("Debug Info") ThemedText, + ], + pane_body() + Children [ + subpane() + Node { + display: Display::Flex, + flex_direction: FlexDirection::Row, + } + Children [ + subpane_header() Children [ + Text("Cell Count") ThemedText + ] + subpane_body() + Node { + display: Display::Flex, + flex_direction: FlexDirection::Row, + align_items: AlignItems::Stretch, + justify_content: JustifyContent::Start, + } + text_setup() + Children [ + Text("###") ThemedText template_value(DebugInfo::CellCount) + ] + ], + subpane() + Node { + display: Display::Flex, + flex_direction: FlexDirection::Row, + } + Children [ + subpane_header() Children [ + Text("Coordinates") ThemedText + ] + subpane_body() + Node { + display: Display::Flex, + flex_direction: FlexDirection::Row, + align_items: AlignItems::Stretch, + justify_content: JustifyContent::Start, + } + text_setup() + Children [ + Text("##,##") ThemedText template_value(DebugInfo::Coordinates) + ] + ] + ] + ] + } +} + +fn primary_ui() -> impl Scene { fn toggle_note( change: On>, notes: Query<&Note, With>, @@ -205,12 +317,9 @@ fn the_ui() -> impl Scene { bsn! { Node { - top: Val::Px(0.0), - left: Val::Px(0.0), display: Display::Flex, flex_direction: FlexDirection::Column, justify_content: JustifyContent::Start, - } Transform pane() @@ -1084,3 +1193,22 @@ fn update_audio( commands.entity(e).insert(AudioPlayer(h)); }); } + +fn update_debug_info_cell_count(query: Query<&Cell>, mut text: Query<(&DebugInfo, &mut Text)>) { + text.iter_mut() + .filter(|(di, _)| **di == DebugInfo::CellCount) + .for_each(|(_, mut t)| { + *t = Text::new(format!("{}", query.count())); + }); +} + +fn update_debug_info_coordinates( + coordinates: Res, + mut text: Query<(&DebugInfo, &mut Text)>, +) { + text.iter_mut() + .filter(|(di, _)| **di == DebugInfo::Coordinates) + .for_each(|(_, mut t)| { + *t = Text::new(format!("{},{}", coordinates.0.x, coordinates.0.y)); + }); +}