Documentation ¶
Overview ¶
Package goosi provides interfaces for OS-specific GUI hardware for portable two-dimensional graphics and input events.
The App interface provides a top-level, single-instance struct that knows about specific hardware, and can create new Window and Texture objects that are hardware-specific and provide the primary GUI interface. It is always available as goosi.TheApp.
Events are communicated through the Window -- see EventTypes and Event in event.go for all the different types.
The driver package creates the App, via its Main function, which is designed to be called by the program's main function. There can be multiple different drivers, but currently OpenGL on top of the glfw cross-platform library (i.e., the vkos driver) is the only one supported. See internal/*driver for older shiny-based drivers that are completely OS-specific and do not require cgo for Windows and X11 platforms (but do require it for mac). These older drivers are no longer compatible with the current GPU-based 3D rendering system in gi and gi3d.
package gi/gimain provides the Main method used to initialize the oswin driver that implements the goosi interfaces, and start the main event processing loop.
See examples in gi/examples directory for current example code.
Index ¶
- Constants
- Variables
- func AssertCaptureIs(t images.TestingT, filename string)
- func Capture() *image.RGBA
- func CaptureAs(filename string) error
- func HandleRecoverBase(r any)
- func HandleRecoverPanic(r any)
- func LogicalFmPhysicalDPI(logScale, pdpi float32) float32
- func SetLogicalDPIScale(scrnName string, dpiScale float32)
- func WindowFlagsToBool(flags WindowFlags) (dialog, modal, tool, fullscreen bool)
- type App
- type Drawer
- type MainMenu
- type Menu
- type MenuItem
- type NewWindowOptions
- type Platforms
- func (i Platforms) Desc() string
- func (i Platforms) Int64() int64
- func (p Platforms) IsMobile() bool
- func (i Platforms) IsValid() bool
- func (i Platforms) MarshalText() ([]byte, error)
- func (i *Platforms) SetInt64(in int64)
- func (i *Platforms) SetString(s string) error
- func (i Platforms) String() string
- func (i *Platforms) UnmarshalText(text []byte) error
- func (i Platforms) Values() []enums.Enum
- type Screen
- type ScreenOrientation
- func (i ScreenOrientation) Desc() string
- func (i ScreenOrientation) Int64() int64
- func (i ScreenOrientation) IsValid() bool
- func (i ScreenOrientation) MarshalText() ([]byte, error)
- func (i *ScreenOrientation) SetInt64(in int64)
- func (i *ScreenOrientation) SetString(s string) error
- func (i ScreenOrientation) String() string
- func (i *ScreenOrientation) UnmarshalText(text []byte) error
- func (i ScreenOrientation) Values() []enums.Enum
- type VirtualKeyboardTypes
- func (i VirtualKeyboardTypes) Desc() string
- func (i VirtualKeyboardTypes) Int64() int64
- func (i VirtualKeyboardTypes) IsValid() bool
- func (i VirtualKeyboardTypes) MarshalText() ([]byte, error)
- func (i *VirtualKeyboardTypes) SetInt64(in int64)
- func (i *VirtualKeyboardTypes) SetString(s string) error
- func (i VirtualKeyboardTypes) String() string
- func (i *VirtualKeyboardTypes) UnmarshalText(text []byte) error
- func (i VirtualKeyboardTypes) Values() []enums.Enum
- type Window
- type WindowFlags
- func (i WindowFlags) BitIndexString() string
- func (i WindowFlags) Desc() string
- func (i WindowFlags) HasFlag(f enums.BitFlag) bool
- func (i WindowFlags) Int64() int64
- func (i WindowFlags) IsValid() bool
- func (i WindowFlags) MarshalText() ([]byte, error)
- func (i *WindowFlags) SetFlag(on bool, f ...enums.BitFlag)
- func (i *WindowFlags) SetInt64(in int64)
- func (i *WindowFlags) SetString(s string) error
- func (i *WindowFlags) SetStringOr(s string) error
- func (i WindowFlags) String() string
- func (i *WindowFlags) UnmarshalText(text []byte) error
- func (i WindowFlags) Values() []enums.Enum
Constants ¶
const ( // MaxTexturesPerSet is the maximum number of image variables that can be used // in one descriptor set. This value is a lowest common denominator across // platforms. To overcome this limitation, when more Texture vals are allocated, // multiple NDescs are used, setting the and switch // across those -- each such Desc set can hold this many textures. // NValsPer on a Texture var can be set higher and only this many will be // allocated in the descriptor set, with bindings of values wrapping // around across as many such sets as are vals, with a warning if insufficient // numbers are present. MaxTexturesPerSet = 16 // MaxImageLayers is the maximum number of layers per image MaxImageLayers = 128 // FlipY used as named arg for flipping the Y axis of images, etc FlipY = true // NoFlipY used as named arg for not flipping the Y axis of images NoFlipY = false )
const ( // Version is the version of this package being used Version = "v0.0.25" // GitCommit is the commit just before the latest version commit GitCommit = "a02e160" // VersionDate is the date-time of the latest version commit in UTC (in the format 'YYYY-MM-DD HH:MM', which is the Go format '2006-01-02 15:04') VersionDate = "2023-12-26 23:34" )
Variables ¶
var ( // NeedsCapture is whether the app drawer needs to capture its next // frame. End-user code should just use [Capture]. NeedsCapture bool // CaptureImage is a channel that sends the image captured after // setting [NeedsCapture] to true. End-user code should just use // [Capture]. CaptureImage = make(chan *image.RGBA) )
var ( // ZoomFactor is a multiplier on screen LogicalDPI ZoomFactor = float32(1.0) // LogicalDPIScale is the default scaling factor for Logical DPI // as a multiplier on Physical DPI. // Smaller numbers produce smaller font sizes etc. LogicalDPIScale = float32(1.0) // LogicalDPIScales are per-screen name versions of LogicalDPIScale // these can be set from preferences (as in gi/prefs) on a per-screen // basis. LogicalDPIScales map[string]float32 )
var HandleRecover = func(r any) { HandleRecoverBase(r) HandleRecoverPanic(r) }
HandleRecover takes the given value of recover, and, if it is not nil, handles it. The behavior of HandleRecover can be customized by changing it to a custom function, but by default it calls HandleRecoverBase and HandleRecoverPanic, which safely prints a stack trace, saves a crash log, and panics on non-mobile platforms. It is set in gi to a function that does the aforementioned things in addition to creating a GUI error dialog. HandleRecover should be called at the start of every goroutine whenever possible. The correct usage of HandleRecover is:
func myFunc() { defer func() { goosi.HandleRecover(recover()) }() ... }
var InitScreenLogicalDPIFunc func()
InitScreenLogicalDPIFunc is a function that can be set to initialize the screen LogicalDPI values based on user preferences etc. Called just before first window is opened.
Functions ¶
func AssertCaptureIs ¶ added in v0.0.12
AssertCaptureIs asserts that the result of Capture is equivalent to the image stored at the given filename in the testdata directory, with ".png" added to the filename if there is no extension (eg: "button" becomes "testdata/button.png"). If it is not, it fails the test with an error, but continues its execution. If there is no image at the given filename in the testdata directory, it creates the image.
func Capture ¶ added in v0.0.10
Capture tells the app drawer to capture its next frame as an image. Once it gets that image, it returns it. It is currently only supported with the offscreen build tag.
func CaptureAs ¶ added in v0.0.10
CaptureAs is a helper function that saves the result of Capture to the given filename. It automatically logs any error in addition to returning it.
func HandleRecoverBase ¶ added in v0.0.25
func HandleRecoverBase(r any)
HandleRecoverBase is the default base value of HandleRecover. It can be extended to form a different value of HandleRecover. It prints a panic message and a stack trace, using a string-based log method that guarantees that the stack trace will be printed before the program exits. This is needed because, without this, the program may exit before it can print the stack trace on some systems like Android, which makes debugging nearly impossible. It also saves a crash log to [TheApp.GokiDataDir].
func HandleRecoverPanic ¶ added in v0.0.25
func HandleRecoverPanic(r any)
HandleRecoverPanic panics on r if r is non-nil and [TheApp.Platform] is not mobile. This is because panicking screws up logging on mobile, but is necessary for debugging on desktop.
func LogicalFmPhysicalDPI ¶
LogicalFmPhysicalDPI computes the logical DPI used in actual screen scaling based on the given logical DPI scale factor (logScale), and also makes it a multiple of 6 to make normal font sizes look best.
func SetLogicalDPIScale ¶
SetLogicalDPIScale sets the LogicalDPIScale factor for given screen name
func WindowFlagsToBool ¶
func WindowFlagsToBool(flags WindowFlags) (dialog, modal, tool, fullscreen bool)
Types ¶
type App ¶
type App interface { // Platform returns the platform type -- can use this for conditionalizing // behavior in minor, simple ways Platform() Platforms // Name is the overall name of the application -- used for specifying an // application-specific preferences directory, etc Name() string // SetName sets the application name -- defaults to GoGi if not otherwise set SetName(name string) // GetScreens gets the current list of screens GetScreens() // NScreens returns the number of different logical and/or physical // screens managed under this overall screen hardware NScreens() int // Screen returns screen for given screen number, or nil if not a // valid screen number. Screen(n int) *Screen // ScreenByName returns screen for given screen name, or nil if not a // valid screen name. ScreenByName(name string) *Screen // NWindows returns the number of windows open for this app. NWindows() int // Window returns given window in list of windows opened under this screen // -- list is not in any guaranteed order, but typically in order of // creation (see also WindowByName) -- returns nil for invalid index. Window(win int) Window // WindowByName returns given window in list of windows opened under this // screen, by name -- nil if not found. WindowByName(name string) Window // WindowInFocus returns the window currently in focus (receiving keyboard // input) -- could be nil if none are. WindowInFocus() Window // ContextWindow returns the window passed as context for clipboard, cursor, etc calls. ContextWindow() Window // NewWindow returns a new Window for this screen. A nil opts is valid and // means to use the default option values. NewWindow(opts *NewWindowOptions) (Window, error) // RemoveWindow removes the given Window from the app's list of windows. // It does not actually close it; see [Window.Close] for that. RemoveWindow(win Window) // ClipBoard returns the clip.Board handler for the system, // in context of given window, which is optional (can be nil) // but can provide useful context on some systems. ClipBoard(win Window) clip.Board // Cursor returns the cursor.Cursor handler for the system, in context of given window. Cursor(win Window) cursor.Cursor // DataDir returns the OS-specific data directory: Mac: ~/Library, // Linux: ~/.config, Windows: ~/AppData/Roaming DataDir() string // GokiDataDir returns the Goki data directory: [App.DataDir] + "Goki". // It ensures that the directory exists first. GokiDataDir() string // About is an informative message about the app. Can use HTML // formatting, including links. About() string // SetAbout sets the about info. SetAbout(about string) // OpenURL opens the given URL in the user's default browser. On Linux // this requires that xdg-utils package has been installed -- uses // xdg-open command. OpenURL(url string) // OpenFiles returns file names that have been set to be open at startup. OpenFiles() []string // SetQuitReqFunc sets the function that is called whenever there is a // request to quit the app (via a OS or a call to QuitReq() method). That // function can then adjudicate whether and when to actually call Quit. SetQuitReqFunc(fun func()) // SetQuitCleanFunc sets the function that is called whenever app is // actually about to quit (irrevocably) -- can do any necessary // last-minute cleanup here. SetQuitCleanFunc(fun func()) // QuitReq is a quit request, triggered either by OS or user call (e.g., // via Quit menu action) -- calls function previously-registered by // SetQuitReqFunc, which is then solely responsible for actually calling // Quit. QuitReq() // IsQuitting returns true when the app is actually quitting -- it is set // to true just before the QuitClean function is called, and before all // the windows are closed. IsQuitting() bool // QuitClean calls the function setup in SetQuitCleanFunc and does other // app cleanup -- called on way to quitting. QuitClean() // Quit closes all windows and exits the program. Quit() // MainLoop runs the main loop of the app. It should not be // called by end-user code; it is for driver use only. MainLoop() // RunOnMain runs given function on main thread (where main event loop is running) // Some functions (GUI-specific etc) must run on this initial main thread for the // overall app. RunOnMain(f func()) // GoRunOnMain runs given function on main thread and returns immediately // Some functions (GUI-specific etc) must run on this initial main thread for the // overall app. GoRunOnMain(f func()) // SendEmptyEvent sends an empty, blank event to global event processing // system, which has the effect of pushing the system along during cases when // the event loop needs to be "pinged" to get things moving along. // See also similar method on Window. SendEmptyEvent() // ShowVirtualKeyboard shows a virtual keyboard of the given type. // ShowVirtualKeyboard only has an effect on mobile platforms (iOS and Android). ShowVirtualKeyboard(typ VirtualKeyboardTypes) // HideVirtualKeyboard hides the virtual keyboard. // HideVirtualKeyboard only has an effect on mobile platforms (iOS and Android). HideVirtualKeyboard() // IsDark returns whether the system color theme is dark (as oppposed to light) IsDark() bool }
App represents the overall OS GUI hardware, and creates Images, Textures and Windows, appropriate for that hardware / OS, and maintains data about the physical screen(s)
var TheApp App
TheApp is the current goosi App -- only ever one in effect
type Drawer ¶ added in v0.0.10
type Drawer interface { // SetMaxTextures updates the max number of textures for drawing // Must call this prior to doing any allocation of images. SetMaxTextures(maxTextures int) // MaxTextures returns the max number of textures for drawing MaxTextures() int // DestBounds returns the bounds of the render destination DestBounds() image.Rectangle // SetGoImage sets given Go image as a drawing source to given image index, // and layer, used in subsequent Draw methods. // A standard Go image is rendered upright on a standard surface. // Set flipY to true to flip. SetGoImage(idx, layer int, img image.Image, flipY bool) // ConfigImageDefaultFormat configures the draw image at the given index // to fit the default image format specified by the given width, height, // and number of layers. ConfigImageDefaultFormat(idx int, width int, height int, layers int) // SyncImages must be called after images have been updated, to sync // memory up to the GPU. SyncImages() // Scale copies texture at given index and layer to render target, // scaling the region defined by src and sr to the destination // such that sr in src-space is mapped to dr in dst-space. // dr is the destination rectangle // sr is the source region (set to image.ZR zero rect for all), // op is the drawing operation: Src = copy source directly (blit), // Over = alpha blend with existing // flipY = flipY axis when drawing this image Scale(idx, layer int, dr image.Rectangle, sr image.Rectangle, op draw.Op, flipY bool) error // Copy copies texture at given index and layer to render target. // dp is the destination point, // sr is the source region (set to image.ZR zero rect for all), // op is the drawing operation: Src = copy source directly (blit), // Over = alpha blend with existing // flipY = flipY axis when drawing this image Copy(idx, layer int, dp image.Point, sr image.Rectangle, op draw.Op, flipY bool) error // UseTextureSet selects the descriptor set to use -- // choose this based on the bank of 16 // texture values if number of textures > MaxTexturesPerSet. UseTextureSet(descIdx int) // StartDraw starts image drawing rendering process on render target // No images can be added or set after this point. // descIdx is the descriptor set to use -- choose this based on the bank of 16 // texture values if number of textures > MaxTexturesPerSet. StartDraw(descIdx int) // EndDraw ends image drawing rendering process on render target EndDraw() // Surface is the vgpu device being drawn to. // Could be nil on unsupported devices (web). Surface() any }
Drawer is an interface representing a type capable of high-performance rendering to a window surface. It is implemented by *goki.dev/vgpu/v2/vdraw.Drawer and internal web and offscreen drivers.
type MainMenu ¶
type MainMenu interface { // Window returns the window that this menu is attached to. Window() Window // SetWindow sets the window associated with this main menu. SetWindow(win Window) // SetFunc sets the callback function that is called whenever a menu item is selected. SetFunc(fun func(win Window, title string, tag int)) // Triggered is called when a menu item is triggered via OS -- calls // callback function set in SetFunc. Triggered(win Window, title string, tag int) // Menu returns the menu pointer for the main menu associated with window. // only for READ ONLY purposes -- use StartUpdate when starting to update it. Menu() Menu // SetMenu sets the menu as the main menu for the window -- generally call this // in response to a window.FocusEvent, after building the menu SetMenu() // StartUpdate locks the menu pointer for the main menu associated with window. // only for READ ONLY purposes -- use StartUpdate when starting to update it. StartUpdate() Menu // EndUpdate unlocks the current update -- must be matched with StartUpdate EndUpdate(men Menu) // Reset resets all items on given menu -- do this before updating. Reset(men Menu) // AddSubMenu adds a sub-menu of given title / label to given menu. AddSubMenu(men Menu, title string) Menu // AddItem adds a menu item of given title / label, shortcut, and tag to // given menu. Callback function set by SetFunc will be called when menu // item is selected. AddItem(men Menu, title string, shortcut string, tag int, active bool) MenuItem // AddSeparator adds a separator menu item. AddSeparator(men Menu) // ItemByTitle finds menu item by title on given menu -- does not iterate // over sub-menus, so that needs to be done manually. ItemByTitle(men Menu, title string) MenuItem // ItemByTag finds menu item by tag on given menu -- does not iterate // over sub-menus, so that needs to be done manually. ItemByTag(men Menu, tag int) MenuItem // SetItemActive sets the active status of given item. SetItemActive(mitem MenuItem, active bool) }
MainMenu supports the OS-specific main menu associated with a window.
type NewWindowOptions ¶
type NewWindowOptions struct { // Size specifies the dimensions of the new window, either in raw pixels // or std 96 dpi pixels depending on StdPixels. If Width or Height are // zero, a driver-dependent default will be used for each zero value // dimension Size image.Point // StdPixels means use standardized "pixel" units for the window size (96 // per inch), not the actual underlying raw display dot pixels StdPixels bool // Pos specifies the position of the window, if non-zero -- always in // device-specific raw pixels Pos image.Point // Title specifies the window title. Title string // Flags can be set using WindowFlags to request different types of windows Flags WindowFlags }
NewWindowOptions are optional arguments to NewWindow.
func (*NewWindowOptions) Fixup ¶
func (o *NewWindowOptions) Fixup()
Fixup fills in defaults and updates everything based on current screen and window context Specific hardware can fine-tune this as well, in driver code
func (*NewWindowOptions) GetTitle ¶
func (o *NewWindowOptions) GetTitle() string
GetTitle returns a sanitized form of o.Title. In particular, its length will not exceed 4096, and it may be further truncated so that it is valid UTF-8 and will not contain the NUL byte.
o may be nil, in which case "" is returned.
func (*NewWindowOptions) SetDialog ¶
func (o *NewWindowOptions) SetDialog()
func (*NewWindowOptions) SetFullscreen ¶
func (o *NewWindowOptions) SetFullscreen()
func (*NewWindowOptions) SetModal ¶
func (o *NewWindowOptions) SetModal()
func (*NewWindowOptions) SetTool ¶
func (o *NewWindowOptions) SetTool()
type Platforms ¶
type Platforms int32 //enums:enum
Platforms are all the supported platforms for Goosi
const ( // MacOS is a mac desktop machine (aka Darwin) MacOS Platforms = iota // LinuxX11 is a Linux OS machine running X11 window server LinuxX11 // Windows is a Microsoft Windows machine Windows // IOS is an Apple iOS or iPadOS mobile phone or iPad IOS // Android is an Android mobile phone or tablet Android // Web is a web browser running the app through WASM Web // Offscreen is an offscreen driver typically used for testing, // specified using the "offscreen" build tag Offscreen )
const PlatformsN Platforms = 7
PlatformsN is the highest valid value for type Platforms, plus one.
func PlatformsValues ¶
func PlatformsValues() []Platforms
PlatformsValues returns all possible values for the type Platforms.
func (Platforms) IsMobile ¶
IsMobile returns whether the platform is a mobile platform (iOS, Android, Web, or Offscreen). Web and Offscreen are considered mobile platforms because they only supports one window.
func (Platforms) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Platforms) SetString ¶
SetString sets the Platforms value from its string representation, and returns an error if the string is invalid.
func (*Platforms) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Screen ¶
type Screen struct { // ScreenNumber is the index of this screen in the list of screens // maintained under Screen. ScreenNumber int // Geometry contains the geometry of the screen in window manager // size units, which may not be same as raw pixels (dots) Geometry image.Rectangle // DevicePixelRatio is a factor that scales the screen's // "natural" pixel coordinates into actual device pixels. // On OS-X, it is backingScaleFactor = 2.0 on "retina" DevicePixelRatio float32 // PixSize is the number of actual pixels in the screen // (raw display dots), computed as Size * DevicePixelRatio PixSize image.Point // PhysicalSize is the actual physical size of the screen, in mm. PhysicalSize image.Point // LogicalDPI is the logical dots per inch of the screen, // which is used for all rendering. // It is: transient zoom factor * screen-specific multiplier * PhysicalDPI LogicalDPI float32 // PhysicalDPI is the physical dots per inch of the screen, // for generating true-to-physical-size output. // It is computed as 25.4 * (PixSize.X / PhysicalSize.X) // where 25.4 is the number of mm per inch. PhysicalDPI float32 // Color depth of the screen, in bits. Depth int // Refresh rate in Hz RefreshRate float32 Orientation ScreenOrientation NativeOrientation ScreenOrientation PrimaryOrientation ScreenOrientation Name string Manufacturer string Model string SerialNumber string }
Screen contains data about each physical and / or logical screen
func (*Screen) ConstrainWinGeom ¶
ConstrainWinGeom constrains window geometry to fit in the screen. Size is in pixel units.
func (*Screen) UpdateLogicalDPI ¶
func (sc *Screen) UpdateLogicalDPI()
UpdateLogicalDPI updates the logical DPI of the screen based on ZoomFactor and LogicalDPIScale (per screen if exists)
func (*Screen) UpdatePhysicalDPI ¶
func (sc *Screen) UpdatePhysicalDPI()
UpdatePhysicalDPI updates the value of [Screen.PhysicalDPI] based on [Screen.PixSize] and [Screen.PhysicalSize]
func (*Screen) WinSizeFmPix ¶
WinSizeFmPix returns window manager size units (where DevicePixelRatio is ignored) converted from pixel units -- i.e., divide by DevicePixelRatio
type ScreenOrientation ¶
type ScreenOrientation int32 //enums:enum
ScreenOrientation is the orientation of the device screen.
const ( // OrientationUnknown means device orientation cannot be determined. // // Equivalent on Android to Configuration.ORIENTATION_UNKNOWN // and on iOS to: // UIDeviceOrientationUnknown // UIDeviceOrientationFaceUp // UIDeviceOrientationFaceDown OrientationUnknown ScreenOrientation = iota // Portrait is a device oriented so it is tall and thin. // // Equivalent on Android to Configuration.ORIENTATION_PORTRAIT // and on iOS to: // UIDeviceOrientationPortrait // UIDeviceOrientationPortraitUpsideDown Portrait // Landscape is a device oriented so it is short and wide. // // Equivalent on Android to Configuration.ORIENTATION_LANDSCAPE // and on iOS to: // UIDeviceOrientationLandscapeLeft // UIDeviceOrientationLandscapeRight Landscape )
const ScreenOrientationN ScreenOrientation = 3
ScreenOrientationN is the highest valid value for type ScreenOrientation, plus one.
func ScreenOrientationValues ¶
func ScreenOrientationValues() []ScreenOrientation
ScreenOrientationValues returns all possible values for the type ScreenOrientation.
func (ScreenOrientation) Desc ¶
func (i ScreenOrientation) Desc() string
Desc returns the description of the ScreenOrientation value.
func (ScreenOrientation) Int64 ¶
func (i ScreenOrientation) Int64() int64
Int64 returns the ScreenOrientation value as an int64.
func (ScreenOrientation) IsValid ¶
func (i ScreenOrientation) IsValid() bool
IsValid returns whether the value is a valid option for type ScreenOrientation.
func (ScreenOrientation) MarshalText ¶
func (i ScreenOrientation) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (*ScreenOrientation) SetInt64 ¶
func (i *ScreenOrientation) SetInt64(in int64)
SetInt64 sets the ScreenOrientation value from an int64.
func (*ScreenOrientation) SetString ¶
func (i *ScreenOrientation) SetString(s string) error
SetString sets the ScreenOrientation value from its string representation, and returns an error if the string is invalid.
func (ScreenOrientation) String ¶
func (i ScreenOrientation) String() string
String returns the string representation of this ScreenOrientation value.
func (*ScreenOrientation) UnmarshalText ¶
func (i *ScreenOrientation) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (ScreenOrientation) Values ¶
func (i ScreenOrientation) Values() []enums.Enum
Values returns all possible values for the type ScreenOrientation.
type VirtualKeyboardTypes ¶
type VirtualKeyboardTypes int32 //enums:enum
VirtualKeyboardTypes are all of the supported virtual keyboard types for mobile platforms
const ( // DefaultKeyboard is the keyboard with default input style and "return" return key DefaultKeyboard VirtualKeyboardTypes = iota // SingleLineKeyboard is the keyboard with default input style and "Done" return key SingleLineKeyboard // NumberKeyboard is the keyboard with number input style and "Done" return key NumberKeyboard )
const VirtualKeyboardTypesN VirtualKeyboardTypes = 3
VirtualKeyboardTypesN is the highest valid value for type VirtualKeyboardTypes, plus one.
func VirtualKeyboardTypesValues ¶
func VirtualKeyboardTypesValues() []VirtualKeyboardTypes
VirtualKeyboardTypesValues returns all possible values for the type VirtualKeyboardTypes.
func (VirtualKeyboardTypes) Desc ¶
func (i VirtualKeyboardTypes) Desc() string
Desc returns the description of the VirtualKeyboardTypes value.
func (VirtualKeyboardTypes) Int64 ¶
func (i VirtualKeyboardTypes) Int64() int64
Int64 returns the VirtualKeyboardTypes value as an int64.
func (VirtualKeyboardTypes) IsValid ¶
func (i VirtualKeyboardTypes) IsValid() bool
IsValid returns whether the value is a valid option for type VirtualKeyboardTypes.
func (VirtualKeyboardTypes) MarshalText ¶
func (i VirtualKeyboardTypes) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (*VirtualKeyboardTypes) SetInt64 ¶
func (i *VirtualKeyboardTypes) SetInt64(in int64)
SetInt64 sets the VirtualKeyboardTypes value from an int64.
func (*VirtualKeyboardTypes) SetString ¶
func (i *VirtualKeyboardTypes) SetString(s string) error
SetString sets the VirtualKeyboardTypes value from its string representation, and returns an error if the string is invalid.
func (VirtualKeyboardTypes) String ¶
func (i VirtualKeyboardTypes) String() string
String returns the string representation of this VirtualKeyboardTypes value.
func (*VirtualKeyboardTypes) UnmarshalText ¶
func (i *VirtualKeyboardTypes) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (VirtualKeyboardTypes) Values ¶
func (i VirtualKeyboardTypes) Values() []enums.Enum
Values returns all possible values for the type VirtualKeyboardTypes.
type Window ¶
type Window interface { // Name returns the name of the window -- name is used strictly for // internal tracking and finding of windows -- see Title for the displayed // title of the window. Name() string // SetName sets the name of the window. SetName(name string) // Title returns the current title of the window, which is displayed in the GUI. Title() string // SetTitle sets the current title of the window, which is displayed in the GUI. SetTitle(title string) // Size returns the current size of the window, in raw underlying dots / pixels. // This includes any high DPI factors that may not be used in OS window sizing // (see WinSize for that size). Size() image.Point // WinSize returns the current size of the window, in OS-specific window manager // units that may not include any high DPI factors. WinSize() image.Point // Position returns the current left-top position of the window relative to // underlying screen, in OS-specific window manager coordinates. Position() image.Point // Insets returns the size of any insets on the window in raw device pixels (dots). // These insets can be caused by status bars, button overlays, or devices cutouts. Insets() styles.SideFloats // SetWinSize sets the size of the window, in OS-specific window manager // units that may not include any high DPI factors (DevPixRatio) // (i.e., the same units as returned in WinSize()) SetWinSize(sz image.Point) // SetSize sets the size of the window, in actual pixel units // (i.e., the same units as returned by Size()) // Divides by DevPixRatio before calling SetWinSize. SetSize(sz image.Point) // SetPos sets the position of the window, in OS window manager // coordinates, which may be different from Size() coordinates // that reflect high DPI SetPos(pos image.Point) // SetGeom sets the position and size in one call -- use this if doing // both because sequential calls to SetPos and SetSize might fail on some // platforms. Size is in actual pixel units (i.e., same units as returned by Size()), // and Pos is in OS-specific window manager units (i.e., as returned in Pos()) SetGeom(pos image.Point, sz image.Point) // Raise requests that the window be at the top of the stack of windows, // and receive focus. If it is iconified, it will be de-iconified. This // is the only supported mechanism for de-iconifying. Raise() // Minimize requests that the window be iconified, making it no longer // visible or active -- rendering should not occur for minimized windows. Minimize() // PhysicalDPI is the physical dots per inch of the window, for generating // true-to-physical-size output, for example -- see the gi/units package for // translating into various other units. PhysicalDPI() float32 // LogicalDPI returns the current logical dots-per-inch resolution of the // window, which should be used for most conversion of standard units -- // physical DPI can be found in the Screen. LogicalDPI() float32 // SetLogicalDPI sets the current logical dots-per-inch resolution of the // window, which should be used for most conversion of standard units -- // physical DPI can be found in the Screen. SetLogicalDPI(dpi float32) // Screen returns the screen for this window, with all the relevant // information about its properties. Screen() *Screen // MainMenu returns the OS-level main menu for this window -- this is // currently for MacOS only -- returns nil for others. MainMenu() MainMenu // Flags returns the bit flags for this window's properties set according // to WindowFlags bits. Flags() WindowFlags // Is returns whether the window has the given flag. Is(flag WindowFlags) bool // IsClosed returns true if this window has been closed (but some threads // may have not received the news yet) IsClosed() bool // IsVisible returns true if this window is not closed or minimized and // there are active screens IsVisible() bool // SetCloseReqFunc sets the function that is called whenever there is a // request to close the window (via a OS or a call to CloseReq() method). That // function can then adjudicate whether and when to actually call Close. SetCloseReqFunc(fun func(win Window)) // SetCloseCleanFunc sets the function that is called whenever window is // actually about to close (irrevocably) -- can do any necessary // last-minute cleanup here. SetCloseCleanFunc(fun func(win Window)) // CloseReq is a close request, triggered either by OS or user call (e.g., // via Close menu action) -- calls function previously-registered by // SetCloseReqFunc, which is then solely responsible for actually calling // Close. CloseReq() // CloseClean calls the function setup in SetCloseCleanFunc and does other // window cleanup -- called on way to closing. CloseClean() // Close requests that the window be closed. The behavior of the Window // after this, whether calling its methods or passing it as an argument, // is undefined. See App.Quit methods to quit overall app. Close() // RunOnWin runs given function on the window's own separate goroutine RunOnWin(f func()) // GoRunOnWin runs given function on the window's unique locked thread // and returns immediately. GoRunOnWin(f func()) // Handle returns the driver-specific handle for this window. // This is only provided for unforeseen emergency backup use; // please file an issue for anything that should be added to the // Window interface. If you need access to some OS API, somebody // else probably does too. // // The return value of Handle is not guaranteed to be consistent // across versions, and depends on platform-specific APIs that may // receive unpredictable breaking changes. // // The return value of Handle will be of the following types for // the following platforms: // - MacOS: uintptr representing NSWindow* // - LinuxX11: uintptr representing X11Window // - Windows: uintptr representing HWND // - IOS: uintptr representing UIViow // - Android: uintptr representing *C.ANativeWindow // - Web: [js.Value] representing [js.Global] (for which you should just call [js.Global] directly) // - Offscreen: nil Handle() any // Sets the mouse position to given values SetMousePos(x, y float64) // Sets the mouse cursor to be enabled (true by default) or disabled (false). // If disabled, setting raw to true will enable raw mouse movement // which can provide better control in a game environment (not avail on Mac). SetCursorEnabled(enabled, raw bool) // IsCursorEnabled returns true or false if cursor is enabled IsCursorEnabled() bool // Drawer returns the drawing system attached to this window surface. // This is typically used for high-performance rendering to the surface. // Wrap access in Lock() / Unlock() calls. Drawer() Drawer // Lock attempts to grab the overall window Mutex lock // and returns true if the window is still open and ready for business. // Otherwise, it might have been closed and any further use should be // abandoned. Do this before any use of window resources // (eg. rendering to the Drawer). Lock() bool // Unlock unlocks the Mutex. Must be called after Lock() is done. Unlock() // SetDestroyGPUResourcesFunc sets the given function // that will be called on the main thread just prior // to destroying the drawer and surface. SetDestroyGPUResourcesFunc(f func()) // SetFPS sets the frames per second for Paint events that drive // updating of the window at regular intervals. 60 is default. // 0 disables -- no regular Paint events are sent. // This only takes effect prior to opening a new window. SetFPS(fps int) // SetTitleBarIsDark sets whether the color theme of the window // title bar is dark (as opposed to light). SetTitleBarIsDark(isDark bool) // EventMgr returns the events.Mgr for this window, // which manages all of the Event sending. EventMgr() *events.Mgr }
Window is a double-buffered OS-specific hardware window.
It provides basic GPU support functions, and is currently implemented via Vulkan on top of glfw cross-platform window mgmt toolkit (see driver/vkos). using the vgpu framework.
The Window maintains its own vdraw.Drawer drawing system for rendering bitmap images and filled regions onto the window surface.
The base full-window image should be drawn with a Scale call first, followed by any overlay images such as sprites or direct upload images already on the GPU (e.g., from 3D render frames)
vgpu.MaxTexturesPerSet = 16 to work cross-platform, meaning that a maximum of 16 images per descriptor set can be uploaded and be ready to use in one render pass. gi.Window uses multiple sets to get around this limitation.
type WindowFlags ¶
type WindowFlags int64 //enums:bitflag
WindowFlags contains all the binary properties of a window -- by default with no other relevant flags a window is a main top-level window.
const ( // Dialog indicates that this is a temporary, pop-up window. Dialog WindowFlags = iota // Modal indicates that this dialog window blocks events going to other // windows until it is closed. Modal // Tool indicates that this is a floating tool window that has minimized // window decoration. Tool // Fullscreen indicates a window that occupies the entire screen. Fullscreen // Minimized indicates a window reduced to an icon, or otherwise no longer // visible or active. Otherwise, the window should be assumed to be // visible. Minimized // Focused indicates that the window has the focus. Focused )
const WindowFlagsN WindowFlags = 6
WindowFlagsN is the highest valid value for type WindowFlags, plus one.
func WindowFlagsValues ¶
func WindowFlagsValues() []WindowFlags
WindowFlagsValues returns all possible values for the type WindowFlags.
func (WindowFlags) BitIndexString ¶
func (i WindowFlags) BitIndexString() string
BitIndexString returns the string representation of this WindowFlags value if it is a bit index value (typically an enum constant), and not an actual bit flag value.
func (WindowFlags) Desc ¶
func (i WindowFlags) Desc() string
Desc returns the description of the WindowFlags value.
func (WindowFlags) HasFlag ¶
func (i WindowFlags) HasFlag(f enums.BitFlag) bool
HasFlag returns whether these bit flags have the given bit flag set.
func (WindowFlags) Int64 ¶
func (i WindowFlags) Int64() int64
Int64 returns the WindowFlags value as an int64.
func (WindowFlags) IsValid ¶
func (i WindowFlags) IsValid() bool
IsValid returns whether the value is a valid option for type WindowFlags.
func (WindowFlags) MarshalText ¶
func (i WindowFlags) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (*WindowFlags) SetFlag ¶
func (i *WindowFlags) SetFlag(on bool, f ...enums.BitFlag)
SetFlag sets the value of the given flags in these flags to the given value.
func (*WindowFlags) SetInt64 ¶
func (i *WindowFlags) SetInt64(in int64)
SetInt64 sets the WindowFlags value from an int64.
func (*WindowFlags) SetString ¶
func (i *WindowFlags) SetString(s string) error
SetString sets the WindowFlags value from its string representation, and returns an error if the string is invalid.
func (*WindowFlags) SetStringOr ¶
func (i *WindowFlags) SetStringOr(s string) error
SetStringOr sets the WindowFlags value from its string representation while preserving any bit flags already set, and returns an error if the string is invalid.
func (WindowFlags) String ¶
func (i WindowFlags) String() string
String returns the string representation of this WindowFlags value.
func (*WindowFlags) UnmarshalText ¶
func (i *WindowFlags) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (WindowFlags) Values ¶
func (i WindowFlags) Values() []enums.Enum
Values returns all possible values for the type WindowFlags.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package clip defines the system clipboard for the GoGi GUI system.
|
Package clip defines the system clipboard for the GoGi GUI system. |
Package cursor defines the oswin cursor interface and standard system cursors that are supported across platforms
|
Package cursor defines the oswin cursor interface and standard system cursors that are supported across platforms |
Package driver provides the default driver for accessing a screen.
|
Package driver provides the default driver for accessing a screen. |
base
Package base provides base driver types that platform-specific drivers can extend to implement interfaces defined in package goosi.
|
Package base provides base driver types that platform-specific drivers can extend to implement interfaces defined in package goosi. |
mobile/mobileinit
Package mobileinit contains common initialization logic for mobile platforms that is relevant to both all-Go apps and gobind-based apps.
|
Package mobileinit contains common initialization logic for mobile platforms that is relevant to both all-Go apps and gobind-based apps. |
offscreen
Package offscreen provides placeholder implementations of goosi interfaces to allow for offscreen testing and capturing of apps.
|
Package offscreen provides placeholder implementations of goosi interfaces to allow for offscreen testing and capturing of apps. |
key
Package key defines an event for physical keyboard keys, for the GoGi GUI system.
|
Package key defines an event for physical keyboard keys, for the GoGi GUI system. |
examples
|
|
Package mimedata defines MIME data support used in clipboard and drag-and-drop functions in the GoGi GUI.
|
Package mimedata defines MIME data support used in clipboard and drag-and-drop functions in the GoGi GUI. |