1
0
Эх сурвалжийг харах

replace Min Max properties with function

Stano Turza 7 жил өмнө
parent
commit
586e8654f3

+ 2 - 16
src/Avalonia.Controls/Platform/IWindowBaseImpl.cs

@@ -69,22 +69,8 @@ namespace Avalonia.Platform
         /// <summary>
         /// Minimum width of the window.
         /// </summary>
-        double MinWidth { get; set; }
-
-        /// <summary>
-        /// Maximum width of the window.
-        /// </summary>
-        double MaxWidth { get; set; }
-
-        /// <summary>
-        /// Minimum height of the window.
-        /// </summary>
-        double MinHeight { get; set; }
-
-        /// <summary>
-        /// Maximum height of the window.
-        /// </summary>
-        double MaxHeight { get; set; }
+        /// 
+        void SetMinMaxSize(Size minSize, Size maxSize);
 
         /// <summary>
         /// Gets platform specific display information

+ 6 - 8
src/Avalonia.Controls/WindowBase.cs

@@ -47,6 +47,11 @@ namespace Avalonia.Controls
         {
             IsVisibleProperty.OverrideDefaultValue<WindowBase>(false);
             IsVisibleProperty.Changed.AddClassHandler<WindowBase>(x => x.IsVisibleChanged);
+
+            MinWidthProperty.Changed.AddClassHandler<WindowBase>((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size((double)e.NewValue, w.MinHeight), new Size(w.MaxWidth, w.MaxHeight)));
+            MinHeightProperty.Changed.AddClassHandler<WindowBase>((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size(w.MinWidth, (double)e.NewValue), new Size(w.MaxWidth, w.MaxHeight)));
+            MaxWidthProperty.Changed.AddClassHandler<WindowBase>((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size(w.MinWidth, w.MinHeight), new Size((double)e.NewValue, w.MaxHeight)));
+            MaxHeightProperty.Changed.AddClassHandler<WindowBase>((w, e) => w.PlatformImpl?.SetMinMaxSize(new Size(w.MinWidth, w.MinHeight), new Size(w.MaxWidth, (double)e.NewValue)));
         }
 
         public WindowBase(IWindowBaseImpl impl) : this(impl, AvaloniaLocator.Current)
@@ -197,14 +202,7 @@ namespace Avalonia.Controls
         {
             using (BeginAutoSizing())
             {
-                if (PlatformImpl != null)
-                {
-                    PlatformImpl.MinHeight = MinHeight;
-                    PlatformImpl.MaxHeight = MaxHeight;
-                    PlatformImpl.MinWidth = MinWidth;
-                    PlatformImpl.MaxWidth = MaxWidth;
-                    PlatformImpl.Resize(finalSize);
-                }
+                PlatformImpl?.Resize(finalSize);
             }
 
             return base.ArrangeOverride(PlatformImpl?.ClientSize ?? default(Size));

+ 3 - 7
src/Avalonia.DesignerSupport/Remote/PreviewerWindowImpl.cs

@@ -67,13 +67,9 @@ namespace Avalonia.DesignerSupport.Remote
             RenderIfNeeded();
         }
 
-        public double MinWidth { get; set; }
-
-        public double MaxWidth { get; set; }
-
-        public double MinHeight { get; set; }
-
-        public double MaxHeight { get; set; }
+        public void SetMinMaxSize(Size minSize, Size maxSize)
+        {
+        }
 
         public IScreenImpl Screen { get; } = new ScreenStub();
 

+ 3 - 7
src/Avalonia.DesignerSupport/Remote/Stubs.cs

@@ -78,13 +78,9 @@ namespace Avalonia.DesignerSupport.Remote
 
         public IScreenImpl Screen { get; } = new ScreenStub();
 
-        public double MinWidth { get; set; }
-
-        public double MaxWidth { get; set; }
-
-        public double MinHeight { get; set; }
-
-        public double MaxHeight { get; set; }
+        public void SetMinMaxSize(Size minSize, Size maxSize)
+        {
+        }
 
         public void SetTitle(string title)
         {

+ 1 - 1
src/Gtk/Avalonia.Gtk3/Interop/Native.cs

@@ -421,6 +421,7 @@ namespace Avalonia.Gtk3.Interop
         public static D.gdk_window_set_override_redirect GdkWindowSetOverrideRedirect;
         public static D.gtk_widget_set_size_request GtkWindowSetSizeRequest;
         public static D.gtk_window_set_default_size GtkWindowSetDefaultSize;
+        public static D.gtk_window_set_geometry_hints GtkWindowSetGeometryHints;
         public static D.gtk_window_get_position GtkWindowGetPosition;
         public static D.gtk_window_move GtkWindowMove;
         public static D.gtk_file_chooser_dialog_new GtkFileChooserDialogNew;
@@ -503,7 +504,6 @@ namespace Avalonia.Gtk3.Interop
         public static D.cairo_move_to CairoMoveTo;
         public static D.cairo_destroy CairoDestroy;
 
-        public static D.gtk_window_set_geometry_hints GtkWindowSetGeometryHints;
         public const int G_TYPE_OBJECT = 80;
     }
 

+ 12 - 14
src/Gtk/Avalonia.Gtk3/WindowBaseImpl.cs

@@ -341,13 +341,19 @@ namespace Avalonia.Gtk3
             }
         }
 
-        public double MinWidth { get; set; }
-
-        public double MaxWidth { get; set; }
+        public void SetMinMaxSize(Size minSize, Size maxSize)
+        {
+            if (GtkWidget.IsClosed)
+                return;
 
-        public double MinHeight { get; set; }
+            GdkGeometry geometry = new GdkGeometry();
+            geometry.min_width = minSize.Width > 0 ? (int)minSize.Width : -1;
+            geometry.min_height = minSize.Height > 0 ? (int)minSize.Height : -1;
+            geometry.max_width = !Double.IsInfinity(maxSize.Width) && maxSize.Width > 0 ? (int)maxSize.Width : 999999;
+            geometry.max_height = !Double.IsInfinity(maxSize.Height) && maxSize.Height > 0 ? (int)maxSize.Height : 999999;
 
-        public double MaxHeight { get; set; }
+            Native.GtkWindowSetGeometryHints(GtkWidget, IntPtr.Zero, ref geometry, GdkWindowHints.GDK_HINT_MIN_SIZE | GdkWindowHints.GDK_HINT_MAX_SIZE);
+        } 
 
         public IMouseDevice MouseDevice => Gtk3Platform.Mouse;
 
@@ -439,15 +445,7 @@ namespace Avalonia.Gtk3
         {
             if (GtkWidget.IsClosed)
                 return;
-
-            GdkGeometry geometry = new GdkGeometry();
-            geometry.min_width = MinWidth > 0 ? (int)MinWidth : -1;
-            geometry.min_height = MinHeight > 0 ? (int)MinHeight : -1;
-            geometry.max_width = !Double.IsInfinity(MaxWidth) && MaxWidth > 0 ? (int)MaxWidth : 999999;
-            geometry.max_height = !Double.IsInfinity(MaxHeight) && MaxHeight > 0 ? (int)MaxHeight : 999999;
-            
-            Native.GtkWindowSetGeometryHints(GtkWidget, IntPtr.Zero, ref geometry, GdkWindowHints.GDK_HINT_MIN_SIZE | GdkWindowHints.GDK_HINT_MAX_SIZE);                
-
+         
             Native.GtkWindowResize(GtkWidget, (int)value.Width, (int)value.Height);
             if (OverrideRedirect)
             {

+ 3 - 7
src/OSX/Avalonia.MonoMac/WindowBaseImpl.cs

@@ -161,13 +161,9 @@ namespace Avalonia.MonoMac
             Position = pos;
         }
 
-        public double MinWidth { get; set; }
-
-        public double MaxWidth { get; set; }
-
-        public double MinHeight { get; set; }
-
-        public double MaxHeight { get; set; }
+        public void SetMinMaxSize(Size minSize, Size maxSize)
+        {
+        }
 
         public IScreenImpl Screen
         {

+ 16 - 15
src/Windows/Avalonia.Win32/WindowImpl.cs

@@ -35,6 +35,9 @@ namespace Avalonia.Win32
         private WindowState _showWindowState;
         private FramebufferManager _framebuffer;
         private OleDropTarget _dropTarget;
+        private Size _minSize;
+        private Size _maxSize;
+
 #if USE_MANAGED_DRAG
         private readonly ManagedWindowResizeDragHelper _managedDrag;
 #endif
@@ -102,13 +105,11 @@ namespace Avalonia.Win32
             }
         }
 
-        public double MinWidth { get; set; }
-
-        public double MaxWidth { get; set; }
-
-        public double MinHeight { get; set; }
-
-        public double MaxHeight { get; set; }
+        public void SetMinMaxSize(Size minSize, Size maxSize)
+        {
+            _minSize = minSize;
+            _maxSize = maxSize;
+        }
 
         public IScreenImpl Screen
         {
@@ -624,17 +625,17 @@ namespace Avalonia.Win32
 
                     MINMAXINFO mmi = Marshal.PtrToStructure<UnmanagedMethods.MINMAXINFO>(lParam);
 
-                    if  (MinWidth > 0)
-                        mmi.ptMinTrackSize.X = (int)((MinWidth * Scaling) + BorderThickness.Left + BorderThickness.Right);
+                    if  (_minSize.Width > 0)
+                        mmi.ptMinTrackSize.X = (int)((_minSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right);
 
-                    if (MinHeight > 0)
-                        mmi.ptMinTrackSize.Y = (int)((MinHeight * Scaling) + BorderThickness.Top + BorderThickness.Bottom);
+                    if (_minSize.Height > 0)
+                        mmi.ptMinTrackSize.Y = (int)((_minSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom);
 
-                    if (!Double.IsInfinity(MaxWidth) && MaxWidth > 0)
-                        mmi.ptMaxTrackSize.X = (int)((MaxWidth * Scaling) + BorderThickness.Left + BorderThickness.Right);
+                    if (!Double.IsInfinity(_maxSize.Width) && _maxSize.Width > 0)
+                        mmi.ptMaxTrackSize.X = (int)((_maxSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right);
 
-                    if (!Double.IsInfinity(MaxHeight) && MaxHeight > 0)
-                        mmi.ptMaxTrackSize.Y = (int)((MaxHeight * Scaling) + BorderThickness.Top + BorderThickness.Bottom);
+                    if (!Double.IsInfinity(_maxSize.Height) && _maxSize.Height > 0)
+                        mmi.ptMaxTrackSize.Y = (int)((_maxSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom);
 
                     Marshal.StructureToPtr(mmi, lParam, true);
                     return IntPtr.Zero;