diff --git a/examples/bevy_api_testing.rs b/examples/bevy_api_testing.rs index fcb9bc8f0abac266939ecf841e7671c7db8654d7..822a17c9ebf1c3193b2daca9244847e1a314aec2 100644 --- a/examples/bevy_api_testing.rs +++ b/examples/bevy_api_testing.rs @@ -1,8 +1,9 @@ use bevy::prelude::*; use bevy_cosmic_edit::{ - change_active_editor_sprite, change_active_editor_ui, ActiveEditor, CosmicEditPlugin, - CosmicEditSpriteBundle, CosmicEditUiBundle, + change_active_editor_sprite, change_active_editor_ui, ActiveEditor, CosmicAttrs, + CosmicEditPlugin, CosmicEditSpriteBundle, CosmicEditUiBundle, }; +use cosmic_text::{Attrs, AttrsOwned}; fn setup(mut commands: Commands) { commands.spawn(Camera2dBundle::default()); @@ -17,6 +18,9 @@ fn setup(mut commands: Commands) { top: Val::Px(100.), ..default() }, + cosmic_attrs: CosmicAttrs(AttrsOwned::new( + Attrs::new().color(cosmic_text::Color::rgb(0, 255, 0)), + )), ..default() }); diff --git a/src/lib.rs b/src/lib.rs index 164865c3e40d4b753a54e5db081766746a1a76f4..3c5b79cf2003214b50becb5fe92195c57e8c7ceb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1009,6 +1009,7 @@ fn redraw_buffer_common( images: &mut ResMut<Assets<Image>>, swash_cache_state: &mut ResMut<SwashCacheState>, editor: &mut Editor, + attrs: &CosmicAttrs, background_image: Option<Handle<Image>>, background_color: Color, cosmic_canvas_img_handle: &mut Handle<Image>, @@ -1026,7 +1027,11 @@ fn redraw_buffer_common( editor .buffer_mut() .set_size(&mut font_system.0, width, height); - let font_color = cosmic_text::Color::rgb(0, 0, 0); + + let font_color = attrs + .0 + .color_opt + .unwrap_or(cosmic_text::Color::rgb(0, 0, 0)); let mut pixels = vec![0; width as usize * height as usize * 4]; if let Some(bg_image) = background_image { @@ -1116,6 +1121,7 @@ fn cosmic_edit_redraw_buffer_ui( mut swash_cache_state: ResMut<SwashCacheState>, mut cosmic_edit_query: Query<( &mut CosmicEditor, + &CosmicAttrs, &CosmicBackground, &BackgroundColor, &CosmicTextPosition, @@ -1128,6 +1134,7 @@ fn cosmic_edit_redraw_buffer_ui( let primary_window = windows.single(); for ( mut editor, + attrs, background_image, background_color, text_position, @@ -1144,6 +1151,7 @@ fn cosmic_edit_redraw_buffer_ui( &mut images, &mut swash_cache_state, &mut editor.0, + attrs, background_image.0.clone(), background_color.0, &mut img.texture, @@ -1168,6 +1176,7 @@ fn cosmic_edit_redraw_buffer( mut swash_cache_state: ResMut<SwashCacheState>, mut cosmic_edit_query: Query<( &mut CosmicEditor, + &CosmicAttrs, &Sprite, &CosmicBackground, &BackgroundColor, @@ -1180,6 +1189,7 @@ fn cosmic_edit_redraw_buffer( let primary_window = windows.single(); for ( mut editor, + attrs, sprite, background_image, background_color, @@ -1196,6 +1206,7 @@ fn cosmic_edit_redraw_buffer( &mut images, &mut swash_cache_state, &mut editor.0, + attrs, background_image.0.clone(), background_color.0, &mut handle,