diff --git a/src/browser_window.rs b/src/browser_window.rs index 1bbc8a3..ef6cdd9 100644 --- a/src/browser_window.rs +++ b/src/browser_window.rs @@ -8,8 +8,8 @@ use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; use std::rc::Rc; use std::sync::Arc; -use winit::{ - dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize}, +use tao::{ + dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Size}, event_loop::EventLoop, window::{ CursorIcon, Fullscreen, Icon, Window, WindowBuilder, WindowButtons, WindowId, WindowLevel, @@ -531,6 +531,45 @@ impl BrowserWindow { } #[napi] + /// Sets the minimum inner size (width and height) for the window. + /// Pass `0` for both width and height to remove the constraint. + pub fn set_min_size(&self, width: u32, height: u32, logical: Option) { + if width == 0 && height == 0 { + self.window.set_min_inner_size(None::); + } else { + if let Some(logical) = logical { + if logical { + self.window.set_min_inner_size(Some(LogicalSize::new(width, height))); + } else { + self.window.set_min_inner_size(Some(PhysicalSize::new(width, height))); + } + } else { + self.window.set_min_inner_size(Some(PhysicalSize::new(width, height))); + } + } + } + + #[napi] + /// Sets the maximum inner size (width and height) for the window. + /// Pass `0` for both width and height to remove the constraint. + pub fn set_max_size(&self, width: u32, height: u32, logical: Option) { + if width == 0 && height == 0 { + self.window.set_max_inner_size(None::); + } else { + if let Some(logical) = logical { + if logical { + self.window.set_max_inner_size(Some(LogicalSize::new(width, height))); + } else { + self.window.set_max_inner_size(Some(PhysicalSize::new(width, height))); + } + } else { + self.window.set_max_inner_size(Some(PhysicalSize::new(width, height))); + } + } + } + + #[napi] + /// Gets the window ID. pub fn id(&self) -> u32 { self.window_id }