diff --git a/Cargo.lock b/Cargo.lock index 53a96e5..2db9987 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -679,8 +679,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" dependencies = [ "cfg-if 1.0.0", + "js-sys", "libc", "wasi 0.10.2+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 8c655a5..7e57d43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ tracing = "0.1.34" itertools = "0.10.3" static_assertions = "1.1.0" phf = "0.10.1" -uuid = { version = "1.0.0", features = ["v4", "fast-rng"] } +uuid = { version = "1.0.0", features = ["v4", "fast-rng", "js"] } [build-dependencies] diff --git a/TODO.md b/TODO.md index 50f123a..18da588 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,6 @@ 1. Function management - Integrals between functions (too hard to implement, maybe will shelve) - Display intersection between functions (would have to rewrite a lot of the function plotting handling) - - Sort by UUIDs - [Drag and drop support](https://github.com/emilk/egui/discussions/1530) in the UI - Hide/disable functions - Prevent user from making too many function entries diff --git a/src/consts.rs b/src/consts.rs index a93a4c9..7d5677b 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -74,7 +74,8 @@ pub const COLORS: &[Color32; 13] = &[ #[cfg(target_arch = "wasm32")] lazy_static::lazy_static! { - pub static IS_MOBILE: bool = { + static ref IS_MOBILE: bool = { + // from https://github.com/emilk/egui/blob/fda8189cbab18e0acab8db972400e4a4ca0d915e/egui_web/src/text_agent.rs#L194 fn is_mobile() -> Option { const MOBILE_DEVICE: [&str; 6] = ["Android", "iPhone", "iPad", "iPod", "webOS", "BlackBerry"]; @@ -83,8 +84,17 @@ lazy_static::lazy_static! { } is_mobile().unwrap_or_default() - } + }; } #[cfg(not(target_arch = "wasm32"))] -pub const IS_MOBILE: bool = false; +const IS_MOBILE: bool = false; + +#[inline] +pub fn is_mobile() -> bool { + #[cfg(target_arch = "wasm32")] + return *IS_MOBILE; + + #[cfg(not(target_arch = "wasm32"))] + return IS_MOBILE; +} diff --git a/src/function_manager.rs b/src/function_manager.rs index 66d4789..867ab4f 100644 --- a/src/function_manager.rs +++ b/src/function_manager.rs @@ -1,4 +1,4 @@ -use crate::consts::IS_MOBILE; +use crate::consts::is_mobile; use crate::function_entry::{FunctionEntry, DEFAULT_FUNCTION_ENTRY}; use crate::widgets::{move_cursor_to_end, widgets_ontop, Movement}; use egui::{Button, Key, Modifiers}; @@ -76,7 +76,7 @@ impl Manager { function.autocomplete.update_string(&new_string); if !function.autocomplete.hint.is_none() { - if !IS_MOBILE && !function.autocomplete.hint.is_single() { + if !is_mobile() && !function.autocomplete.hint.is_single() { if ui.input().key_pressed(Key::ArrowDown) { movement = Movement::Down; } else if ui.input().key_pressed(Key::ArrowUp) {