use super::*;
impl Default for DisplayInfo {
fn default() -> Self {
Self::new(
DEFAULT_WINDOW_WIDTH,
DEFAULT_WINDOW_HEIGHT,
1.0,
DEFAULT_REFRESH_RATE_HZ,
ColorSpace::Srgb,
)
}
}
impl Default for WindowConfig {
fn default() -> Self {
Self {
title: DEFAULT_WINDOW_TITLE.to_string(),
width: DEFAULT_WINDOW_WIDTH,
height: DEFAULT_WINDOW_HEIGHT,
min_size: None,
max_size: None,
position: None,
resizable: true,
decorations: true,
transparent: false,
always_on_top: false,
fullscreen: FullscreenMode::Windowed,
immersive: false,
visible: true,
render: RenderConfig::default(),
orientation: OrientationLock::Auto,
status_bar: StatusBarStyle::Auto,
preferred_theme: None,
icon: None,
icon_path: None,
}
}
}
impl SafeAreaInsets {
#[must_use]
pub fn to_edges(&self) -> Edges {
Edges::new(
self.get_top(),
self.get_right(),
self.get_bottom(),
self.get_left(),
)
}
}
impl WindowConfig {
pub fn set_size(&mut self, width: u32, height: u32) -> &mut Self {
self.set_width(width.max(1)).set_height(height.max(1))
}
#[must_use]
pub fn min_size_value(&self) -> Option<(u32, u32)> {
let Self { min_size, .. } = self;
*min_size
}
#[must_use]
pub fn max_size_value(&self) -> Option<(u32, u32)> {
let Self { max_size, .. } = self;
*max_size
}
#[must_use]
pub fn position_value(&self) -> Option<(i32, i32)> {
let Self { position, .. } = self;
*position
}
#[must_use]
pub fn preferred_theme_value(&self) -> Option<ThemeMode> {
let Self {
preferred_theme, ..
} = self;
*preferred_theme
}
#[must_use]
pub fn icon_value(&self) -> Option<ImageBuffer> {
let Self { icon, .. } = self;
icon.clone()
}
#[must_use]
pub fn icon_path_value(&self) -> Option<String> {
let Self { icon_path, .. } = self;
icon_path.clone()
}
}
impl WindowState {
#[must_use]
pub fn from_config(id: WindowId, config: &WindowConfig, scale_factor: f32) -> Self {
let safe_scale: f32 = scale_factor.max(0.5);
let logical_w: f32 = config.get_width().max(1) as f32;
let logical_h: f32 = config.get_height().max(1) as f32;
let phys_w: u32 = ((logical_w * safe_scale).round() as u32).max(1);
let phys_h: u32 = ((logical_h * safe_scale).round() as u32).max(1);
let display: DisplayInfo = DisplayInfo::new(
phys_w,
phys_h,
safe_scale,
DEFAULT_REFRESH_RATE_HZ,
config.get_render().get_color_space(),
);
Self {
id,
logical_width: logical_w,
logical_height: logical_h,
physical_width: phys_w,
physical_height: phys_h,
scale_factor: safe_scale,
safe_area: SafeAreaInsets::default(),
display,
focused: true,
minimized: false,
maximized: false,
fullscreen: config.get_fullscreen(),
system_theme: config.preferred_theme_value().unwrap_or(ThemeMode::Light),
}
}
#[must_use]
pub fn logical_size(&self) -> Size {
Size::new(self.get_logical_width(), self.get_logical_height())
}
#[must_use]
pub fn breakpoint(&self) -> Breakpoint {
Breakpoint::from_width(self.get_logical_width())
}
}