From 8ebbfa9767bcb8f8efd43cc1c7d40e9c61f6c461 Mon Sep 17 00:00:00 2001 From: JL710 <76447362+JL710@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:10:30 +0200 Subject: window tasks for setting min and max size --- runtime/src/window.rs | 16 ++++++++++++++++ winit/src/program.rs | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/runtime/src/window.rs b/runtime/src/window.rs index b5c6ee50..598ee491 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -158,6 +158,12 @@ pub enum Action { /// This enables mouse events for the window and stops mouse events /// from being passed to whatever is underneath. DisableMousePassthrough(Id), + + /// Set the minimum inner window size. + SetMinSize(Id, Option), + + /// Set the maximum inner window size. + SetMaxSize(Id, Option), } /// Subscribes to the frames of the window of the running application. @@ -376,6 +382,16 @@ pub fn change_title(id: Id, title: String) -> Task { task::effect(crate::Action::Window(Action::ChangeTitle(id, title))) } +/// Set the inner maximum size of the window. +pub fn set_max_size(id: Id, size: Option) -> Task { + task::effect(crate::Action::Window(Action::SetMaxSize(id, size))) +} + +/// Set the inner minimum size of the window. +pub fn set_min_size(id: Id, size: Option) -> Task { + task::effect(crate::Action::Window(Action::SetMinSize(id, size))) +} + /// Show the [system menu] at cursor position. /// /// [system menu]: https://en.wikipedia.org/wiki/Common_menus_in_Microsoft_Windows#System_menu diff --git a/winit/src/program.rs b/winit/src/program.rs index 052b36b0..58fec9df 100644 --- a/winit/src/program.rs +++ b/winit/src/program.rs @@ -1291,6 +1291,26 @@ fn run_action( ); } } + window::Action::SetMinSize(id, size) => { + if let Some(window) = window_manager.get_mut(id) { + window.raw.set_min_inner_size(size.map(|x| { + winit::dpi::LogicalSize { + width: x.width, + height: x.height, + } + })); + } + } + window::Action::SetMaxSize(id, size) => { + if let Some(window) = window_manager.get_mut(id) { + window.raw.set_max_inner_size(size.map(|x| { + winit::dpi::LogicalSize { + width: x.width, + height: x.height, + } + })); + } + } window::Action::ChangeTitle(id, title) => { if let Some(window) = window_manager.get_mut(id) { window.raw.set_title(&title); -- cgit