From a88b3553ba8b38c4e638d55f9113ec89215b2db2 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 30 Oct 2021 10:34:55 +1100 Subject: [PATCH] [mac] Support min/max --- v2/internal/frontend/desktop/darwin/WailsContext.m | 6 +++--- v2/internal/frontend/desktop/darwin/frontend.go | 4 ---- v2/internal/frontend/desktop/darwin/window.go | 13 ++++++++++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/v2/internal/frontend/desktop/darwin/WailsContext.m b/v2/internal/frontend/desktop/darwin/WailsContext.m index bbe26e516..e7d0bab2d 100644 --- a/v2/internal/frontend/desktop/darwin/WailsContext.m +++ b/v2/internal/frontend/desktop/darwin/WailsContext.m @@ -56,7 +56,7 @@ NSSize size = { minWidth, minHeight }; self.minSize = size; - + [self.mainWindow setMinSize:size]; [self adjustWindowSize]; @@ -73,7 +73,7 @@ size.height = maxHeight > 0 ? maxHeight : FLT_MAX; self.maxSize = size; - + [self.mainWindow setMinSize:size]; [self adjustWindowSize]; @@ -90,7 +90,7 @@ if ( currentFrame.size.width < self.minSize.width ) currentFrame.size.width = self.minSize.width; if ( currentFrame.size.height > self.maxSize.height ) currentFrame.size.height = self.maxSize.height; if ( currentFrame.size.height < self.minSize.height ) currentFrame.size.height = self.minSize.height; - + [self.mainWindow setFrame:currentFrame display:TRUE animate:FALSE]; } diff --git a/v2/internal/frontend/desktop/darwin/frontend.go b/v2/internal/frontend/desktop/darwin/frontend.go index 1b4e43b07..7e5c2ff8f 100644 --- a/v2/internal/frontend/desktop/darwin/frontend.go +++ b/v2/internal/frontend/desktop/darwin/frontend.go @@ -66,10 +66,6 @@ func NewFrontend(ctx context.Context, appoptions *options.App, myLogger *logger. bindings: appBindings, dispatcher: dispatcher, ctx: ctx, - minHeight: appoptions.MinHeight, - minWidth: appoptions.MinWidth, - maxHeight: appoptions.MaxHeight, - maxWidth: appoptions.MaxWidth, } // Check if we have been given a directory to serve assets from. diff --git a/v2/internal/frontend/desktop/darwin/window.go b/v2/internal/frontend/desktop/darwin/window.go index a27bebe82..4bd65665d 100644 --- a/v2/internal/frontend/desktop/darwin/window.go +++ b/v2/internal/frontend/desktop/darwin/window.go @@ -73,7 +73,9 @@ func NewWindow(frontendOptions *options.App, debugMode bool) *Window { appearance = c.String(string(mac.Appearance)) } - var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, fullscreen, fullSizeContent, hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, debug) + var context *C.WailsContext = C.Create(title, width, height, frameless, resizable, fullscreen, fullSizeContent, + hideTitleBar, titlebarAppearsTransparent, hideTitle, useToolbar, hideToolbarSeparator, webviewIsTransparent, + alwaysOnTop, hideWindowOnClose, appearance, windowIsTranslucent, debug) // Create menu result := &Window{ @@ -100,6 +102,9 @@ func NewWindow(frontendOptions *options.App, debugMode bool) *Window { result.SetApplicationMenu(frontendOptions.Menu) } + result.SetMinSize(frontendOptions.MinWidth, frontendOptions.MinHeight) + result.SetMaxSize(frontendOptions.MaxWidth, frontendOptions.MaxHeight) + return result } @@ -156,10 +161,16 @@ func (w *Window) UnMinimise() { } func (w *Window) SetMinSize(width int, height int) { + if width == 0 && height == 0 { + return + } C.SetMinSize(w.context, C.int(width), C.int(height)) } func (w *Window) SetMaxSize(width int, height int) { + if width == 0 && height == 0 { + return + } C.SetMaxSize(w.context, C.int(width), C.int(height)) }