diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..adb36c82 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.exe \ No newline at end of file diff --git a/examples/build.bat b/examples/build.bat new file mode 100644 index 00000000..8d772171 --- /dev/null +++ b/examples/build.bat @@ -0,0 +1,17 @@ +@echo off +:: cd every subdirectory and run command go build +for /d %%i in (*) do ( + :: skip img dir + if "%%i"=="img" goto :skip + set lastdir=%%i + cd %%i || goto error + echo Building %%i + go build || goto error + cd .. +) + +exit /b 0 + +:error +echo Error building %lastdir%: %errorlevel% +exit /b %errorlevel% \ No newline at end of file diff --git a/examples/close/close.exe.manifest b/examples/close/close.exe.manifest new file mode 100644 index 00000000..86aa0d39 --- /dev/null +++ b/examples/close/close.exe.manifest @@ -0,0 +1,15 @@ + + + + + + + + + + + PerMonitorV2, PerMonitor + True + + + diff --git a/examples/close/close.go b/examples/close/close.go new file mode 100644 index 00000000..c4ed9996 --- /dev/null +++ b/examples/close/close.go @@ -0,0 +1,67 @@ +// Copyright 2013 The Walk Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/tailscale/walk" + + . "github.com/tailscale/walk/declarative" +) + +func main() { + err := run() + if err != nil { + fmt.Println("Error:", err) + os.Exit(1) + } + fmt.Println("Exited cleanly") + os.Exit(0) +} + +func run() error { + var mw *walk.MainWindow + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + if err := (MainWindow{ + AssignTo: &mw, + Title: "Window Closing Test", + Layout: VBox{Spacing: 2}, + Size: Size{800, 600}, + }.Create()); err != nil { + walk.MsgBox(nil, "Error", fmt.Sprintf("%v", err), walk.MsgBoxIconError) + return fmt.Errorf("creating main window: %w", err) + } + + mw.Closing().Attach(func(canceled *bool, reason walk.CloseReason) { + //walk.MsgBox(nil, "Info", fmt.Sprintf("Closing now (reason %d)", reason), walk.MsgBoxIconInformation) + //check if context is done + if ctx.Err() != nil { + return + } + *canceled = true + fmt.Println("Got close message") + mw.SetTitle("Closing...") + cancel() + }) + + go func() { + <-ctx.Done() + fmt.Println("Doing clean up process...") + time.Sleep(1 * time.Second) + mw.Close() + walk.App().Exit(0) + }() + code := mw.Run() + if code != 0 { + return fmt.Errorf("main window closed with %d", code) + } + return nil +} diff --git a/examples/close/rsrc.syso b/examples/close/rsrc.syso new file mode 100644 index 00000000..61c3644f Binary files /dev/null and b/examples/close/rsrc.syso differ