diff --git a/examples/bevy_api_testing.rs b/examples/bevy_api_testing.rs index 7bc27c18441fca92f6187404531239e319d7c281..75f7d4d2562f37d688262b322956817f72b38b16 100644 --- a/examples/bevy_api_testing.rs +++ b/examples/bevy_api_testing.rs @@ -1,8 +1,5 @@ use bevy::prelude::*; -use bevy_cosmic_edit::{ - bevy_color_to_cosmic, change_active_editor_sprite, change_active_editor_ui, Attrs, AttrsOwned, - CosmicAttrs, CosmicEditPlugin, CosmicEditSpriteBundle, CosmicEditUiBundle, Focus, -}; +use bevy_cosmic_edit::*; fn setup(mut commands: Commands) { commands.spawn(Camera2dBundle::default()); @@ -39,6 +36,15 @@ fn setup(mut commands: Commands) { commands.insert_resource(Focus(Some(sprite_editor))); } +pub fn bevy_color_to_cosmic(color: bevy::prelude::Color) -> CosmicColor { + cosmic_text::Color::rgba( + (color.r() * 255.) as u8, + (color.g() * 255.) as u8, + (color.b() * 255.) as u8, + (color.a() * 255.) as u8, + ) +} + fn main() { App::new() .add_plugins(DefaultPlugins) diff --git a/examples/every_option.rs b/examples/every_option.rs index 9777aeee3eb2c517cda89813a9156f6b0fb16a2d..c522c701bf48a8e4e595f54d954c7684e1d34ccf 100644 --- a/examples/every_option.rs +++ b/examples/every_option.rs @@ -1,10 +1,5 @@ use bevy::{prelude::*, ui::FocusPolicy, window::PrimaryWindow}; -use bevy_cosmic_edit::{ - bevy_color_to_cosmic, change_active_editor_sprite, change_active_editor_ui, get_x_offset, - Attrs, AttrsOwned, CosmicAttrs, CosmicBackground, CosmicEditPlugin, CosmicEditUiBundle, - CosmicEditor, CosmicMaxChars, CosmicMaxLines, CosmicMetrics, CosmicText, CosmicTextPosition, - Edit, Focus, -}; +use bevy_cosmic_edit::*; #[derive(Resource)] struct TextChangeTimer(pub Timer); @@ -61,6 +56,15 @@ fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { ))); } +pub fn bevy_color_to_cosmic(color: bevy::prelude::Color) -> CosmicColor { + cosmic_text::Color::rgba( + (color.r() * 255.) as u8, + (color.g() * 255.) as u8, + (color.b() * 255.) as u8, + (color.a() * 255.) as u8, + ) +} + // Test for update_buffer_text fn text_swapper( mut timer: ResMut<TextChangeTimer>, diff --git a/examples/font_per_widget.rs b/examples/font_per_widget.rs index fa90dadaf44ea6f239761004fe4b5928207c5ba5..7f7a336e77bf7c3054a2ab8182b361695a711b3d 100644 --- a/examples/font_per_widget.rs +++ b/examples/font_per_widget.rs @@ -1,11 +1,7 @@ #![allow(clippy::type_complexity)] use bevy::{prelude::*, window::PrimaryWindow}; -use bevy_cosmic_edit::{ - bevy_color_to_cosmic, change_active_editor_sprite, change_active_editor_ui, Attrs, AttrsOwned, - CosmicAttrs, CosmicEditPlugin, CosmicEditUiBundle, CosmicFontConfig, CosmicMetrics, CosmicText, - CosmicTextPosition, Family, Focus, FontStyle, FontWeight, -}; +use bevy_cosmic_edit::*; fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { commands.spawn(Camera2dBundle::default()); @@ -262,6 +258,15 @@ fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { commands.insert_resource(Focus(id)); } +pub fn bevy_color_to_cosmic(color: bevy::prelude::Color) -> CosmicColor { + cosmic_text::Color::rgba( + (color.r() * 255.) as u8, + (color.g() * 255.) as u8, + (color.b() * 255.) as u8, + (color.a() * 255.) as u8, + ) +} + fn main() { let font_config = CosmicFontConfig { fonts_dir_path: None, diff --git a/examples/image_background.rs b/examples/image_background.rs index fbbb0e3ce561ae8b97ede7d4c03a2827609af03d..e3d2f87fa8d4382c06846abeb1e80eaa80ba4404 100644 --- a/examples/image_background.rs +++ b/examples/image_background.rs @@ -1,8 +1,5 @@ use bevy::prelude::*; -use bevy_cosmic_edit::{ - bevy_color_to_cosmic, change_active_editor_sprite, change_active_editor_ui, Attrs, AttrsOwned, - CosmicAttrs, CosmicBackground, CosmicEditPlugin, CosmicEditUiBundle, Focus, -}; +use bevy_cosmic_edit::*; fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { commands.spawn(Camera2dBundle::default()); @@ -29,6 +26,15 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { commands.insert_resource(Focus(Some(editor))); } +pub fn bevy_color_to_cosmic(color: bevy::prelude::Color) -> CosmicColor { + cosmic_text::Color::rgba( + (color.r() * 255.) as u8, + (color.g() * 255.) as u8, + (color.b() * 255.) as u8, + (color.a() * 255.) as u8, + ) +} + fn main() { App::new() .add_plugins(DefaultPlugins) diff --git a/examples/multiple_sprites.rs b/examples/multiple_sprites.rs index 77e7ad54a5ed896ffb6d69bf912d1773560965e5..d93018b9c87b0c9e60a4d8ce362ca98a819d8d8a 100644 --- a/examples/multiple_sprites.rs +++ b/examples/multiple_sprites.rs @@ -1,9 +1,5 @@ use bevy::{core_pipeline::clear_color::ClearColorConfig, prelude::*, window::PrimaryWindow}; -use bevy_cosmic_edit::{ - bevy_color_to_cosmic, change_active_editor_sprite, change_active_editor_ui, Attrs, AttrsOwned, - CosmicAttrs, CosmicEditPlugin, CosmicEditSpriteBundle, CosmicFontConfig, CosmicMetrics, - CosmicText, CosmicTextPosition, Family, Focus, -}; +use bevy_cosmic_edit::*; fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { let primary_window = windows.single(); @@ -69,6 +65,15 @@ fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { commands.spawn(cosmic_edit_2); } +pub fn bevy_color_to_cosmic(color: bevy::prelude::Color) -> CosmicColor { + cosmic_text::Color::rgba( + (color.r() * 255.) as u8, + (color.g() * 255.) as u8, + (color.b() * 255.) as u8, + (color.a() * 255.) as u8, + ) +} + fn main() { let font_bytes: &[u8] = include_bytes!("../assets/fonts/VictorMono-Regular.ttf"); let font_config = CosmicFontConfig { diff --git a/examples/readonly.rs b/examples/readonly.rs index e42a3b259ee24330cd6cb9d0932fe377e6704a9c..16207d1e03ae1fd9f261563bd8804c9dc75e0966 100644 --- a/examples/readonly.rs +++ b/examples/readonly.rs @@ -1,8 +1,5 @@ use bevy::{prelude::*, window::PrimaryWindow}; -use bevy_cosmic_edit::{ - bevy_color_to_cosmic, Attrs, AttrsOwned, CosmicAttrs, CosmicEditPlugin, CosmicEditUiBundle, - CosmicFontConfig, CosmicMetrics, CosmicText, CosmicTextPosition, Family, Focus, ReadOnly, -}; +use bevy_cosmic_edit::*; fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { let primary_window = windows.single(); @@ -51,6 +48,15 @@ fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { commands.insert_resource(Focus(id)); } +pub fn bevy_color_to_cosmic(color: bevy::prelude::Color) -> CosmicColor { + cosmic_text::Color::rgba( + (color.r() * 255.) as u8, + (color.g() * 255.) as u8, + (color.b() * 255.) as u8, + (color.a() * 255.) as u8, + ) +} + fn main() { let font_bytes: &[u8] = include_bytes!("../assets/fonts/VictorMono-Regular.ttf"); let font_config = CosmicFontConfig { diff --git a/examples/restricted_input.rs b/examples/restricted_input.rs index 7077e37ae35c693410823056ad8241271bbfffbe..77f16ebb18fe00b249b8d594e3dc15c72be33e08 100644 --- a/examples/restricted_input.rs +++ b/examples/restricted_input.rs @@ -1,9 +1,5 @@ use bevy::{prelude::*, window::PrimaryWindow}; -use bevy_cosmic_edit::{ - bevy_color_to_cosmic, change_active_editor_sprite, change_active_editor_ui, Attrs, AttrsOwned, - CosmicAttrs, CosmicEditPlugin, CosmicEditUiBundle, CosmicMaxChars, CosmicMaxLines, - CosmicMetrics, CosmicText, Focus, -}; +use bevy_cosmic_edit::*; fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { commands.spawn(Camera2dBundle::default()); @@ -43,6 +39,15 @@ fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { commands.insert_resource(Focus(Some(editor))); } +pub fn bevy_color_to_cosmic(color: bevy::prelude::Color) -> CosmicColor { + cosmic_text::Color::rgba( + (color.r() * 255.) as u8, + (color.g() * 255.) as u8, + (color.b() * 255.) as u8, + (color.a() * 255.) as u8, + ) +} + fn main() { App::new() .add_plugins(DefaultPlugins) diff --git a/src/lib.rs b/src/lib.rs index b970fee16507cc26b00399b7ab5288fb4abe79d7..921b9cc2d8e01a632b9e427bcbe11a8d3421e349 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -655,15 +655,6 @@ fn save_edit_history( }; } -pub fn bevy_color_to_cosmic(color: bevy::prelude::Color) -> cosmic_text::Color { - cosmic_text::Color::rgba( - (color.r() * 255.) as u8, - (color.g() * 255.) as u8, - (color.b() * 255.) as u8, - (color.a() * 255.) as u8, - ) -} - fn get_text_size(buffer: &Buffer) -> (f32, f32) { let width = buffer.layout_runs().map(|run| run.line_w).reduce(f32::max); let height = buffer.layout_runs().count() as f32 * buffer.metrics().line_height;