@@ -20,7 +20,7 @@ use tauri_runtime::{
2020 webview:: { DetachedWebview , DownloadEvent , PendingWebview , WebviewIpcHandler } ,
2121 window:: {
2222 CursorIcon , DetachedWindow , DragDropEvent , PendingWindow , RawWindow , WebviewEvent ,
23- WindowBuilder , WindowBuilderBase , WindowEvent , WindowId ,
23+ WindowBuilder , WindowBuilderBase , WindowEvent , WindowId , WindowSizeConstraints ,
2424 } ,
2525 DeviceEventFilter , Error , EventLoopProxy , ExitRequestedEventAction , Icon , ProgressBarState ,
2626 ProgressBarStatus , Result , RunEvent , Runtime , RuntimeHandle , RuntimeInitArgs , UserAttentionType ,
@@ -43,8 +43,8 @@ use wry::WebViewBuilderExtWindows;
4343use tao:: {
4444 dpi:: {
4545 LogicalPosition as TaoLogicalPosition , LogicalSize as TaoLogicalSize ,
46- PhysicalPosition as TaoPhysicalPosition , PhysicalSize as TaoPhysicalSize ,
47- Position as TaoPosition , Size as TaoSize ,
46+ LogicalUnit as ToaLogicalUnit , PhysicalPosition as TaoPhysicalPosition ,
47+ PhysicalSize as TaoPhysicalSize , Position as TaoPosition , Size as TaoSize ,
4848 } ,
4949 event:: { Event , StartCause , WindowEvent as TaoWindowEvent } ,
5050 event_loop:: {
@@ -774,12 +774,22 @@ impl WindowBuilder for WindowBuilderWrapper {
774774 . minimizable ( config. minimizable )
775775 . shadow ( config. shadow ) ;
776776
777- if let ( Some ( min_width) , Some ( min_height) ) = ( config. min_width , config. min_height ) {
778- window = window. min_inner_size ( min_width, min_height) ;
777+ let mut constraints = WindowSizeConstraints :: default ( ) ;
778+
779+ if let Some ( min_width) = config. min_width {
780+ constraints. min_width = Some ( ToaLogicalUnit :: new ( min_width) . into ( ) ) ;
781+ }
782+ if let Some ( min_height) = config. min_height {
783+ constraints. min_height = Some ( ToaLogicalUnit :: new ( min_height) . into ( ) ) ;
784+ }
785+ if let Some ( max_width) = config. max_width {
786+ constraints. max_width = Some ( ToaLogicalUnit :: new ( max_width) . into ( ) ) ;
779787 }
780- if let ( Some ( max_width ) , Some ( max_height) ) = ( config. max_width , config . max_height ) {
781- window = window . max_inner_size ( max_width , max_height) ;
788+ if let Some ( max_height) = config. max_height {
789+ constraints . max_height = Some ( ToaLogicalUnit :: new ( max_height) . into ( ) ) ;
782790 }
791+ window = window. inner_size_constraints ( constraints) ;
792+
783793 if let ( Some ( x) , Some ( y) ) = ( config. x , config. y ) {
784794 window = window. position ( x, y) ;
785795 }
@@ -823,6 +833,16 @@ impl WindowBuilder for WindowBuilderWrapper {
823833 self
824834 }
825835
836+ fn inner_size_constraints ( mut self , constraints : WindowSizeConstraints ) -> Self {
837+ self . inner . window . inner_size_constraints = tao:: window:: WindowSizeConstraints {
838+ min_width : constraints. min_width ,
839+ min_height : constraints. min_height ,
840+ max_width : constraints. max_width ,
841+ max_height : constraints. max_height ,
842+ } ;
843+ self
844+ }
845+
826846 fn resizable ( mut self , resizable : bool ) -> Self {
827847 self . inner = self . inner . with_resizable ( resizable) ;
828848 self
@@ -1144,6 +1164,7 @@ pub enum WindowMessage {
11441164 SetSize ( Size ) ,
11451165 SetMinSize ( Option < Size > ) ,
11461166 SetMaxSize ( Option < Size > ) ,
1167+ SetSizeConstraints ( WindowSizeConstraints ) ,
11471168 SetPosition ( Position ) ,
11481169 SetFullscreen ( bool ) ,
11491170 SetFocus ,
@@ -1850,6 +1871,16 @@ impl<T: UserEvent> WindowDispatch<T> for WryWindowDispatcher<T> {
18501871 )
18511872 }
18521873
1874+ fn set_size_constraints ( & self , constraints : WindowSizeConstraints ) -> Result < ( ) > {
1875+ send_user_message (
1876+ & self . context ,
1877+ Message :: Window (
1878+ self . window_id ,
1879+ WindowMessage :: SetSizeConstraints ( constraints) ,
1880+ ) ,
1881+ )
1882+ }
1883+
18531884 fn set_position ( & self , position : Position ) -> Result < ( ) > {
18541885 send_user_message (
18551886 & self . context ,
@@ -2831,6 +2862,14 @@ fn handle_user_message<T: UserEvent>(
28312862 WindowMessage :: SetMaxSize ( size) => {
28322863 window. set_max_inner_size ( size. map ( |s| SizeWrapper :: from ( s) . 0 ) ) ;
28332864 }
2865+ WindowMessage :: SetSizeConstraints ( constraints) => {
2866+ window. set_inner_size_constraints ( tao:: window:: WindowSizeConstraints {
2867+ min_width : constraints. min_width ,
2868+ min_height : constraints. min_height ,
2869+ max_width : constraints. max_width ,
2870+ max_height : constraints. max_height ,
2871+ } ) ;
2872+ }
28342873 WindowMessage :: SetPosition ( position) => {
28352874 window. set_outer_position ( PositionWrapper :: from ( position) . 0 )
28362875 }
0 commit comments