From 5f5dd89f853f86153d9c1e2b1ac6177211e12659 Mon Sep 17 00:00:00 2001 From: sam edelsten <samedelsten1@gmail.com> Date: Mon, 29 Apr 2024 15:58:33 +0100 Subject: [PATCH] fix placeholder on passwords, remove feature gates --- Cargo.toml | 6 ++---- examples/password.rs | 3 ++- src/lib.rs | 3 --- src/plugins/mod.rs | 2 -- src/plugins/password/mod.rs | 23 +++++++++++++++++++---- src/plugins/placeholder/mod.rs | 9 +++++++-- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b4dc8d0..2c425e2 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 5dc4d50..0539f39 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 308de2c..1cc13e0 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 8355c2f..08a7f60 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 7a7d045..a36109c 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 7fa3d94..a180779 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), ); } } -- GitLab