notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit aacc41e4c2c6c7f467c92b8bb6d5858e41dfa18e
parent f9d61615001a626643f9cdf0354eda1eeac2328c
Author: kernelkind <kernelkind@gmail.com>
Date:   Fri,  3 May 2024 13:10:56 -0400

Add flag to emulate mobile during preview

Since the is_mobile check was moved to compile-time instead of runtime
in 0a6a44104131e2ec29286e51a800d05471e1a150, we need a way to override
the check when previewing using the 'mobile' flag.

Signed-off-by: kernelkind <kernelkind@gmail.com>
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
MCargo.toml | 1+
Mpreview | 20+++++++++++++++++++-
Msrc/ui/mod.rs | 6++++++
Msrc/ui_preview/main.rs | 13++++++++-----
4 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -45,6 +45,7 @@ egui_virtual_list = "0.3.0" [features] default = [] +emulate_mobile = [] profiling = ["puffin", "puffin_egui", "eframe/puffin"] [profile.small] diff --git a/preview b/preview @@ -1,2 +1,20 @@ #!/usr/bin/env bash -cargo run --bin ui_preview --release -- "$@" + +MOBILE_FLAG=0 +FILTERED_ARGS=() + +# Loop through the command line arguments +for arg in "$@"; do + if [[ "$arg" == "--mobile" ]]; then + MOBILE_FLAG=1 + else + # Add non '--mobile' arguments to the filtered list + FILTERED_ARGS+=("$arg") + fi +done + +if [[ "$MOBILE_FLAG" -eq 1 ]]; then + cargo run --bin ui_preview --features emulate_mobile --release -- "${FILTERED_ARGS[@]}" +else + cargo run --bin ui_preview --release -- "$@" +fi diff --git a/src/ui/mod.rs b/src/ui/mod.rs @@ -38,7 +38,13 @@ pub fn padding<R>( } #[inline] +#[allow(unreachable_code)] pub fn is_mobile(_ctx: &egui::Context) -> bool { + #[cfg(feature = "emulate_mobile")] + { + return true; + } + #[cfg(any(target_os = "android", target_os = "ios"))] { true diff --git a/src/ui_preview/main.rs b/src/ui_preview/main.rs @@ -54,14 +54,17 @@ macro_rules! previews { #[tokio::main] async fn main() { let mut name: Option<String> = None; + + #[allow(unused_assignments)] + #[allow(unused_mut)] let mut is_mobile = false; + #[cfg(feature = "emulate_mobile")] + { + is_mobile = true + } for arg in env::args() { - if arg == "--mobile" { - is_mobile = true; - } else { - name = Some(arg); - } + name = Some(arg); } let name = if let Some(name) = name {