mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Disable fullscreen button if there are size constraints
This commit is contained in:
parent
f800222781
commit
41779866c4
4 changed files with 85 additions and 50 deletions
|
|
@ -48,73 +48,81 @@ func main() {
|
|||
windowCounter++
|
||||
})
|
||||
|
||||
// Disabled menu item
|
||||
adjustMenu := menu.AddSubmenu("Adjust")
|
||||
adjustMenu.Add("Set Position (0,0)").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.SetPosition(0, 0)
|
||||
})
|
||||
})
|
||||
adjustMenu.Add("Set Position (Random)").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.SetPosition(rand.Intn(1000), rand.Intn(800))
|
||||
})
|
||||
})
|
||||
adjustMenu.Add("Set Size (800,600)").OnClick(func(ctx *application.Context) {
|
||||
sizeMenu := menu.AddSubmenu("Size")
|
||||
sizeMenu.Add("Set Size (800,600)").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.SetSize(800, 600)
|
||||
})
|
||||
})
|
||||
|
||||
adjustMenu.Add("Set Size (Random)").OnClick(func(ctx *application.Context) {
|
||||
sizeMenu.Add("Set Size (Random)").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.SetSize(rand.Intn(800)+200, rand.Intn(600)+200)
|
||||
})
|
||||
})
|
||||
adjustMenu.Add("Set Min Size (200,200)").OnClick(func(ctx *application.Context) {
|
||||
sizeMenu.Add("Set Min Size (200,200)").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.SetMinSize(200, 200)
|
||||
})
|
||||
})
|
||||
adjustMenu.Add("Set Max Size (600,600)").OnClick(func(ctx *application.Context) {
|
||||
sizeMenu.Add("Set Max Size (600,600)").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.SetFullscreenButtonEnabled(false)
|
||||
w.SetMaxSize(600, 600)
|
||||
})
|
||||
})
|
||||
adjustMenu.Add("Reset Min Size").OnClick(func(ctx *application.Context) {
|
||||
sizeMenu.Add("Reset Min Size").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.SetMinSize(0, 0)
|
||||
})
|
||||
})
|
||||
|
||||
adjustMenu.Add("Reset Max Size").OnClick(func(ctx *application.Context) {
|
||||
sizeMenu.Add("Reset Max Size").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.SetMaxSize(0, 0)
|
||||
w.SetFullscreenButtonEnabled(true)
|
||||
})
|
||||
})
|
||||
adjustMenu.Add("Center").OnClick(func(ctx *application.Context) {
|
||||
positionMenu := menu.AddSubmenu("Position")
|
||||
positionMenu.Add("Set Position (0,0)").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.SetPosition(0, 0)
|
||||
})
|
||||
})
|
||||
positionMenu.Add("Set Position (Random)").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.SetPosition(rand.Intn(1000), rand.Intn(800))
|
||||
})
|
||||
})
|
||||
positionMenu.Add("Center").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.Center()
|
||||
})
|
||||
})
|
||||
adjustMenu.Add("Minimise (for 2 secs)").OnClick(func(ctx *application.Context) {
|
||||
stateMenu := menu.AddSubmenu("State")
|
||||
stateMenu.Add("Minimise (for 2 secs)").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.Minimise()
|
||||
time.Sleep(2 * time.Second)
|
||||
w.Restore()
|
||||
})
|
||||
})
|
||||
adjustMenu.Add("Maximise").OnClick(func(ctx *application.Context) {
|
||||
stateMenu.Add("Maximise").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.Maximise()
|
||||
})
|
||||
})
|
||||
adjustMenu.Add("Fullscreen").OnClick(func(ctx *application.Context) {
|
||||
stateMenu.Add("Fullscreen").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.Fullscreen()
|
||||
})
|
||||
})
|
||||
adjustMenu.Add("Restore").OnClick(func(ctx *application.Context) {
|
||||
stateMenu.Add("UnFullscreen").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.UnFullscreen()
|
||||
})
|
||||
})
|
||||
stateMenu.Add("Restore").OnClick(func(ctx *application.Context) {
|
||||
currentWindow(func(w *application.Window) {
|
||||
w.Restore()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ type (
|
|||
isMaximised() bool
|
||||
isFullscreen() bool
|
||||
disableSizeConstraints()
|
||||
setFullscreenButtonEnabled(enabled bool)
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -248,6 +249,14 @@ func (w *Window) Fullscreen() *Window {
|
|||
return w
|
||||
}
|
||||
|
||||
func (w *Window) SetFullscreenButtonEnabled(enabled bool) *Window {
|
||||
w.options.FullscreenButtonEnabled = enabled
|
||||
if w.impl != nil {
|
||||
w.impl.setFullscreenButtonEnabled(enabled)
|
||||
}
|
||||
return w
|
||||
}
|
||||
|
||||
// IsMinimised returns true if the window is minimised
|
||||
func (w *Window) IsMinimised() bool {
|
||||
if w.impl == nil {
|
||||
|
|
@ -474,7 +483,7 @@ func (w *Window) UnMaximise() {
|
|||
if w.impl == nil {
|
||||
return
|
||||
}
|
||||
w.enableConstraints()
|
||||
w.enableSizeConstraints()
|
||||
w.impl.unmaximise()
|
||||
}
|
||||
|
||||
|
|
@ -482,7 +491,7 @@ func (w *Window) UnFullscreen() {
|
|||
if w.impl == nil {
|
||||
return
|
||||
}
|
||||
w.enableConstraints()
|
||||
w.enableSizeConstraints()
|
||||
w.impl.unfullscreen()
|
||||
}
|
||||
|
||||
|
|
@ -503,10 +512,11 @@ func (w *Window) disableSizeConstraints() {
|
|||
if w.impl == nil {
|
||||
return
|
||||
}
|
||||
w.impl.disableSizeConstraints()
|
||||
w.impl.setMinSize(0, 0)
|
||||
w.impl.setMaxSize(0, 0)
|
||||
}
|
||||
|
||||
func (w *Window) enableConstraints() {
|
||||
func (w *Window) enableSizeConstraints() {
|
||||
if w.impl == nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ package application
|
|||
#include <stdlib.h>
|
||||
#include "Cocoa/Cocoa.h"
|
||||
#import <WebKit/WebKit.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
extern void registerListener(unsigned int event);
|
||||
|
||||
|
|
@ -357,9 +358,7 @@ void windowUnFullscreen(void* nsWindow) {
|
|||
if( !windowIsFullscreen(nsWindow) ) {
|
||||
return;
|
||||
}
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[(NSWindow*)nsWindow toggleFullScreen:nil];
|
||||
});
|
||||
windowToggleFullscreen(nsWindow);
|
||||
}
|
||||
|
||||
// restore window to normal size
|
||||
|
|
@ -381,6 +380,17 @@ void windowRestore(void* nsWindow) {
|
|||
});
|
||||
}
|
||||
|
||||
// disable window fullscreen button
|
||||
void setFullscreenButtonEnabled(void* nsWindow, bool enabled) {
|
||||
// Disable fullscreen button on main thread
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Get window
|
||||
NSWindow* window = (NSWindow*)nsWindow;
|
||||
NSButton *fullscreenButton = [window standardWindowButton:NSWindowZoomButton];
|
||||
fullscreenButton.enabled = enabled;
|
||||
});
|
||||
}
|
||||
|
||||
// Set the titlebar style
|
||||
void windowSetTitleBarAppearsTransparent(void* nsWindow, bool transparent) {
|
||||
// Set window titlebar style on main thread
|
||||
|
|
@ -645,6 +655,8 @@ static void windowSetFullScreen(void *window, bool fullscreen) {
|
|||
}
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
NSWindow* nsWindow = (NSWindow*)window;
|
||||
windowSetMaxSize(nsWindow, 0, 0);
|
||||
windowSetMinSize(nsWindow, 0, 0);
|
||||
[nsWindow toggleFullScreen:nil];
|
||||
});
|
||||
}
|
||||
|
|
@ -693,6 +705,10 @@ type macosWindow struct {
|
|||
parent *Window
|
||||
}
|
||||
|
||||
func (w *macosWindow) setFullscreenButtonEnabled(enabled bool) {
|
||||
C.setFullscreenButtonEnabled(w.nsWindow, C.bool(enabled))
|
||||
}
|
||||
|
||||
func (w *macosWindow) disableSizeConstraints() {
|
||||
C.windowDisableSizeConstraints(w.nsWindow)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,26 +16,27 @@ const (
|
|||
|
||||
type Window struct {
|
||||
// Alias is a human-readable name for the window. This can be used to reference the window in the frontend.
|
||||
Alias string
|
||||
Title string
|
||||
Width, Height int
|
||||
AlwaysOnTop bool
|
||||
URL string
|
||||
DisableResize bool
|
||||
Frameless bool
|
||||
MinWidth int
|
||||
MinHeight int
|
||||
MaxWidth int
|
||||
MaxHeight int
|
||||
StartState WindowState
|
||||
Mac *MacWindow
|
||||
BackgroundColour *RGBA
|
||||
Assets Assets
|
||||
HTML string
|
||||
JS string
|
||||
CSS string
|
||||
X int
|
||||
Y int
|
||||
Alias string
|
||||
Title string
|
||||
Width, Height int
|
||||
AlwaysOnTop bool
|
||||
URL string
|
||||
DisableResize bool
|
||||
Frameless bool
|
||||
MinWidth int
|
||||
MinHeight int
|
||||
MaxWidth int
|
||||
MaxHeight int
|
||||
StartState WindowState
|
||||
Mac *MacWindow
|
||||
BackgroundColour *RGBA
|
||||
Assets Assets
|
||||
HTML string
|
||||
JS string
|
||||
CSS string
|
||||
X int
|
||||
Y int
|
||||
FullscreenButtonEnabled bool
|
||||
}
|
||||
|
||||
var WindowDefaults = &Window{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue