Documentation
¶
Overview ¶
Package window provides platform-neutral window, input, and OpenGL context primitives.
The input layer is intentionally command-free. It reports keys, text, modifiers, mouse buttons, cursor movement, scroll wheels, high-resolution scroll deltas, and pinch gestures where the platform exposes them. UI and app layers decide whether those generic events mean pan, zoom, edit, select, or any other command.
Index ¶
- func GetDisplayScale() float32
- type Button
- type ButtonState
- type Clipboard
- type CursorCaptureSupport
- type DockMenuCallback
- type DockMenuItem
- type DockMenuSupport
- type FileDialogSupport
- type FileDialogType
- type InputEvent
- type InputEventType
- type IntegratedTitleBarSupport
- type Key
- type KeyMods
- type KeyState
- type OpenGLShareGroupProvider
- type SharedOpenGLContext
- type SharedOpenGLContextProvider
- type SystemKeyCaptureSupport
- type TitleBarInsets
- type URLEventSupport
- type Window
- type XVisualInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDisplayScale ¶
func GetDisplayScale() float32
GetDisplayScale returns the display scale factor before creating a window. This can be used to calculate the physical window size needed to achieve a desired logical size on HiDPI displays. Returns 1.0 if scale detection is not available or fails.
Types ¶
type ButtonState ¶
type ButtonState int
ButtonState represents the state of a mouse button.
const ( // ButtonStatePressed indicates the button was pressed this frame ButtonStatePressed ButtonState = iota // ButtonStateDown indicates the button is currently down ButtonStateDown // ButtonStateReleased indicates the button was released this frame ButtonStateReleased // ButtonStateUp indicates the button is currently up ButtonStateUp )
func (ButtonState) IsDown ¶
func (bs ButtonState) IsDown() bool
IsDown returns true if the button state indicates the button is currently down.
type Clipboard ¶
type Clipboard interface {
// GetText returns the current text content from the system clipboard.
// Returns an empty string if the clipboard is empty or doesn't contain text.
GetText() string
// SetText copies the given text to the system clipboard.
// Returns an error if the operation fails.
SetText(text string) error
}
Clipboard provides cross-platform clipboard access for text data.
func GetClipboard ¶
func GetClipboard() Clipboard
GetClipboard returns the system clipboard implementation. This function is implemented in platform-specific files.
type CursorCaptureSupport ¶
type CursorCaptureSupport interface {
SetCursorCaptured(captured bool)
}
type DockMenuCallback ¶
type DockMenuCallback func(tag int)
DockMenuCallback is called when a dock menu item is selected
type DockMenuItem ¶
DockMenuItem represents an item in the dock menu (macOS only)
type DockMenuSupport ¶
type DockMenuSupport interface {
// SetDockMenu configures the dock menu items and callback
SetDockMenu(items []DockMenuItem, callback DockMenuCallback)
}
DockMenuSupport is an optional interface that windows can implement to provide dock menu functionality (macOS only)
type FileDialogSupport ¶
type FileDialogSupport interface {
// ShowOpenPanel shows a native open file/directory dialog
// Returns the selected path or empty string if cancelled
ShowOpenPanel(dialogType FileDialogType, allowedExtensions []string) string
}
FileDialogSupport is an optional interface that windows can implement to provide native file dialog functionality
type FileDialogType ¶
type FileDialogType int
FileDialogType specifies what a file dialog should select
const ( FileDialogTypeDirectory FileDialogType = iota FileDialogTypeFile )
type InputEvent ¶
type InputEvent struct {
Type InputEventType
Key Key
Text string
Mods KeyMods
Repeat bool
// Button is meaningful for MouseDown/MouseUp.
// For MouseMove, Button may identify the button associated with a platform
// drag event; otherwise use Window.GetButtonState to inspect active buttons.
Button Button
// ButtonValid reports whether Button was populated for this event. It is
// true for MouseDown/MouseUp and for platform drag MouseMove events.
ButtonValid bool
// MouseX/MouseY are meaningful for MouseDown, MouseUp, and MouseMove events.
// They are in the same backing-pixel coordinate space as Window.Cursor.
MouseX float32
MouseY float32
// MouseDeltaX/MouseDeltaY are meaningful for MouseMove events when the
// platform reports relative movement. They are especially useful while the
// cursor is captured and absolute cursor position no longer changes normally.
MouseDeltaX float32
MouseDeltaY float32
// ScrollX/ScrollY are meaningful for Scroll events. Values are in "wheel ticks"
// where 1.0 corresponds to a standard mouse wheel notch (platform-dependent).
// Existing mouse-wheel callers should continue to use these fields.
ScrollX float32
ScrollY float32
// RawScrollX/RawScrollY are meaningful for Scroll events and preserve the
// platform's high-resolution scroll units where available. On macOS precise
// scrolling devices these are NSEvent scrollingDelta values in logical
// points. On coarse wheel platforms they match ScrollX/ScrollY.
RawScrollX float32
RawScrollY float32
// PreciseScroll reports whether Scroll came from a high-resolution scrolling
// device such as a touchpad. Platforms that cannot distinguish precision
// scrolling leave this false.
PreciseScroll bool
// PinchScale is meaningful for Pinch events. It is a multiplicative scale
// delta for the gesture event; values greater than 1 zoom in and values less
// than 1 zoom out.
PinchScale float32
// PinchDelta is meaningful for Pinch events and carries the raw platform
// magnification delta when available. On macOS this is NSEvent magnification.
PinchDelta float32
}
InputEvent is a raw input event emitted by a platform window backend.
Contract: - Events are queued during Poll() and returned by DrainInputEvents(). - DrainInputEvents() clears the internal queue.
type InputEventType ¶
type InputEventType uint8
InputEventType describes the kind of input event.
const ( InputEventKeyDown InputEventType = iota InputEventKeyUp InputEventFlagsChanged InputEventText InputEventMouseDown InputEventMouseUp InputEventMouseMove InputEventScroll InputEventPinch )
func (InputEventType) String ¶
func (t InputEventType) String() string
type IntegratedTitleBarSupport ¶
type IntegratedTitleBarSupport interface {
SetIntegratedTitleBar(enabled bool) bool
IntegratedTitleBarInsets() TitleBarInsets
BeginWindowDrag() bool
}
IntegratedTitleBarSupport is implemented when Gowin can preserve native window controls while extending the client surface into the title bar. BeginWindowDrag should be called for a primary-button press in an application-defined draggable region.
type Key ¶
type Key int
Key represents a keyboard key.
const ( KeyUnknown Key = iota // Letters KeyA KeyB KeyC KeyD KeyE KeyF KeyG KeyH KeyI KeyJ KeyK KeyL KeyM KeyN KeyO KeyP KeyQ KeyR KeyS KeyT KeyU KeyV KeyW KeyX KeyY KeyZ // Numbers Key0 Key1 Key2 Key3 Key4 Key5 Key6 Key7 Key8 Key9 // Function keys KeyF1 KeyF2 KeyF3 KeyF4 KeyF5 KeyF6 KeyF7 KeyF8 KeyF9 KeyF10 KeyF11 KeyF12 // Modifier keys KeyLeftShift KeyRightShift KeyLeftControl KeyRightControl KeyLeftAlt KeyRightAlt KeyLeftSuper // Windows key on Windows, Command key on macOS KeyRightSuper // Windows key on Windows, Command key on macOS // Special keys KeySpace KeyEnter KeyEscape KeyBackspace KeyDelete KeyTab KeyCapsLock KeyScrollLock KeyNumLock KeyPrintScreen KeyPause // Arrow keys KeyUp KeyDown KeyLeft KeyRight // Navigation keys KeyHome KeyEnd KeyPageUp KeyPageDown KeyInsert // Punctuation and symbols KeyGraveAccent // ` KeyMinus // - KeyEqual // = KeyLeftBracket // [ KeyRightBracket // ] KeyBackslash // \ KeySemicolon // ; KeyApostrophe // ' KeyComma // , KeyPeriod // . KeySlash // / // Numpad keys KeyNumpad0 KeyNumpad1 KeyNumpad2 KeyNumpad3 KeyNumpad4 KeyNumpad5 KeyNumpad6 KeyNumpad7 KeyNumpad8 KeyNumpad9 KeyNumpadDecimal // . KeyNumpadDivide // / KeyNumpadMultiply // * KeyNumpadSubtract // - KeyNumpadAdd // + KeyNumpadEnter KeyNumpadEqual // = )
type KeyState ¶
type KeyState int
KeyState represents the state of a keyboard key.
const ( // KeyStatePressed indicates the key was pressed this frame KeyStatePressed KeyState = iota // KeyStateDown indicates the key is currently down KeyStateDown // KeyStateReleased indicates the key was released this frame KeyStateReleased // KeyStateUp indicates the key is currently up KeyStateUp // KeyStateRepeated indicates the key is being held down (repeated) KeyStateRepeated )
type OpenGLShareGroupProvider ¶
type OpenGLShareGroupProvider interface {
}
OpenGLShareGroupProvider exposes opaque native context and pixel-format tokens that a renderer can use only while creating another context in this window's share group. The tokens are backend-specific and remain owned by the window.
type SharedOpenGLContext ¶
type SharedOpenGLContext interface {
}
SharedOpenGLContext owns an OpenGL context on a dedicated OS thread. Calls to Run are serialized and execute with that context current.
type SharedOpenGLContextProvider ¶
type SharedOpenGLContextProvider interface {
}
SharedOpenGLContextProvider is an optional window capability for creating GL contexts in the window's resource share group.
type SystemKeyCaptureSupport ¶
type SystemKeyCaptureSupport interface {
SetSystemKeyCaptured(captured bool)
}
SystemKeyCaptureSupport lets an application keep operating-system shortcut keys in the focused window instead of handing them to the host desktop.
type TitleBarInsets ¶
TitleBarInsets describes the logical-pixel area reserved for native window controls when application content is extended into the system title bar.
type URLEventSupport ¶
type URLEventSupport interface {
// SetURLHandler sets a callback to receive URLs opened via custom schemes.
// On macOS, this handles Apple Events when the app is already running.
SetURLHandler(handler func(url string))
}
URLEventSupport is an optional interface that windows can implement to receive URL open events (e.g., custom URL schemes on macOS)
type Window ¶
type Window interface {
GL() (gl.OpenGL, error)
Close()
Poll() bool
Swap()
BackingSize() (width, height int)
Cursor() (x, y float32)
Scale() float32
GetKeyState(key Key) KeyState
GetButtonState(button Button) ButtonState
// DrainInputEvents returns queued raw input events since the last call and
// clears the internal queue.
DrainInputEvents() []InputEvent
// TextInput returns the UTF-8 text entered since the last call to TextInput.
// Implementations should buffer text during Poll() and clear the buffer when
// TextInput is called.
TextInput() string
}