Remove global context

This commit is contained in:
meehl committed 2025-10-27 23:10:11 +01:00
1 parent f3d2f73925
commit d8e52218f8
25 files changed
+1607 -1036

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
use std::sync::Arc;
use winit::window::Window;
use crate::dpi::{ConvertToLogical, LogicalSize, PhysicalSize};
pub struct WindowState {
pub window: Option<Arc<Window>>,
pub size: PhysicalSize<u32>,
pub scale_factor: f32,
pending_window_title: std::cell::Cell<Option<String>>,
}
impl Default for WindowState {
fn default() -> Self {
Self {
window: None,
size: Default::default(),
scale_factor: 1.0,
pending_window_title: std::cell::Cell::new(None),
}
}
}
impl WindowState {
pub fn set_window(&mut self, window: Arc<Window>) {
if let Some(title) = self.pending_window_title.take() {
window.set_title(&title);
}
self.window = Some(window);
}
pub fn set_window_title(&self, title: &str) {
if let Some(ref window) = self.window {
window.set_title(title);
} else {
self.pending_window_title.set(Some(title.to_string()));
}
}
pub fn logical_size(&self) -> LogicalSize<u32> {
self.size.to_logical(self.scale_factor)
}
}