diff --git a/Cargo.toml b/Cargo.toml index b4dc8d0b68c040697f6c8d6d3a5a35cb1e4ccca9..2c425e21aa9fe12f9ddf1d57732b6403f91dc97c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,6 @@ exclude = ["assets/*"] [features] multicam = [] -placeholder = [] -password = ["unicode-segmentation"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -34,11 +32,11 @@ bevy = { version = "0.13", default-features = false, features = [ ] } cosmic-text = { version = "0.11.2" } # TODO: move crossbeam to wasm32, once input.rs has separate wasm copy/paste fn +unicode-segmentation = { version = "1.11.0" } + crossbeam-channel = "0.5.8" image = "0.24.6" sys-locale = "0.3.0" -unicode-segmentation = { version = "1.11.0", optional = true } - [target.'cfg(not(target_arch = "wasm32"))'.dependencies] arboard = "3.2.0" diff --git a/examples/password.rs b/examples/password.rs index 5dc4d507a8d22b7d4c34072a45108c6c50beb3e5..0539f39557b5f438a56a570ade71930164928b4f 100644 --- a/examples/password.rs +++ b/examples/password.rs @@ -1,5 +1,5 @@ use bevy::prelude::*; -use bevy_cosmic_edit::{password::Password, *}; +use bevy_cosmic_edit::{password::Password, placeholder::Placeholder, *}; use util::{change_active_editor_sprite, deselect_editor_on_esc, print_editor_text}; fn setup(mut commands: Commands) { @@ -23,6 +23,7 @@ fn setup(mut commands: Commands) { ..default() }, Password::default(), + Placeholder::new("Password", Attrs::new()), )); } diff --git a/src/lib.rs b/src/lib.rs index 308de2cc4f8c024bb91cb0fabeb3baf056a1585a..1cc13e040cc458929113ac5fb4116b6ef813a7af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -293,10 +293,7 @@ impl Plugin for CosmicEditPlugin { } fn add_feature_plugins(app: &mut App) -> &mut App { - #[cfg(feature = "placeholder")] app.add_plugins(plugins::placeholder::PlaceholderPlugin); - - #[cfg(feature = "password")] app.add_plugins(plugins::password::PasswordPlugin); app diff --git a/src/plugins/mod.rs b/src/plugins/mod.rs index 8355c2fb4089375d89fad9d153c68621f4b4028a..08a7f609753d4e9fc21c3d47d18b1c76649df80d 100644 --- a/src/plugins/mod.rs +++ b/src/plugins/mod.rs @@ -1,4 +1,2 @@ -#[cfg(feature = "password")] pub mod password; -#[cfg(feature = "placeholder")] pub mod placeholder; diff --git a/src/plugins/password/mod.rs b/src/plugins/password/mod.rs index 7a7d045e14aff518bf59e8a3fc3b38f3795ae6cf..a36109c8e5bfc303172a59f6a326a95ce4863983 100644 --- a/src/plugins/password/mod.rs +++ b/src/plugins/password/mod.rs @@ -1,4 +1,4 @@ -use crate::buffer::BufferExtras; +use crate::{buffer::BufferExtras, placeholder::Placeholder}; use bevy::prelude::*; use cosmic_text::{Cursor, Edit, Selection, Shaping}; use unicode_segmentation::UnicodeSegmentation; @@ -10,6 +10,9 @@ use crate::{ pub struct PasswordPlugin; +#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)] +pub struct PasswordSet; + impl Plugin for PasswordPlugin { fn build(&self, app: &mut App) { app.add_systems(PreUpdate, (hide_password_text.before(input_mouse),)) @@ -22,7 +25,7 @@ impl Plugin for PasswordPlugin { .add_systems( PostUpdate, ( - hide_password_text.before(Render), + hide_password_text.before(Render).in_set(PasswordSet), restore_password_text.after(Render), ), ); @@ -50,10 +53,16 @@ fn hide_password_text( &mut CosmicBuffer, &DefaultAttrs, Option<&mut CosmicEditor>, + Option<&Placeholder>, )>, mut font_system: ResMut<CosmicFontSystem>, ) { - for (mut password, mut buffer, attrs, editor_opt) in q.iter_mut() { + for (mut password, mut buffer, attrs, editor_opt, placeholder_opt) in q.iter_mut() { + if let Some(placeholder) = placeholder_opt { + if placeholder.is_active() { + continue; + } + } if let Some(mut editor) = editor_opt { let mut cursor = editor.cursor(); let mut selection = editor.selection(); @@ -122,10 +131,16 @@ fn restore_password_text( &mut CosmicBuffer, &DefaultAttrs, Option<&mut CosmicEditor>, + Option<&Placeholder>, )>, mut font_system: ResMut<CosmicFontSystem>, ) { - for (password, mut buffer, attrs, editor_opt) in q.iter_mut() { + for (password, mut buffer, attrs, editor_opt, placeholder_opt) in q.iter_mut() { + if let Some(placeholder) = placeholder_opt { + if placeholder.is_active() { + continue; + } + } if let Some(mut editor) = editor_opt { let mut cursor = editor.cursor(); let mut selection = editor.selection(); diff --git a/src/plugins/placeholder/mod.rs b/src/plugins/placeholder/mod.rs index 7fa3d94bfa8650929993a641d32c8f46e1fedbf6..a1807795af188ba9753dd358b753d691880e791c 100644 --- a/src/plugins/placeholder/mod.rs +++ b/src/plugins/placeholder/mod.rs @@ -1,4 +1,4 @@ -use crate::buffer::BufferExtras; +use crate::{buffer::BufferExtras, Render}; use bevy::prelude::*; use cosmic_text::{Attrs, Edit}; @@ -21,6 +21,10 @@ impl Placeholder { attrs, } } + + pub fn is_active(&self) -> bool { + self.active + } } pub struct PlaceholderPlugin; @@ -36,7 +40,8 @@ impl Plugin for PlaceholderPlugin { remove_placeholder_on_input, ) .chain() - .after(KbInput), + .after(KbInput) + .before(Render), ); } }