window

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 19 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DefaultCornerRadius = 10
View Source
const DefaultTargetFPS = 30

Variables

View Source
var (
	// ErrFileDialogUnavailable indicates that the current target has no
	// synchronous native file dialog integration (for example, a browser or
	// mobile build).
	ErrFileDialogUnavailable = errors.New("window: native file dialog is unavailable")
	// ErrFileDialogInvalidOptions indicates an invalid mode or filter.
	ErrFileDialogInvalidOptions = errors.New("window: invalid file dialog options")
)
View Source
var ErrWebViewUnavailable = scene.ErrWebViewUnavailable

ErrWebViewUnavailable is returned when no platform browser implementation is installed for the current target.

Functions

func NewWebViewBackend

func NewWebViewBackend(context *Context) (scene.WebViewBackend, error)

NewWebViewBackend selects a host-provided backend. The built-in adapters live in the optional window/webview package so applications that do not enable WebView do not link platform browser dependencies.

func OpenFile

func OpenFile(options FileDialogOptions) (string, error)

OpenFile opens a native dialog for one file. An empty path means cancellation.

func OpenFileDialog

func OpenFileDialog(options FileDialogOptions) ([]string, error)

OpenFileDialog opens a modal native file dialog without an explicit owner. An empty result means the user cancelled the dialog.

func OpenFiles

func OpenFiles(options FileDialogOptions) ([]string, error)

OpenFiles opens a native dialog that allows multiple files. An empty result means cancellation.

func OpenFolder

func OpenFolder(options FileDialogOptions) (string, error)

OpenFolder opens a native dialog for one folder. An empty path means cancellation.

func RegisterFileDialogBackend

func RegisterFileDialogBackend(backend FileDialogBackend)

RegisterFileDialogBackend installs the optional native file dialog backend. Applications should call this once during startup, before opening a dialog.

func RegisterWebViewBackend

func RegisterWebViewBackend(factory WebViewBackendFactory)

RegisterWebViewBackend installs a host-provided platform backend factory. Passing nil clears the current registration.

func RegisterWebViewBackendIfUnset

func RegisterWebViewBackendIfUnset(factory WebViewBackendFactory) bool

RegisterWebViewBackendIfUnset installs factory only when no backend factory has been registered. Optional built-in adapters use this form so an application-provided factory keeps precedence.

func RegisterX11WebViewBackendIfUnset

func RegisterX11WebViewBackendIfUnset(factory WebViewBackendFactory) bool

RegisterX11WebViewBackendIfUnset installs an embedded Linux backend that requires an X11 parent window. Linux window creation will prefer X11 or XWayland when this registration succeeds.

Types

type Context

type Context struct {
	Height int

	Width int
	// contains filtered or unexported fields
}

func NewContext

func NewContext(width, height int, title string, options Options) *Context

func (*Context) ActivateRender

func (c *Context) ActivateRender()

ActivateRender selects this window's immediate rendering context. Windows share a rendering thread; resource residency and lifetime stay per device.

func (*Context) Canvas2D

func (c *Context) Canvas2D(width, height int) *graphics.Canvas2D

func (*Context) ClipboardText

func (c *Context) ClipboardText() (string, bool)

func (*Context) Cursor added in v0.1.4

func (s *Context) Cursor() input.Cursor

func (*Context) Destroy

func (c *Context) Destroy()

func (*Context) DevicePixelRatio

func (c *Context) DevicePixelRatio() float64

DevicePixelRatio returns the current platform pixel density.

func (*Context) FrameRequested

func (c *Context) FrameRequested() bool

func (*Context) GetLogicalXY

func (c *Context) GetLogicalXY(x, y float64) (float64, float64)

func (*Context) GetViewport

func (c *Context) GetViewport() (int, int)

func (*Context) LoopGame

func (c *Context) LoopGame(f func() (bool, error)) error

func (*Context) Minimize

func (c *Context) Minimize()

func (*Context) MouseCaptured

func (s *Context) MouseCaptured() bool

MouseCaptured reports whether the platform currently owns the mouse lock.

func (*Context) NativeHandle

func (c *Context) NativeHandle() uintptr

NativeHandle returns the native surface identifier when the host needs to embed a platform control. On Wayland this is the wl_surface pointer.

func (*Context) NativeX11Window

func (c *Context) NativeX11Window() uintptr

NativeX11Window returns the X11 parent window used for embedded native controls. It returns zero when the context uses another display backend.

func (*Context) OnCloseRequested

func (s *Context) OnCloseRequested(handler func() bool)

func (*Context) OnFilesDropped

func (c *Context) OnFilesDropped(f func(x, y float64, files []string))

OnFilesDropped registers a callback for files dropped onto the window. Coordinates are in logical viewport units. The files slice is only valid for the duration of the callback and must be copied when retained.

func (*Context) OnKeydown

func (c *Context) OnKeydown(f func(input.KeyCode))

func (*Context) OnKeyup

func (c *Context) OnKeyup(f func(input.KeyCode))

func (*Context) OnMouseDown

func (c *Context) OnMouseDown(f func(x, y float64, button input.MouseButton))

func (*Context) OnMouseMove

func (c *Context) OnMouseMove(f func(x, y float64))

func (*Context) OnMouseUp

func (c *Context) OnMouseUp(f func(x, y float64, button input.MouseButton))

func (*Context) OnMouseWheel

func (c *Context) OnMouseWheel(f func(xoff float64, yoff float64))

func (*Context) OnTextCommand

func (s *Context) OnTextCommand(handler func(input.TextCommand))

func (*Context) OnTextComposition

func (s *Context) OnTextComposition(handler func(input.TextComposition))

func (*Context) OnTextInput

func (s *Context) OnTextInput(handler func(string))

func (*Context) OnTextSelection

func (s *Context) OnTextSelection(handler func(input.TextSelection))

func (*Context) OnTouchEnd

func (c *Context) OnTouchEnd(f func(x, y float64))

func (*Context) OnTouchMove

func (c *Context) OnTouchMove(f func(x, y float64))

func (*Context) OnTouchStart

func (c *Context) OnTouchStart(f func(x, y float64))

func (*Context) OpenFile

func (c *Context) OpenFile(options FileDialogOptions) (string, error)

func (*Context) OpenFileDialog

func (c *Context) OpenFileDialog(options FileDialogOptions) ([]string, error)

OpenFileDialog opens a modal native file dialog owned by the engine window. An empty result means the user cancelled the dialog.

func (*Context) OpenFiles

func (c *Context) OpenFiles(options FileDialogOptions) ([]string, error)

func (*Context) OpenFolder

func (c *Context) OpenFolder(options FileDialogOptions) (string, error)

func (*Context) RequestClose

func (s *Context) RequestClose()

func (*Context) RequestFrame

func (c *Context) RequestFrame()

func (*Context) SetAlwaysOnTop

func (c *Context) SetAlwaysOnTop(enabled bool)

func (*Context) SetBorderVisible

func (c *Context) SetBorderVisible(visible bool)

func (*Context) SetClipboardText

func (c *Context) SetClipboardText(text string) bool

func (*Context) SetCursor added in v0.1.4

func (s *Context) SetCursor(cursor input.Cursor)

SetCursor changes the system pointer on the window thread. Repeated values do not call the platform, so idle frames and text editing do no native work.

func (*Context) SetDecorations

func (c *Context) SetDecorations(mode DecorationMode)

func (*Context) SetIcon

func (c *Context) SetIcon(data []byte) error

func (*Context) SetIconDecoder

func (support *Context) SetIconDecoder(decoder IconDecoder)

SetIconDecoder configures the decoder used by SetIcon.

func (*Context) SetIdleDeadline

func (c *Context) SetIdleDeadline(deadline func() (time.Time, bool))

SetIdleDeadline installs the loop-thread scheduler's next idle deadline. A zero deadline with idle=true means wait until a platform event or Wake.

func (*Context) SetInputRegion

func (c *Context) SetInputRegion(rects []InputRegionRect)

func (*Context) SetMouseCaptured

func (s *Context) SetMouseCaptured(captured bool) bool

SetMouseCaptured hides and locks the mouse for unlimited relative movement. It returns whether the platform accepted the request. Activation may be asynchronous; MouseCaptured reports the actual state. Call on the window thread.

func (*Context) SetResizable

func (c *Context) SetResizable(enabled bool)

func (*Context) SetRoundedCorners

func (c *Context) SetRoundedCorners(enabled bool)

func (*Context) SetShadowVisible

func (c *Context) SetShadowVisible(visible bool)

func (*Context) SetTargetFPS

func (c *Context) SetTargetFPS(fps int)

func (*Context) SetTaskbarVisible

func (c *Context) SetTaskbarVisible(visible bool)

func (*Context) SetTextInputConfig

func (s *Context) SetTextInputConfig(config input.TextInputConfig)

func (*Context) SetTitle

func (c *Context) SetTitle(title string)

func (*Context) SetTitleBarHeight

func (c *Context) SetTitleBarHeight(float64)

func (*Context) SetViewport

func (c *Context) SetViewport(width, height int)

func (*Context) SetViewportMode

func (c *Context) SetViewportMode(mode ViewportMode)

func (*Context) SetVsyncEnabled

func (c *Context) SetVsyncEnabled(enable bool)

func (*Context) StartWindowDrag

func (c *Context) StartWindowDrag()

func (*Context) TakeFrameRequest

func (c *Context) TakeFrameRequest() bool

func (*Context) TakeMouseDelta

func (s *Context) TakeMouseDelta() (float64, float64)

TakeMouseDelta consumes motion accumulated since the last call, in native window coordinates. Absolute cursor movement and capture transitions are excluded.

func (*Context) TextInputConfig

func (s *Context) TextInputConfig() input.TextInputConfig

func (*Context) ToggleFullscreen

func (c *Context) ToggleFullscreen()

func (*Context) ToggleMaximize

func (c *Context) ToggleMaximize()

func (*Context) UsesClientWindowBorder

func (c *Context) UsesClientWindowBorder() bool

UsesClientWindowBorder reports whether custom decorations should render the border in the surface content for consistent X11 and Wayland appearance.

func (*Context) Wake

func (c *Context) Wake()

Wake interrupts native idle waits and is safe to call from other goroutines.

type DecorationMode

type DecorationMode string
const (
	DecorationSystem DecorationMode = "system"
	DecorationNone   DecorationMode = "none"
)

func (DecorationMode) Valid

func (m DecorationMode) Valid() bool

type FileDialogBackend

type FileDialogBackend func(*Context, FileDialogOptions) ([]string, error)

FileDialogBackend is the platform implementation selected by the host project. Keeping it outside this package lets projects that do not use file dialogs avoid linking desktop portal dependencies.

type FileDialogFilter

type FileDialogFilter struct {
	Name       string
	Extensions []string
}

FileDialogFilter describes one group in the native dialog's file type menu. Extensions may be written with or without a leading dot (for example, both "png" and ".png" are accepted).

type FileDialogMode

type FileDialogMode uint8

FileDialogMode controls which kind of entries a native file dialog accepts.

const (
	// FileDialogFiles selects one file.
	FileDialogFiles FileDialogMode = iota
	// FileDialogFolder selects one folder.
	FileDialogFolder
	// FileDialogMultipleFiles selects one or more files.
	FileDialogMultipleFiles
)

type FileDialogOptions

type FileDialogOptions struct {
	Title       string
	DefaultPath string
	Filters     []FileDialogFilter
	// Mode defaults to FileDialogFiles.
	Mode FileDialogMode
}

FileDialogOptions configures OpenFileDialog.

type IconDecoder

type IconDecoder interface {
	DecodeIcon([]byte) (image.Image, error)
}

IconDecoder decodes a window icon selected by an application resource feature. Concrete image formats live outside the window core package.

type InputRegionRect

type InputRegionRect struct {
	X      int
	Y      int
	Width  int
	Height int
}

InputRegionRect describes an interactive rectangle in logical viewport coordinates.

type Options

type Options struct {
	DRMDevice           string
	Decorations         DecorationMode
	RenderScale         float64
	MaxDevicePixelRatio float64
	TitleBarHeight      float64
	// CornerRadius controls renderer-owned window corners in logical pixels.
	// Windows uses alpha composition for radii larger than its native 8 DIP.
	CornerRadius   int
	DRMConnectorID uint32
	Antialias      bool
	Transparent    bool
	Border         bool
	Shadow         bool
	Resizable      bool
}

func DefaultOptions

func DefaultOptions() Options

type ViewportMode

type ViewportMode string
const (
	ViewportModeContain     ViewportMode = "contain"
	ViewportModeCover       ViewportMode = "cover"
	ViewportModeStretch     ViewportMode = "stretch"
	ViewportModeFixedWidth  ViewportMode = "fixed-width"
	ViewportModeFixedHeight ViewportMode = "fixed-height"
	ViewportModeExpand      ViewportMode = "expand"
	ViewportModeAdaptive    ViewportMode = "adaptive"
	ViewportModeInteger     ViewportMode = "integer-scale"
)

type WebViewBackendFactory

type WebViewBackendFactory func(*Context) (scene.WebViewBackend, error)

WebViewBackendFactory allows a host application to provide a native browser backend without changing the ECS protocol. Registration should happen before creating the window context.

Directories

Path Synopsis
codec
png
Package png provides the opt-in PNG window icon decoder.
Package png provides the opt-in PNG window icon decoder.
svg
Package svg provides SVG window icon decoding at a statically selected size.
Package svg provides SVG window icon decoding at a statically selected size.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL