Skip to main content

egui_charts/styles/
responsive.rs

1//! Simplified layout context for desktop-only UI.
2//!
3//! Provides a minimal [`LayoutContext`] that captures screen dimensions and
4//! DPI scaling. In this desktop-only build, touch targets default to pointer
5//! (24px) mode.
6
7use egui::Vec2;
8
9/// Simplified layout context for desktop-only applications
10#[derive(Debug, Clone)]
11pub struct LayoutContext {
12    /// Screen size in logical pixels
13    pub screen_size: Vec2,
14    /// Display scale factor (pixels per point)
15    pub scale_factor: f32,
16}
17
18impl LayoutContext {
19    /// Create LayoutContext from egui Context
20    pub fn from_egui(ctx: &egui::Context) -> Self {
21        let screen = ctx.input(|i| i.viewport().outer_rect.unwrap_or(egui::Rect::EVERYTHING));
22        Self {
23            screen_size: screen.size(),
24            scale_factor: ctx.pixels_per_point(),
25        }
26    }
27
28    /// Physical width in pixels
29    pub fn physical_width(&self) -> f32 {
30        self.screen_size.x
31    }
32
33    /// Physical height in pixels
34    pub fn physical_height(&self) -> f32 {
35        self.screen_size.y
36    }
37
38    /// Minimum touch target size (always pointer/desktop value)
39    pub fn min_touch_target(&self) -> f32 {
40        24.0
41    }
42}