use std::sync::Arc;
use mgui_core::Rect;
use mgui_shell::{ShellMetrics, WindowShell};
use winit::dpi::{LogicalPosition, LogicalSize};
use winit::window::Window;
#[derive(Clone)]
pub struct DesktopWindow {
window: Arc<Window>,
}
impl DesktopWindow {
pub fn new(window: Arc<Window>) -> Self {
Self { window }
}
pub fn as_winit(&self) -> &Arc<Window> {
&self.window
}
}
impl WindowShell for DesktopWindow {
fn metrics(&self) -> ShellMetrics {
let sf = (self.window.scale_factor() as f32).max(0.01);
let phys = self.window.inner_size();
ShellMetrics::from_physical(phys.width, phys.height, sf)
}
fn request_redraw(&self) {
self.window.request_redraw();
}
fn set_title(&self, title: &str) {
self.window.set_title(title);
}
fn set_visible(&self, visible: bool) {
self.window.set_visible(visible);
}
fn set_ime_allowed(&self, allowed: bool) {
self.window.set_ime_allowed(allowed);
}
fn set_ime_cursor_area(&self, rect: Rect) {
self.window.set_ime_cursor_area(
LogicalPosition::new(rect.x as f64, rect.y as f64),
LogicalSize::new(rect.width.max(0.0) as f64, rect.height.max(0.0) as f64),
);
}
}