Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions src/browser_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<bool>) {
if width == 0 && height == 0 {
self.window.set_min_inner_size(None::<Size>);
} 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<bool>) {
if width == 0 && height == 0 {
self.window.set_max_inner_size(None::<Size>);
} 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
}
Expand Down