From 69c4e6ea28feb4bb1064fa4646697290dc956524 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Thu, 24 Sep 2020 21:43:37 +1000 Subject: [PATCH] Min/Max size supported --- v2/internal/ffenestri/ffenestri_darwin.c | 37 ++++++++++++------------ v2/test/minmax/main.go | 12 ++++---- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/v2/internal/ffenestri/ffenestri_darwin.c b/v2/internal/ffenestri/ffenestri_darwin.c index 9fca02cbf..d038fce6e 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.c +++ b/v2/internal/ffenestri/ffenestri_darwin.c @@ -321,24 +321,6 @@ void Center(struct Application *app) { ) } -void SetMaximumSize(void *appPointer, int width, int height) { - Debug("SetMaximumSize Called"); - // struct Application *app = (struct Application*) appPointer; - // GdkGeometry size; - // size.max_height = (height == 0 ? INT_MAX: height); - // size.max_width = (width == 0 ? INT_MAX: width); - // gtk_window_set_geometry_hints(app->mainWindow, NULL, &size, GDK_HINT_MAX_SIZE); -} - -void SetMinimumSize(void *appPointer, int width, int height) { - Debug("SetMinimumSize Called"); - // struct Application *app = (struct Application*) appPointer; - // GdkGeometry size; - // size.max_height = height; - // size.max_width = width; - // gtk_window_set_geometry_hints(app->mainWindow, NULL, &size, GDK_HINT_MIN_SIZE); -} - void ToggleMaximise(struct Application *app) { ON_MAIN_THREAD( app->maximised = !app->maximised; @@ -682,6 +664,18 @@ void disableBoolConfig(id config, const char *setting) { msg(msg(config, s("preferences")), s("setValue:forKey:"), msg(c("NSNumber"), s("numberWithBool:"), 0), str(setting)); } +void setMinMaxSize(struct Application *app) +{ + if (app->maxHeight > 0 && app->maxWidth > 0) + { + msg(app->mainWindow, s("setMaxSize:"), CGSizeMake(app->maxWidth, app->maxHeight)); + } + if (app->minHeight > 0 && app->minWidth > 0) + { + msg(app->mainWindow, s("setMinSize:"), CGSizeMake(app->minWidth, app->minHeight)); + } +} + void Run(void *applicationPointer, int argc, char **argv) { struct Application *app = (struct Application*) applicationPointer; @@ -800,7 +794,12 @@ void Run(void *applicationPointer, int argc, char **argv) { } - + // Fix up resizing + if (app->resizable == 0) { + app->minHeight = app->maxHeight = app->height; + app->minWidth = app->maxWidth = app->width; + } + setMinMaxSize(app); // msg(mainWindow, s("setFrame:display:animate:"), CGRectMake(0, 0, 0, 0), YES, YES); // // Set the icon diff --git a/v2/test/minmax/main.go b/v2/test/minmax/main.go index 4c00f3e69..0bdadf0a7 100644 --- a/v2/test/minmax/main.go +++ b/v2/test/minmax/main.go @@ -10,12 +10,12 @@ func main() { // Create application with options app := wails.CreateAppWithOptions(&options.App{ Title: "minmax", - Width: 1024, - Height: 768, - MinWidth: 800, - MinHeight: 600, - MaxWidth: 1280, - MaxHeight: 1024, + Width: 800, + Height: 600, + MinWidth: 400, + MinHeight: 300, + MaxWidth: 1024, + MaxHeight: 768, }) app.Bind(newBasic())