mirror of https://github.com/emilk/egui.git
Browse Source
* eframe web: Add WebInfo::user_agent * Deprecate `Modifier::ALT_SHIFT` * Add code for formatting Modifiers and Key * Add type KeyboardShortcut * Code cleanup * Add Context::os/set_os to query/set what OS egui believes it is on * Add Fonts::has_glyph(s) * Add helper function for formatting keyboard shortcuts * Faster code * Add way to set a shortcut text on menu buttons * Cleanup * format_keyboard_shortcut -> format_shortcut * Add TODO about supporting more keyboard sumbols * Modifiers::plus * Use the new keyboard shortcuts in emark editor demo * Explain why ALT+SHIFT is a bad modifier combo * Fix doctestpull/2208/head
Emil Ernerfeldt
2 years ago
committed by
GitHub
16 changed files with 571 additions and 82 deletions
@ -0,0 +1,71 @@ |
|||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
|||
pub enum OperatingSystem { |
|||
/// Unknown OS - could be wasm
|
|||
Unknown, |
|||
|
|||
/// Android OS.
|
|||
Android, |
|||
|
|||
/// Apple iPhone OS.
|
|||
IOS, |
|||
|
|||
/// Linux or Unix other than Android.
|
|||
Nix, |
|||
|
|||
/// MacOS.
|
|||
Mac, |
|||
|
|||
/// Windows.
|
|||
Windows, |
|||
} |
|||
|
|||
impl Default for OperatingSystem { |
|||
fn default() -> Self { |
|||
Self::from_target_os() |
|||
} |
|||
} |
|||
|
|||
impl OperatingSystem { |
|||
pub const fn from_target_os() -> Self { |
|||
if cfg!(target_arch = "wasm32") { |
|||
Self::Unknown |
|||
} else if cfg!(target_os = "android") { |
|||
Self::Android |
|||
} else if cfg!(target_os = "ios") { |
|||
Self::IOS |
|||
} else if cfg!(target_os = "macos") { |
|||
Self::Mac |
|||
} else if cfg!(target_os = "windows") { |
|||
Self::Android |
|||
} else if cfg!(target_os = "linux") |
|||
|| cfg!(target_os = "dragonfly") |
|||
|| cfg!(target_os = "freebsd") |
|||
|| cfg!(target_os = "netbsd") |
|||
|| cfg!(target_os = "openbsd") |
|||
{ |
|||
Self::Nix |
|||
} else { |
|||
Self::Unknown |
|||
} |
|||
} |
|||
|
|||
/// Helper: try to guess from the user-agent of a browser.
|
|||
pub fn from_user_agent(user_agent: &str) -> Self { |
|||
if user_agent.contains("Android") { |
|||
Self::Android |
|||
} else if user_agent.contains("like Mac") { |
|||
Self::IOS |
|||
} else if user_agent.contains("Win") { |
|||
Self::Windows |
|||
} else if user_agent.contains("Mac") { |
|||
Self::Mac |
|||
} else if user_agent.contains("Linux") |
|||
|| user_agent.contains("X11") |
|||
|| user_agent.contains("Unix") |
|||
{ |
|||
Self::Nix |
|||
} else { |
|||
Self::Unknown |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue