start working on better mobile support
This commit is contained in:
parent
61c26001b4
commit
22d1be59f5
@ -101,7 +101,9 @@ impl Default for FunctionEntry {
|
||||
impl FunctionEntry {
|
||||
/// Creates edit box for [`FunctionEntry`] to edit function settings and string.
|
||||
/// Returns whether or not this function was marked for removal.
|
||||
pub fn function_entry(&mut self, ui: &mut egui::Ui, can_remove: bool, i: usize) -> bool {
|
||||
pub fn function_entry(
|
||||
&mut self, ui: &mut egui::Ui, can_remove: bool, i: usize, mobile: bool,
|
||||
) -> bool {
|
||||
let output_string = self.autocomplete.string.clone();
|
||||
self.update_string(&output_string);
|
||||
|
||||
@ -727,6 +729,7 @@ mod tests {
|
||||
do_extrema: false,
|
||||
do_roots: false,
|
||||
plot_width: pixel_width,
|
||||
is_mobile: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate static_assertions;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate static_assertions;
|
||||
|
||||
@ -30,6 +30,14 @@ cfg_if::cfg_if! {
|
||||
// Remove the element
|
||||
loading_element.remove();
|
||||
}
|
||||
|
||||
fn is_mobile() -> Option<bool> {
|
||||
const MOBILE_DEVICE: [&str; 6] = ["Android", "iPhone", "iPad", "iPod", "webOS", "BlackBerry"];
|
||||
|
||||
let user_agent = web_sys::window()?.navigator().user_agent().ok()?;
|
||||
Some(MOBILE_DEVICE.iter().any(|&name| user_agent.contains(name)))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,6 +68,8 @@ pub struct AppSettings {
|
||||
|
||||
/// Stores current plot pixel width
|
||||
pub plot_width: usize,
|
||||
|
||||
pub is_mobile: bool,
|
||||
}
|
||||
|
||||
impl Default for AppSettings {
|
||||
@ -75,6 +85,7 @@ impl Default for AppSettings {
|
||||
do_extrema: true,
|
||||
do_roots: true,
|
||||
plot_width: 0,
|
||||
is_mobile: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,10 +135,19 @@ impl MathApp {
|
||||
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||
let start = instant::Instant::now();
|
||||
|
||||
#[allow(unused_mut)]
|
||||
#[allow(unused_assignments)]
|
||||
let mut mobile = false;
|
||||
|
||||
// Remove loading indicator on wasm
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
stop_loading();
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
mobile = is_mobile().unwrap_or_default();
|
||||
}
|
||||
|
||||
#[cfg(threading)]
|
||||
tracing::info!("Threading: Enabled");
|
||||
|
||||
@ -256,7 +276,10 @@ impl MathApp {
|
||||
dark_mode: true,
|
||||
text: text_data.expect("text.json failed to load"),
|
||||
opened: Opened::default(),
|
||||
settings: AppSettings::default(),
|
||||
settings: AppSettings {
|
||||
is_mobile: mobile,
|
||||
..AppSettings::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -362,7 +385,7 @@ impl MathApp {
|
||||
let mut remove_i: Option<usize> = None;
|
||||
for (i, function) in self.functions.iter_mut().enumerate() {
|
||||
// Entry for a function
|
||||
if function.function_entry(ui, can_remove, i) {
|
||||
if function.function_entry(ui, can_remove, i, self.settings.is_mobile) {
|
||||
remove_i = Some(i);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user