-
-
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.
- Loading branch information
1 parent
9a4cb53
commit 260336e
Showing
12 changed files
with
338 additions
and
10 deletions.
There are no files selected for viewing
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,24 @@ | ||
# Window Menu Example | ||
|
||
*** Windows Only *** | ||
|
||
This example demonstrates how to create a window with a menu bar that can be toggled using the window.ToggleMenuBar() method. | ||
|
||
## Features | ||
|
||
- Default menu bar with File, Edit, and Help menus | ||
- F1 key to toggle menu bar visibility | ||
- Simple HTML interface with instructions | ||
|
||
## Running the Example | ||
|
||
```bash | ||
cd v3/examples/window-menu | ||
go run . | ||
``` | ||
|
||
## How it Works | ||
|
||
The example creates a window with a default menu and binds the F10 key to toggle the menu bar's visibility. The menu bar will hide when F10 is pressed and show when F10 is released. | ||
|
||
Note: The menu bar toggling functionality only works on Windows. On other platforms, the F10 key binding will have no effect. |
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,14 @@ | ||
<html> | ||
<head> | ||
<title>Window Menu Demo</title> | ||
<link rel="stylesheet" href="/style.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>About Window Menu Demo</h1> | ||
<p>Press F1 to toggle menu bar visibility</p> | ||
<p>Press F2 to show menu bar</p> | ||
<p>Press F3 to hide menu bar</p> | ||
</div> | ||
</body> | ||
</html> |
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,48 @@ | ||
<html> | ||
<head> | ||
<title>Window Menu Demo</title> | ||
<style> | ||
body { | ||
font-family: system-ui, -apple-system, sans-serif; | ||
margin: 0; | ||
padding: 2rem; | ||
background: #f5f5f5; | ||
color: #333; | ||
} | ||
.container { | ||
max-width: 600px; | ||
margin: 0 auto; | ||
background: white; | ||
padding: 2rem; | ||
border-radius: 8px; | ||
box-shadow: 0 2px 4px rgba(0,0,0,0.1); | ||
} | ||
h1 { | ||
margin-top: 0; | ||
color: #2d2d2d; | ||
} | ||
.key { | ||
background: #e9e9e9; | ||
padding: 2px 8px; | ||
border-radius: 4px; | ||
border: 1px solid #ccc; | ||
font-family: monospace; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Window Menu Demo</h1> | ||
<p>This example demonstrates the menu bar visibility toggle feature.</p> | ||
<p>Press <span class="key">F1</span> to toggle the menu bar.</p> | ||
<p>Press <span class="key">F2</span> to show the menu bar.</p> | ||
<p>Press <span class="key">F3</span> to hide the menu bar.</p> | ||
<p>The menu includes:</p> | ||
<ul> | ||
<li>File menu with Exit option</li> | ||
<li>MenuBar menu with Hide options</li> | ||
<li>Help menu with About</li> | ||
</ul> | ||
</div> | ||
</body> | ||
</html> |
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,26 @@ | ||
body { | ||
font-family: system-ui, -apple-system, sans-serif; | ||
margin: 0; | ||
padding: 2rem; | ||
background: #f5f5f5; | ||
color: #333; | ||
} | ||
.container { | ||
max-width: 600px; | ||
margin: 0 auto; | ||
background: white; | ||
padding: 2rem; | ||
border-radius: 8px; | ||
box-shadow: 0 2px 4px rgba(0,0,0,0.1); | ||
} | ||
h1 { | ||
margin-top: 0; | ||
color: #2d2d2d; | ||
} | ||
.key { | ||
background: #e9e9e9; | ||
padding: 2px 8px; | ||
border-radius: 4px; | ||
border: 1px solid #ccc; | ||
font-family: monospace; | ||
} |
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,64 @@ | ||
package main | ||
|
||
import ( | ||
"embed" | ||
_ "embed" | ||
"github.com/wailsapp/wails/v3/pkg/application" | ||
"log" | ||
) | ||
|
||
//go:embed assets/* | ||
var assets embed.FS | ||
|
||
func main() { | ||
app := application.New(application.Options{ | ||
Name: "Window Menu Demo", | ||
Description: "A demo of menu bar toggling", | ||
Assets: application.AssetOptions{ | ||
Handler: application.BundledAssetFileServer(assets), | ||
}, | ||
}) | ||
|
||
// Create a menu | ||
menu := app.NewMenu() | ||
fileMenu := menu.AddSubmenu("File") | ||
fileMenu.Add("Exit").OnClick(func(ctx *application.Context) { | ||
app.Quit() | ||
}) | ||
|
||
editMenu := menu.AddSubmenu("MenuBar") | ||
editMenu.Add("Hide MenuBar").OnClick(func(ctx *application.Context) { | ||
app.CurrentWindow().HideMenuBar() | ||
}) | ||
|
||
helpMenu := menu.AddSubmenu("Help") | ||
helpMenu.Add("About").OnClick(func(ctx *application.Context) { | ||
app.CurrentWindow().SetURL("/about.html") | ||
}) | ||
|
||
// Create window with menu | ||
app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ | ||
Title: "Window Menu Demo", | ||
Width: 800, | ||
Height: 600, | ||
Windows: application.WindowsWindow{ | ||
Menu: menu, | ||
}, | ||
KeyBindings: map[string]func(window *application.WebviewWindow){ | ||
"F1": func(window *application.WebviewWindow) { | ||
window.ToggleMenuBar() | ||
}, | ||
"F2": func(window *application.WebviewWindow) { | ||
window.ShowMenuBar() | ||
}, | ||
"F3": func(window *application.WebviewWindow) { | ||
window.HideMenuBar() | ||
}, | ||
}, | ||
}) | ||
|
||
err := app.Run() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
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
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.