Skip to content

Commit

Permalink
small fixes for emscripten support (luaegui)
Browse files Browse the repository at this point in the history
  • Loading branch information
coderedart committed Mar 1, 2024
1 parent 4b15c0a commit e669fce
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
[package]
name = "egui_overlay"
version.workspace = true
version = "0.8.1"
repository.workspace = true
edition.workspace = true
license.workspace = true
description = "Egui integration to easily create Desktop Overlays"

[features]
default = ["egui_default", "three_d"]
default = ["egui_default", "glfw_default", "three_d"]
egui_default = ["egui/default"]
glfw_default = ["egui_window_glfw_passthrough/default"]
three_d = ["dep:egui_render_three_d"]
wgpu = ["dep:egui_render_wgpu"]

[dependencies]
egui_window_glfw_passthrough = { version = "0.8", path = "crates/egui_window_glfw_passthrough" }
egui_window_glfw_passthrough = { version = "0.8", path = "crates/egui_window_glfw_passthrough", default-features = false }
egui = { workspace = true }
tracing = { workspace = true }
raw-window-handle = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/egui_window_glfw_passthrough/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "egui_window_glfw_passthrough"
description = "egui windowing backend using Glfw"
version.workspace = true
version = "0.8.1"
repository.workspace = true
edition.workspace = true
license.workspace = true
Expand Down
10 changes: 7 additions & 3 deletions crates/egui_window_glfw_passthrough/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,16 +641,20 @@ impl GlfwBackend {
/// 2. Non-Printable.
///
/// Printable keys are dependent on layout. For example, `W` in `Qwerty` layout will map to `Z` in `Azerty` layout.
/// 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`.
/// 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`.
/// For all printable keys like `W`, we will use this fn to translate to egui's `Key`. So, we will translate it to `Z`.
/// For non-printable keys like `Enter` or `Backspace` or `F2`, we will translate in a layout independent way.
/// This is very useful for eg: keyboard shortcuts, as user expects to see `Z` when he uses it as shortcut on his keyboard.
///
/// You can directly use [layout_independent_glfw_to_egui_key] to just get the physical key location without caring about logical layout.
/// 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.
/// So, pressing the key at `W` location will always move the character forward, even if it is `Z` according to layout.
#[allow(unused)]
pub fn layout_based_glfw_to_egui_key(key: glfw::Key, scancode: i32) -> Option<Key> {
match key {
#[cfg(target_os = "emscripten")]
return layout_independent_glfw_to_egui_key(key);
#[cfg(not(target_os = "emscripten"))]
return match key {
glfw::Key::Apostrophe
| glfw::Key::Comma
| glfw::Key::Minus
Expand Down Expand Up @@ -719,7 +723,7 @@ pub fn layout_based_glfw_to_egui_key(key: glfw::Key, scancode: i32) -> Option<Ke
name.and_then(|n| egui::Key::from_name(&n))
}
_ => layout_independent_glfw_to_egui_key(key),
}
};
}
/// a function to get the matching egui key event for a given glfw key. egui does not support all the keys provided here.
/// This just matches the enum to map to the relevant egui key.
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ pub trait EguiOverlay {
}
}

pub struct OverlayApp<T: EguiOverlay> {
pub struct OverlayApp<T: EguiOverlay + 'static> {
pub user_data: T,
pub egui_context: Context,
pub default_gfx_backend: DefaultGfxBackend,
pub glfw_backend: GlfwBackend,
}

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

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

#[cfg(not(target_os = "emscripten"))]
{
Expand Down

0 comments on commit e669fce

Please sign in to comment.