Skip to main content

incular_config/
defaults.rs

1//! Framework defaults shared by application, environment, and widget layers.
2//!
3//! Defaults that affect more than one crate live here so a constructor cannot
4//! silently drift from the runtime or another widget family.  Renderer and
5//! design-system policy stays outside this crate: a plain container remains
6//! transparent, while a visible application surface belongs to the root
7//! widget or an ambient theme.
8
9use crate::{Axis, Brightness, Clip, TextDirection};
10use incular_core::{Color, Size};
11
12/// Whether a native application window participates in desktop compositing
13/// with framebuffer alpha.
14///
15/// This is presentation policy, not a paint color. A transparent window may
16/// render fully opaque frames, and an opaque window may still use alpha inside
17/// its render tree for antialiasing, effects, and offscreen composition.
18#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
19pub enum TransparencyMode {
20    #[default]
21    Opaque,
22    Transparent,
23}
24
25impl TransparencyMode {
26    #[must_use]
27    pub const fn is_transparent(self) -> bool {
28        matches!(self, Self::Transparent)
29    }
30}
31
32/// Which side of the content/window relationship owns the logical size.
33///
34/// `Viewport` is the normal application-window model: native window metrics
35/// are authoritative and the root receives tight viewport constraints.
36/// `Content` is intended for compact, content-sized top-level windows: the
37/// initial logical size is the stable minimum content viewport, retained content may
38/// grow beyond it, and the native host follows the measured root layout extent.
39/// Paint-only overflow and transient presentation are not content size.
40#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
41pub enum WindowSizePolicy {
42    #[default]
43    Viewport,
44    Content,
45}
46
47/// Defaults used when an application does not provide window/environment
48/// policy.
49#[derive(Clone, Copy, Debug, PartialEq)]
50pub struct ApplicationDefaults {
51    /// Fallback native window title.
52    pub window_title: &'static str,
53    /// Initial logical window size before native metrics are known.
54    pub initial_window_size: Size,
55    pub window_size_policy: WindowSizePolicy,
56    pub resizable: bool,
57    pub visible: bool,
58    pub decorations: bool,
59    /// How the native host/view participates in operating-system compositing.
60    pub transparency_mode: TransparencyMode,
61    /// Base color underneath the application's rendered scene.
62    ///
63    /// This is independent of [`TransparencyMode`]. A transparent host may use
64    /// an opaque background, and an opaque host may begin from transparent
65    /// scene content before native presentation.
66    pub background_color: Color,
67    pub maximized: bool,
68    /// Neutral environment values used until a platform publishes a snapshot.
69    pub scale_factor: f64,
70    pub text_scale: f32,
71    pub brightness: Brightness,
72    pub text_direction: TextDirection,
73    pub reduced_motion: bool,
74}
75
76impl ApplicationDefaults {
77    /// The framework's stable desktop/application defaults.
78    pub const DEFAULT: Self = Self {
79        window_title: "Incular",
80        initial_window_size: Size {
81            width: 800.0,
82            height: 600.0,
83        },
84        window_size_policy: WindowSizePolicy::Viewport,
85        resizable: true,
86        visible: true,
87        decorations: true,
88        transparency_mode: TransparencyMode::Opaque,
89        background_color: Color::BLACK,
90        maximized: false,
91        scale_factor: 1.0,
92        text_scale: 1.0,
93        brightness: Brightness::Light,
94        text_direction: TextDirection::Ltr,
95        reduced_motion: false,
96    };
97}
98
99impl Default for ApplicationDefaults {
100    fn default() -> Self {
101        Self::DEFAULT
102    }
103}
104
105/// Defaults shared by plain text and sliver-backed widgets.
106#[derive(Clone, Copy, Debug, PartialEq)]
107pub struct WidgetDefaults {
108    /// Font size used by a plain `Text`/`TextStyle` with no ambient override
109    /// (Flutter's `kDefaultFontSize`, 14 logical px).
110    pub text_size: f32,
111    /// Conservative estimate used before a lazy child has been laid out.
112    pub lazy_item_extent: f32,
113    /// Logical pixels materialized before and after a sliver viewport.
114    pub sliver_cache_extent: f32,
115    /// Fallback main-axis extent for an unbounded `SliverFillViewport`.
116    pub sliver_fill_viewport_extent: f32,
117    pub scroll_direction: Axis,
118    pub page_scroll_direction: Axis,
119    pub scroll_clip_behavior: Clip,
120    pub grid_cross_axis_count: usize,
121}
122
123impl WidgetDefaults {
124    /// The framework's stable widget defaults.
125    pub const DEFAULT: Self = Self {
126        text_size: 14.0,
127        lazy_item_extent: 48.0,
128        sliver_cache_extent: 250.0,
129        sliver_fill_viewport_extent: 600.0,
130        scroll_direction: Axis::Vertical,
131        page_scroll_direction: Axis::Horizontal,
132        scroll_clip_behavior: Clip::HardEdge,
133        grid_cross_axis_count: 1,
134    };
135}
136
137impl Default for WidgetDefaults {
138    fn default() -> Self {
139        Self::DEFAULT
140    }
141}