Skip to content

Commit

Permalink
prevent_default_event_handling and readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivy committed Aug 1, 2024
1 parent 2707b43 commit 6eaa8e0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ An example WASM project is live at [mvlabat.github.io/bevy_egui_web_showcase](ht
- Clipboard
- Opening URLs
- Multiple windows support (see [./examples/two_windows.rs](https://github.com/mvlabat/bevy_egui/blob/v0.20.1/examples/two_windows.rs))
- Mobile web virtual keyboard (still rough support and only works without prevent_default_event_handling set to false on the WindowPlugin primary_window)

`bevy_egui` can be compiled with using only `bevy`, `egui` and `bytemuck` as dependencies: `manage_clipboard` and `open_url` features,
that require additional crates, can be disabled.
Expand Down
80 changes: 47 additions & 33 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,41 +710,55 @@ impl Plugin for EguiPlugin {
#[cfg(target_arch = "wasm32")]
{
use bevy::prelude::Res;
app.init_resource::<text_agent::TextAgentChannel>();

app.add_systems(
PreStartup,
|channel: Res<text_agent::TextAgentChannel>,
mut subscribed_input_events: NonSendMut<SubscribedEvents<web_sys::InputEvent>>,
mut subscribed_keyboard_events: NonSendMut<
SubscribedEvents<web_sys::KeyboardEvent>,
>| {
text_agent::install_text_agent(
&mut subscribed_input_events,
&mut subscribed_keyboard_events,
channel.sender.clone(),
)
.unwrap();
},
);

app.add_systems(
PreStartup,
text_agent::virtual_keyboard_handler
.in_set(EguiSet::ProcessInput)
.after(process_input_system)
.after(InputSystem)
.after(EguiSet::InitContexts),
);
let maybe_window_plugin = app.get_added_plugins::<bevy::prelude::WindowPlugin>();

if !maybe_window_plugin.is_empty()
&& maybe_window_plugin[0].primary_window.is_some()
&& maybe_window_plugin[0]
.primary_window
.as_ref()
.unwrap()
.prevent_default_event_handling
{
app.init_resource::<text_agent::TextAgentChannel>();

app.add_systems(
PreStartup,
|channel: Res<text_agent::TextAgentChannel>,
mut subscribed_input_events: NonSendMut<
SubscribedEvents<web_sys::InputEvent>,
>,
mut subscribed_keyboard_events: NonSendMut<
SubscribedEvents<web_sys::KeyboardEvent>,
>| {
text_agent::install_text_agent(
&mut subscribed_input_events,
&mut subscribed_keyboard_events,
channel.sender.clone(),
)
.unwrap();
},
);

app.add_systems(
PreUpdate,
text_agent::propagate_text
.in_set(EguiSet::ProcessInput)
.after(process_input_system)
.after(InputSystem)
.after(EguiSet::InitContexts),
);
app.add_systems(
PreStartup,
text_agent::virtual_keyboard_handler
.in_set(EguiSet::ProcessInput)
.after(process_input_system)
.after(InputSystem)
.after(EguiSet::InitContexts),
);

app.add_systems(
PreUpdate,
text_agent::propagate_text
.in_set(EguiSet::ProcessInput)
.after(process_input_system)
.after(InputSystem)
.after(EguiSet::InitContexts),
);
}
}
app.add_systems(
PreUpdate,
Expand Down

0 comments on commit 6eaa8e0

Please sign in to comment.