From fa7b52e8ce47000c1215868017ab7257644f8d64 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Sat, 26 Aug 2023 08:31:22 -0700 Subject: [PATCH] Font buttons use their font for preview --- bin/editor.rs | 25 ++++++++++++++++++++++--- src/ui.rs | 20 +++++++++++++++----- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/bin/editor.rs b/bin/editor.rs index 39317e3..a4f22cc 100644 --- a/bin/editor.rs +++ b/bin/editor.rs @@ -242,7 +242,10 @@ fn initialize_ui(mut commands: Commands) { content_containers.iter().for_each(|(name, target)| { parent.spawn(( b.clone(), - ui::Title { text: name.clone() }, + ui::Title { + text: name.clone(), + ..default() + }, ui::Collapse { target: *target }, )); }); @@ -268,6 +271,7 @@ fn initialize_ui(mut commands: Commands) { }, ui::Title { text: "Assets".into(), + ..default() }, ui::Minimize { target: container }, ui::Sorting(0), @@ -380,6 +384,7 @@ mod audio { handle: handle.clone(), }, get_asset_name(&server, handle.clone()), + None, ); commands.entity(id).insert(AudioSourceBundle { source: handle.clone(), @@ -416,6 +421,7 @@ mod audio { handle: handle.clone(), }, get_asset_name(&server, handle.clone()), + None, ); commands.entity(id).insert(AudioSourceBundle { source: handle.clone(), @@ -473,6 +479,7 @@ mod assets { commands: &mut Commands, target: ui::TargetAsset, name: String, + font: Option>, ) -> Entity { commands .spawn(( @@ -487,7 +494,10 @@ mod assets { border_color: Color::BLACK.into(), ..default() }, - ui::Title { text: name }, + ui::Title { + text: name, + font: font.clone(), + }, )) .set_parent(root.single()) .id() @@ -512,7 +522,10 @@ mod assets { border_color: Color::BLACK.into(), ..default() }, - ui::Title { text: name }, + ui::Title { + text: name, + ..default() + }, )) .set_parent(root.single()) .id() @@ -585,6 +598,7 @@ mod gltf { handle: handle.clone(), }, get_asset_name(&server, handle.clone()), + None, ); } AssetEvent::Removed { handle } => { @@ -613,6 +627,7 @@ mod gltf { handle: handle.clone(), }, get_asset_name(&server, handle.clone()), + None, ); } }); @@ -762,6 +777,7 @@ mod scenes { handle: handle.clone(), }, name.clone(), + None, ); } CustomAssetEvent::Remove { handle } => { @@ -829,6 +845,7 @@ mod animations { handle: handle.clone(), }, name.clone(), + None, ); } CustomAssetEvent::Remove { handle } => { @@ -904,6 +921,7 @@ mod fonts { handle: handle.clone(), }, get_asset_name(&server, handle.clone()), + Some(handle.clone()), ); } AssetEvent::Removed { handle } => { @@ -932,6 +950,7 @@ mod fonts { handle: handle.clone(), }, get_asset_name(&server, handle.clone()), + Some(handle.clone()), ); } }); diff --git a/src/ui.rs b/src/ui.rs index 42192e9..4babd3e 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -55,9 +55,10 @@ pub use title::*; mod title { use super::*; - #[derive(Debug, Component)] + #[derive(Debug, Component, Default)] pub struct Title { pub text: String, + pub font: Option>, } #[derive(Debug, Component)] @@ -93,16 +94,24 @@ mod title { ) { events.for_each(|(entity, title, note, minimize, close)| { commands.entity(entity).with_children(|parent| { + let style = match &title.font { + Some(handle) => TextStyle { + color: Color::BLACK, + font: handle.clone(), + ..default() + }, + None => TextStyle { + color: Color::BLACK, + ..default() + }, + }; parent.spawn(( TextBundle { text: Text { sections: vec![ TextSection { value: title.text.clone(), - style: TextStyle { - color: Color::BLACK, - ..default() - }, + style, }, TextSection { value: note @@ -591,6 +600,7 @@ pub mod alert { }, Title { text: "Alert".into(), + ..default() }, Close { target: parent.parent_entity(),