cli/pkg/display/window.go
Snider 4e02d5bc97 refactor: bring external packages home and restructure
- Imported packages from separate repos:
  - github.com/Snider/config -> pkg/config
  - github.com/Snider/display -> pkg/display
  - github.com/Snider/help -> pkg/help
  - github.com/Snider/i18n -> pkg/i18n
  - github.com/Snider/updater -> pkg/updater
- Moved core code from root to pkg/core
- Flattened nested package structures
- Updated all import paths to github.com/Snider/Core/pkg/*
- Added Display interface to Core
- Updated go.work for workspace modules

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 15:30:43 +00:00

111 lines
3 KiB
Go

package display
import "github.com/wailsapp/wails/v3/pkg/application"
// WindowConfig holds the configuration for a window. This struct is used to
// create a new window with the specified options.
type WindowConfig struct {
Name string
Title string
Width int
Height int
URL string
AlwaysOnTop bool
Hidden bool
MinimiseButtonState application.ButtonState
MaximiseButtonState application.ButtonState
CloseButtonState application.ButtonState
Frameless bool
}
// WindowOption is an interface for applying configuration options to a
// WindowConfig.
type WindowOption interface {
Apply(*WindowConfig)
}
// WindowOptionFunc is a function that implements the WindowOption interface.
// This allows us to use ordinary functions as window options.
type WindowOptionFunc func(*WindowConfig)
// Apply calls the underlying function to apply the configuration.
func (f WindowOptionFunc) Apply(c *WindowConfig) {
f(c)
}
// WithName sets the name of the window.
func WithName(name string) WindowOption {
return WindowOptionFunc(func(c *WindowConfig) {
c.Name = name
})
}
// WithTitle sets the title of the window.
func WithTitle(title string) WindowOption {
return WindowOptionFunc(func(c *WindowConfig) {
c.Title = title
})
}
// WithWidth sets the width of the window.
func WithWidth(width int) WindowOption {
return WindowOptionFunc(func(c *WindowConfig) {
c.Width = width
})
}
// WithHeight sets the height of the window.
func WithHeight(height int) WindowOption {
return WindowOptionFunc(func(c *WindowConfig) {
c.Height = height
})
}
// WithURL sets the URL that the window will load.
func WithURL(url string) WindowOption {
return WindowOptionFunc(func(c *WindowConfig) {
c.URL = url
})
}
// WithAlwaysOnTop sets the window to always be on top of other windows.
func WithAlwaysOnTop(alwaysOnTop bool) WindowOption {
return WindowOptionFunc(func(c *WindowConfig) {
c.AlwaysOnTop = alwaysOnTop
})
}
// WithHidden sets the window to be hidden when it is created.
func WithHidden(hidden bool) WindowOption {
return WindowOptionFunc(func(c *WindowConfig) {
c.Hidden = hidden
})
}
// WithMinimiseButtonState sets the state of the minimise button.
func WithMinimiseButtonState(state application.ButtonState) WindowOption {
return WindowOptionFunc(func(c *WindowConfig) {
c.MinimiseButtonState = state
})
}
// WithMaximiseButtonState sets the state of the maximise button.
func WithMaximiseButtonState(state application.ButtonState) WindowOption {
return WindowOptionFunc(func(c *WindowConfig) {
c.MaximiseButtonState = state
})
}
// WithCloseButtonState sets the state of the close button.
func WithCloseButtonState(state application.ButtonState) WindowOption {
return WindowOptionFunc(func(c *WindowConfig) {
c.CloseButtonState = state
})
}
// WithFrameless sets the window to be frameless.
func WithFrameless(frameless bool) WindowOption {
return WindowOptionFunc(func(c *WindowConfig) {
c.Frameless = frameless
})
}