Skip to content

Commit e669fce

Browse files
committed
small fixes for emscripten support (luaegui)
1 parent 4b15c0a commit e669fce

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
[package]
22
name = "egui_overlay"
3-
version.workspace = true
3+
version = "0.8.1"
44
repository.workspace = true
55
edition.workspace = true
66
license.workspace = true
77
description = "Egui integration to easily create Desktop Overlays"
88

99
[features]
10-
default = ["egui_default", "three_d"]
10+
default = ["egui_default", "glfw_default", "three_d"]
1111
egui_default = ["egui/default"]
12+
glfw_default = ["egui_window_glfw_passthrough/default"]
1213
three_d = ["dep:egui_render_three_d"]
1314
wgpu = ["dep:egui_render_wgpu"]
1415

1516
[dependencies]
16-
egui_window_glfw_passthrough = { version = "0.8", path = "crates/egui_window_glfw_passthrough" }
17+
egui_window_glfw_passthrough = { version = "0.8", path = "crates/egui_window_glfw_passthrough", default-features = false }
1718
egui = { workspace = true }
1819
tracing = { workspace = true }
1920
raw-window-handle = { workspace = true }

crates/egui_window_glfw_passthrough/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "egui_window_glfw_passthrough"
33
description = "egui windowing backend using Glfw"
4-
version.workspace = true
4+
version = "0.8.1"
55
repository.workspace = true
66
edition.workspace = true
77
license.workspace = true

crates/egui_window_glfw_passthrough/src/lib.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -641,16 +641,20 @@ impl GlfwBackend {
641641
/// 2. Non-Printable.
642642
///
643643
/// Printable keys are dependent on layout. For example, `W` in `Qwerty` layout will map to `Z` in `Azerty` layout.
644-
/// For text, we will always use the text event. But for "keys" (eg: game input), we will need to decide whether to consider the `W`` as `W`` or `Z`.
644+
/// For text, we will always use the text event. But for "keys" (eg: game input), we will need to decide whether to consider the `W` as `W` or `Z`.
645645
/// For all printable keys like `W`, we will use this fn to translate to egui's `Key`. So, we will translate it to `Z`.
646646
/// For non-printable keys like `Enter` or `Backspace` or `F2`, we will translate in a layout independent way.
647647
/// This is very useful for eg: keyboard shortcuts, as user expects to see `Z` when he uses it as shortcut on his keyboard.
648648
///
649649
/// You can directly use [layout_independent_glfw_to_egui_key] to just get the physical key location without caring about logical layout.
650650
/// So, you will simply get `W` even if the user is using Azerty layout. This is important, as you want to preserve the "positions" irrespective of layouts.
651651
/// So, pressing the key at `W` location will always move the character forward, even if it is `Z` according to layout.
652+
#[allow(unused)]
652653
pub fn layout_based_glfw_to_egui_key(key: glfw::Key, scancode: i32) -> Option<Key> {
653-
match key {
654+
#[cfg(target_os = "emscripten")]
655+
return layout_independent_glfw_to_egui_key(key);
656+
#[cfg(not(target_os = "emscripten"))]
657+
return match key {
654658
glfw::Key::Apostrophe
655659
| glfw::Key::Comma
656660
| glfw::Key::Minus
@@ -719,7 +723,7 @@ pub fn layout_based_glfw_to_egui_key(key: glfw::Key, scancode: i32) -> Option<Ke
719723
name.and_then(|n| egui::Key::from_name(&n))
720724
}
721725
_ => layout_independent_glfw_to_egui_key(key),
722-
}
726+
};
723727
}
724728
/// a function to get the matching egui key event for a given glfw key. egui does not support all the keys provided here.
725729
/// This just matches the enum to map to the relevant egui key.

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ pub trait EguiOverlay {
118118
}
119119
}
120120

121-
pub struct OverlayApp<T: EguiOverlay> {
121+
pub struct OverlayApp<T: EguiOverlay + 'static> {
122122
pub user_data: T,
123123
pub egui_context: Context,
124124
pub default_gfx_backend: DefaultGfxBackend,
125125
pub glfw_backend: GlfwBackend,
126126
}
127127

128-
impl<T: EguiOverlay> OverlayApp<T> {
128+
impl<T: EguiOverlay + 'static> OverlayApp<T> {
129129
pub fn enter_event_loop(mut self) {
130130
// polls for events and returns if there's some activity.
131131
// But if there is no event for the specified duration, it will return anyway.
@@ -171,7 +171,7 @@ impl<T: EguiOverlay> OverlayApp<T> {
171171

172172
// on emscripten, just keep calling forever i guess.
173173
#[cfg(target_os = "emscripten")]
174-
set_main_loop_callback(callback);
174+
egui_window_glfw_passthrough::set_main_loop_callback(callback);
175175

176176
#[cfg(not(target_os = "emscripten"))]
177177
{

0 commit comments

Comments
 (0)