Skip to content

Commit

Permalink
cleanup and working but janky 0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivy committed Jul 13, 2024
1 parent 55bad5b commit 7b8438b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ web-sys = { version = "0.3.63", features = [
"EventTarget",
"HtmlInputElement",
"InputEvent",
"KeyboardEvent",
"Navigator",
"TouchEvent",
"Window",
Expand Down
2 changes: 1 addition & 1 deletion src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ pub fn process_input_system(
});
}

#[cfg(target_arch = "wasm32")]
let mut editing_text = false;
#[cfg(target_arch = "wasm32")]
for context in context_params.contexts.iter() {
Expand Down Expand Up @@ -390,7 +391,6 @@ pub fn process_input_system(
});
}
bevy::input::touch::TouchPhase::Moved => {

window_context
.egui_input
.events
Expand Down
24 changes: 2 additions & 22 deletions src/text_agent.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! The text agent is an `<input>` element used to trigger
//! mobile keyboard and IME input.

use std::{cell::Cell, rc::Rc, sync::Mutex};
use std::sync::Mutex;

use bevy::{
prelude::{EventWriter, Res, Resource},
Expand Down Expand Up @@ -76,7 +76,6 @@ pub fn install_text_agent(sender: Sender<egui::Event>) -> Result<(), JsValue> {
.dyn_into::<web_sys::HtmlInputElement>()?;
let input = std::rc::Rc::new(input);
input.set_id(AGENT_ID);
let is_composing = Rc::new(Cell::new(false));
{
let style = input.style();
// Transparent
Expand Down Expand Up @@ -134,31 +133,12 @@ pub fn install_text_agent(sender: Sender<egui::Event>) -> Result<(), JsValue> {
}

{
// When IME is off
let input_clone = input.clone();
let sender_clone = sender.clone();
let is_composing = is_composing.clone();
let on_input = Closure::wrap(Box::new(move |_event: web_sys::InputEvent| {
let text = input_clone.value();
if !text.is_empty() && !is_composing.get() {
input_clone.set_value("");
if text.len() == 1 {
let _ = sender_clone.send(egui::Event::Text(text.clone()));
}
}
}) as Box<dyn FnMut(_)>);
input.add_event_listener_with_callback("input", on_input.as_ref().unchecked_ref())?;
on_input.forget();
}

{
// When IME is off
let input_clone = input.clone();
let sender_clone = sender.clone();
let is_composing = is_composing.clone();
let on_input = Closure::wrap(Box::new(move |_event: web_sys::InputEvent| {
let text = input_clone.value();
if !text.is_empty() && !is_composing.get() {
if !text.is_empty() {
input_clone.set_value("");
if text.len() == 1 {
let _ = sender_clone.send(egui::Event::Text(text.clone()));
Expand Down

0 comments on commit 7b8438b

Please sign in to comment.