-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WEP] Customise Window Titlebars (#3508)
* Add proposal. Reference Mac implementation * Add windows support. Update proposal. * Update example * Rename Active->Enable,Inactive->Disabled. Ensure window can get controls back after hiding close on windows. Added guide. Updated example. * Add ExStyle option for setting titlebar style. * Fix linux builds * Tidy up
- Loading branch information
1 parent
2baca5d
commit bf9e17a
Showing
12 changed files
with
518 additions
and
90 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
mkdocs-website/docs/en/learn/guides/customising-windows.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Customising Window Controls in Wails | ||
|
||
Wails provides an API to control the appearance and functionality of the controls of a window. | ||
This functionality is available on Windows and macOS, but not on Linux. | ||
|
||
## Setting the Window Button States | ||
|
||
The button states are defined by the `ButtonState` enum: | ||
|
||
```go | ||
type ButtonState int | ||
|
||
const ( | ||
ButtonEnabled ButtonState = 0 | ||
ButtonDisabled ButtonState = 1 | ||
ButtonHidden ButtonState = 2 | ||
) | ||
``` | ||
|
||
- `ButtonEnabled`: The button is enabled and visible. | ||
- `ButtonDisabled`: The button is visible but disabled (grayed out). | ||
- `ButtonHidden`: The button is hidden from the titlebar. | ||
|
||
The button states can be set during window creation or at runtime. | ||
|
||
### Setting Button States During Window Creation | ||
|
||
When creating a new window, you can set the initial state of the buttons using the `WebviewWindowOptions` struct: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/wailsapp/wails/v3/pkg/application" | ||
) | ||
|
||
func main() { | ||
app := application.New(application.Options{ | ||
Name: "My Application", | ||
}) | ||
|
||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ | ||
MinimiseButtonState: application.ButtonHidden, | ||
MaximiseButtonState: application.ButtonDisabled, | ||
CloseButtonState: application.ButtonEnabled, | ||
}) | ||
|
||
app.Run() | ||
} | ||
``` | ||
|
||
In the example above, the minimise button is hidden, the maximise button is inactive (grayed out), and the close button is active. | ||
|
||
### Setting Button States at Runtime | ||
|
||
You can also change the button states at runtime using the following methods on the `Window` interface: | ||
|
||
```go | ||
window.SetMinimiseButtonState(wails.ButtonHidden) | ||
window.SetMaximiseButtonState(wails.ButtonEnabled) | ||
window.SetCloseButtonState(wails.ButtonDisabled) | ||
``` | ||
|
||
### Platform Differences | ||
|
||
The button state functionality behaves slightly differently on Windows and macOS: | ||
|
||
| | Windows | Mac | | ||
|-----------------------|------------------------|------------------------| | ||
| Disable Min/Max/Close | Disables Min/Max/Close | Disables Min/Max/Close | | ||
| Hide Min | Disables Min | Hides Min button | | ||
| Hide Max | Disables Max | Hides Max button | | ||
| Hide Close | Hides all controls | Hides Close | | ||
|
||
Note: On Windows, it is not possible to hide the Min/Max buttons individually. | ||
However, disabling both will hide both of the controls and only show the | ||
close button. | ||
|
||
### Controlling Window Style (Windows) | ||
|
||
To control the style of the titlebar on Windows, you can use the `ExStyle` field in the `WebviewWindowOptions` struct: | ||
|
||
Example: | ||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/wailsapp/wails/v3/pkg/application" | ||
"github.com/wailsapp/wails/v3/pkg/w32" | ||
) | ||
|
||
func main() { | ||
app := application.New(application.Options{ | ||
Name: "My Application", | ||
}) | ||
|
||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ | ||
Windows: application.WindowsWindow{ | ||
ExStyle: w32.WS_EX_TOOLWINDOW | w32.WS_EX_NOREDIRECTIONBITMAP | w32.WS_EX_TOPMOST, | ||
}, | ||
}) | ||
|
||
app.Run() | ||
} | ||
``` | ||
|
||
Other options that affect the Extended Style of a window will be overridden by this setting: | ||
- HiddenOnTaskbar | ||
- AlwaysOnTop | ||
- IgnoreMouseEvents | ||
- BackgroundType |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.