functora-egui 0.2.0

shadcn/ui-inspired widget library for egui - buttons, inputs, selects, dialogs, and 70+ more components with light/dark theming
Documentation
use crate::responsive::breakpoint::Breakpoint;

#[cfg(target_arch = "wasm32")]
#[must_use]
pub fn startup_width(cc: &eframe::CreationContext<'_>) -> f32 {
    web_sys::window()
        .and_then(|win| {
            win.visual_viewport()
                .map(|vp| crate::utils::f64_to_f32(vp.width()))
                .or_else(|| {
                    win.inner_width()
                        .ok()
                        .and_then(|v| v.as_f64())
                        .map(crate::utils::f64_to_f32)
                })
        })
        .unwrap_or_else(|| cc.egui_ctx.input(|input| input.viewport_rect().width()))
}

#[cfg(not(target_arch = "wasm32"))]
#[must_use]
pub fn startup_width(ctx: &egui::Context) -> f32 {
    ctx.input(|input| input.viewport_rect().width())
}

#[cfg(target_arch = "wasm32")]
#[must_use]
pub fn is_mobile_initial(cc: &eframe::CreationContext<'_>) -> bool {
    let width = startup_width(cc);
    if width == 0.0 {
        true
    } else {
        width < Breakpoint::MOBILE_MAX_WIDTH
    }
}

#[cfg(not(target_arch = "wasm32"))]
#[must_use]
pub fn is_mobile_initial_ctx(ctx: &egui::Context) -> bool {
    let width = startup_width(ctx);
    if width == 0.0 {
        true
    } else {
        width < Breakpoint::MOBILE_MAX_WIDTH
    }
}

#[must_use]
pub fn is_mobile(ctx: &egui::Context) -> bool {
    crate::responsive::responsive_ext::ResponsiveExt::on_mobile(ctx)
}