base

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package base provides base driver types that platform-specific drivers can extend to implement interfaces defined in package goosi.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(f func(a goosi.App), a goosi.App, ab *App)

Main is called from main thread when it is time to start running the main loop. When function f returns, the app ends automatically.

This version of Main should be called by platform-specific implementations of Main with their platform-specific app instance and its base App field. Other platform-specific initial configuration steps can be called before this.

Types

type App

type App struct {
	// This is the App as a [goosi.App] interface, which preserves the actual identity
	// of the app when calling interface methods in the base App.
	This goosi.App `view:"-"`

	// Mu is the main mutex protecting access to app operations, including [App.RunOnMain] functions.
	Mu sync.Mutex `view:"-"`

	// MainQueue is the queue of functions to call on the main loop. To add to it, use [App.RunOnMain].
	MainQueue chan FuncRun `view:"-"`

	// MainDone is a channel on which is a signal is sent when the main loop of the app should be terminated.
	MainDone chan struct{} `view:"-"`

	// Nm is the name of the app.
	Nm string `label:"Name"`

	// Abt is the about information for the app.
	Abt string `label:"About"`

	// OpenFls are files that have been set by the operating system to open at startup.
	OpenFls []string `label:"Open files"`

	// Quitting is whether the app is quitting and thus closing all of the windows
	Quitting bool

	// QuitReqFunc is a function to call when a quit is requested
	QuitReqFunc func()

	// QuitCleanFunc is a function to call when the app is about to quit
	QuitCleanFunc func()

	// Dark is whether the system color theme is dark (as opposed to light)
	Dark bool
}

App contains the data and logic common to all implementations of goosi.App.

func (*App) About

func (a *App) About() string

func (*App) ClipBoard

func (a *App) ClipBoard(win goosi.Window) clip.Board

func (*App) Cursor

func (a *App) Cursor(win goosi.Window) cursor.Cursor

func (*App) GetScreens

func (a *App) GetScreens()

func (*App) GoRunOnMain

func (a *App) GoRunOnMain(f func())

GoRunOnMain runs the given function on the main thread and returns immediately

func (*App) GokiDataDir added in v0.0.25

func (a *App) GokiDataDir() string

func (*App) HideVirtualKeyboard

func (a *App) HideVirtualKeyboard()

func (*App) IsDark

func (a *App) IsDark() bool

func (*App) IsQuitting

func (a *App) IsQuitting() bool

func (*App) MainLoop

func (a *App) MainLoop()

func (*App) Name

func (a *App) Name() string

func (*App) OpenFiles

func (a *App) OpenFiles() []string

func (*App) OpenURL

func (a *App) OpenURL(url string)

func (*App) Quit

func (a *App) Quit()

func (*App) QuitReq

func (a *App) QuitReq()

func (*App) RunOnMain

func (a *App) RunOnMain(f func())

RunOnMain runs the given function on the main thread

func (*App) SendEmptyEvent

func (a *App) SendEmptyEvent()

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..

func (*App) SetAbout

func (a *App) SetAbout(about string)

func (*App) SetName

func (a *App) SetName(name string)

func (*App) SetQuitCleanFunc

func (a *App) SetQuitCleanFunc(fun func())

func (*App) SetQuitReqFunc

func (a *App) SetQuitReqFunc(fun func())

func (*App) ShowVirtualKeyboard

func (a *App) ShowVirtualKeyboard(typ goosi.VirtualKeyboardTypes)

func (*App) StopMain

func (a *App) StopMain()

StopMain stops the main loop and thus terminates the app

type AppMulti

type AppMulti[W goosi.Window] struct {
	App

	// Windows are the windows associated with the app
	Windows []W

	// Screens are the screens associated with the app
	Screens []*goosi.Screen

	// AllScreens is a unique list of all screens ever seen, from which
	// information can be got if something is missing in [AppMulti.Screens]
	AllScreens []*goosi.Screen

	// CtxWindow is a dynamically set context window used for some operations
	CtxWindow W `label:"Context window"`
}

AppMulti contains the data and logic common to all implementations of goosi.App on multi-window platforms (desktop), as opposed to single-window platforms (mobile, web, and offscreen), for which you should use AppSingle. An AppMulti is associated with a corresponding type of goosi.Window. The goosi.Window type should embed WindowMulti.

func NewAppMulti

func NewAppMulti[W goosi.Window]() AppMulti[W]

NewAppMulti makes a new AppMulti.

func (*AppMulti[W]) ContextWindow

func (a *AppMulti[W]) ContextWindow() goosi.Window

func (*AppMulti[W]) NScreens

func (a *AppMulti[W]) NScreens() int

func (*AppMulti[W]) NWindows

func (a *AppMulti[W]) NWindows() int

func (*AppMulti[W]) QuitClean

func (a *AppMulti[W]) QuitClean()

func (*AppMulti[W]) RemoveWindow

func (a *AppMulti[W]) RemoveWindow(w goosi.Window)

RemoveWindow removes the given Window from the app's list of windows. It does not actually close it; see Window.Close for that.

func (*AppMulti[W]) Screen

func (a *AppMulti[W]) Screen(n int) *goosi.Screen

func (*AppMulti[W]) ScreenByName

func (a *AppMulti[W]) ScreenByName(name string) *goosi.Screen

func (*AppMulti[W]) Window

func (a *AppMulti[W]) Window(win int) goosi.Window

func (*AppMulti[W]) WindowByName

func (a *AppMulti[W]) WindowByName(name string) goosi.Window

func (*AppMulti[W]) WindowInFocus

func (a *AppMulti[W]) WindowInFocus() goosi.Window

type AppSingle

type AppSingle[D goosi.Drawer, W goosi.Window] struct {
	App

	// Drawer is the single [goosi.Drawer] used for the app.
	Drawer D

	// Win is the single [goosi.Window] associated with the app.
	Win W `label:"Window"`

	// Scrn is the single [goosi.Screen] associated with the app.
	Scrn *goosi.Screen `label:"Screen"`

	// Insts are the size of any insets on the sides of the screen.
	Insts styles.SideFloats `label:"Insets"`
}

AppSingle contains the data and logic common to all implementations of goosi.App on single-window platforms (mobile, web, and offscreen), as opposed to multi-window platforms (desktop), for which you should use AppMulti. An AppSingle is associated with a corresponding type of goosi.Drawer and goosi.Window. The goosi.Window type should embed WindowSingle.

func NewAppSingle

func NewAppSingle[D goosi.Drawer, W goosi.Window]() AppSingle[D, W]

NewAppSingle makes a new AppSingle.

func (*AppSingle[D, W]) ContextWindow

func (a *AppSingle[D, W]) ContextWindow() goosi.Window

func (*AppSingle[D, W]) Insets

func (a *AppSingle[D, W]) Insets() styles.SideFloats

func (*AppSingle[D, W]) NScreens

func (a *AppSingle[D, W]) NScreens() int

func (*AppSingle[D, W]) NWindows

func (a *AppSingle[D, W]) NWindows() int

func (*AppSingle[D, W]) QuitClean

func (a *AppSingle[D, W]) QuitClean()

func (*AppSingle[D, W]) RemoveWindow

func (a *AppSingle[D, W]) RemoveWindow(w goosi.Window)

func (*AppSingle[D, W]) Screen

func (a *AppSingle[D, W]) Screen(n int) *goosi.Screen

func (*AppSingle[D, W]) ScreenByName

func (a *AppSingle[D, W]) ScreenByName(name string) *goosi.Screen

func (*AppSingle[D, W]) SingleDrawer

func (a *AppSingle[D, W]) SingleDrawer() goosi.Drawer

func (*AppSingle[D, W]) Window

func (a *AppSingle[D, W]) Window(win int) goosi.Window

func (*AppSingle[D, W]) WindowByName

func (a *AppSingle[D, W]) WindowByName(name string) goosi.Window

func (*AppSingle[D, W]) WindowInFocus

func (a *AppSingle[D, W]) WindowInFocus() goosi.Window

type AppSingler

type AppSingler interface {
	goosi.App

	// SingleDrawer returns the single [goosi.Drawer] associated with this app.
	SingleDrawer() goosi.Drawer

	// Insets returns the size of any insets on the sides of the screen.
	Insets() styles.SideFloats
}

AppSingler describes the common functionality implemented by AppSingle apps that WindowSingle windows need to access.

type FuncRun

type FuncRun struct {
	F    func()
	Done chan struct{}
}

FuncRun is a simple helper type that contains a function to call and a channel to send a signal on when the function is finished running.

type Window

type Window[A goosi.App] struct {

	// This is the Window as a [goosi.Window] interface, which preserves the actual identity
	// of the window when calling interface methods in the base Window.
	This goosi.Window `view:"-"`

	// App is the [goosi.App] associated with the window.
	App A

	// Mu is the main mutex protecting access to window operations, including [Window.RunOnWin] functions.
	Mu sync.Mutex `view:"-"`

	// RunQueue is the queue of functions to call on the window loop. To add to it, use [Window.RunOnWin].
	RunQueue chan FuncRun `view:"-"`

	// WinClose is a channel on which a single is sent to indicate that the
	// window should close.
	WinClose chan struct{} `view:"-"`

	// CloseReqFunc is the function to call on a close request
	CloseReqFunc func(win goosi.Window)

	// CloseCleanFunc is the function to call to close the window
	CloseCleanFunc func(win goosi.Window)

	// Nm is the name of the window
	Nm string `label:"Name"`

	// Titl is the title of the window
	Titl string `label:"Title"`

	// Flgs contains the flags associated with the window
	Flgs goosi.WindowFlags `label:"Flags"`

	// FPS is the FPS (frames per second) for rendering the window
	FPS int

	// EvMgr is the event manager for the window
	EvMgr events.Mgr `label:"Event manger"`

	// DestroyGPUFunc should be set to a function that will destroy GPU resources
	// in the main thread prior to destroying the drawer
	// and the surface; otherwise it is difficult to
	// ensure that the proper ordering of destruction applies.
	DestroyGPUFunc func()

	// CursorEnabled is whether the cursor is currently enabled
	CursorEnabled bool
}

Window contains the data and logic common to all implementations of goosi.Window. A Window is associated with a corresponding goosi.App type.

func NewWindow

func NewWindow[A goosi.App](a A, opts *goosi.NewWindowOptions) Window[A]

NewWindow makes a new Window for the given app with the given options.

func (*Window[A]) Close

func (w *Window[A]) Close()

func (*Window[A]) CloseClean

func (w *Window[A]) CloseClean()

func (*Window[A]) CloseReq

func (w *Window[A]) CloseReq()

func (*Window[A]) EventMgr

func (w *Window[A]) EventMgr() *events.Mgr

func (*Window[A]) Flags

func (w *Window[A]) Flags() goosi.WindowFlags

func (*Window[A]) GoRunOnWin

func (w *Window[A]) GoRunOnWin(f func())

GoRunOnWin runs given function on window's unique locked thread and returns immediately

func (*Window[A]) Insets

func (w *Window[A]) Insets() styles.SideFloats

func (*Window[A]) Is

func (w *Window[A]) Is(flag goosi.WindowFlags) bool

func (*Window[A]) IsClosed

func (w *Window[A]) IsClosed() bool

func (*Window[A]) IsCursorEnabled

func (w *Window[A]) IsCursorEnabled() bool

func (*Window[A]) IsVisible

func (w *Window[A]) IsVisible() bool

func (*Window[A]) Lock

func (w *Window[A]) Lock() bool

func (*Window[A]) MainMenu

func (w *Window[A]) MainMenu() goosi.MainMenu

func (*Window[A]) Name

func (w *Window[A]) Name() string

func (*Window[A]) RunOnWin

func (w *Window[A]) RunOnWin(f func())

RunOnWin runs given function on the window's unique locked thread.

func (*Window[A]) SetCloseCleanFunc

func (w *Window[A]) SetCloseCleanFunc(fun func(win goosi.Window))

func (*Window[A]) SetCloseReqFunc

func (w *Window[A]) SetCloseReqFunc(fun func(win goosi.Window))

func (*Window[A]) SetCursorEnabled

func (w *Window[A]) SetCursorEnabled(enabled, raw bool)

func (*Window[A]) SetDestroyGPUResourcesFunc

func (w *Window[A]) SetDestroyGPUResourcesFunc(f func())

func (*Window[A]) SetFPS

func (w *Window[A]) SetFPS(fps int)

func (*Window[A]) SetMousePos

func (w *Window[A]) SetMousePos(x, y float64)

func (*Window[A]) SetName

func (w *Window[A]) SetName(name string)

func (*Window[A]) SetTitle

func (w *Window[A]) SetTitle(title string)

func (*Window[A]) SetTitleBarIsDark

func (w *Window[A]) SetTitleBarIsDark(isDark bool)

func (*Window[A]) Title

func (w *Window[A]) Title() string

func (*Window[A]) Unlock

func (w *Window[A]) Unlock()

func (*Window[A]) WinLoop

func (w *Window[A]) WinLoop()

WinLoop runs the window's own locked processing loop.

type WindowMulti

type WindowMulti[A goosi.App, D goosi.Drawer] struct {
	Window[A]

	// Draw is the [goosi.Drawer] used for this window.
	Draw D `label:"Drawer"`

	// Pos is the position of the window
	Pos image.Point `label:"Position"`

	// WnSize is the size of the window in window manager coordinates
	WnSize image.Point `label:"Window manager size"`

	// PixSize is the pixel size of the window in raw display dots
	PixSize image.Point `label:"Pixel size"`

	// 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

	// 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.
	PhysDPI float32 `label:"Physical DPI"`

	// 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
	LogDPI float32 `label:"Logical DPI"`
}

WindowMulti contains the data and logic common to all implementations of goosi.Window on multi-window platforms (desktop), as opposed to single-window platforms (mobile, web, and offscreen), for which you should use WindowSingle. A WindowMulti is associated with a corresponding goosi.App type. The goosi.App type should embed AppMulti.

func NewWindowMulti

func NewWindowMulti[A goosi.App, D goosi.Drawer](a A, opts *goosi.NewWindowOptions) WindowMulti[A, D]

NewWindowMulti makes a new WindowMulti for the given app with the given options.

func (*WindowMulti[A, D]) Drawer

func (w *WindowMulti[A, D]) Drawer() goosi.Drawer

func (*WindowMulti[A, D]) IsVisible

func (w *WindowMulti[A, D]) IsVisible() bool

func (*WindowMulti[A, D]) LogicalDPI

func (w *WindowMulti[A, D]) LogicalDPI() float32

func (*WindowMulti[A, D]) PhysicalDPI

func (w *WindowMulti[A, D]) PhysicalDPI() float32

func (*WindowMulti[A, D]) Position

func (w *WindowMulti[A, D]) Position() image.Point

func (*WindowMulti[A, D]) SetGeom

func (w *WindowMulti[A, D]) SetGeom(pos image.Point, sz image.Point)

func (*WindowMulti[A, D]) SetLogicalDPI

func (w *WindowMulti[A, D]) SetLogicalDPI(dpi float32)

func (*WindowMulti[A, D]) SetPos

func (w *WindowMulti[A, D]) SetPos(pos image.Point)

func (*WindowMulti[A, D]) SetSize

func (w *WindowMulti[A, D]) SetSize(sz image.Point)

func (*WindowMulti[A, D]) SetWinSize

func (w *WindowMulti[A, D]) SetWinSize(sz image.Point)

func (*WindowMulti[A, D]) Size

func (w *WindowMulti[A, D]) Size() image.Point

func (*WindowMulti[A, D]) WinSize

func (w *WindowMulti[A, D]) WinSize() image.Point

type WindowSingle

type WindowSingle[A AppSingler] struct {
	Window[A]
}

WindowSingle contains the data and logic common to all implementations of goosi.Window on single-window platforms (mobile, web, and offscreen), as opposed to multi-window platforms (desktop), for which you should use WindowSingle. A WindowSingle is associated with a corresponding AppSingler type.

func NewWindowSingle

func NewWindowSingle[A AppSingler](a A, opts *goosi.NewWindowOptions) WindowSingle[A]

NewWindowSingle makes a new WindowSingle for the given app with the given options.

func (*WindowSingle[A]) Drawer

func (w *WindowSingle[A]) Drawer() goosi.Drawer

func (*WindowSingle[A]) Insets

func (w *WindowSingle[A]) Insets() styles.SideFloats

func (*WindowSingle[A]) LogicalDPI

func (w *WindowSingle[A]) LogicalDPI() float32

func (*WindowSingle[A]) Minimize

func (w *WindowSingle[A]) Minimize()

func (*WindowSingle[A]) PhysicalDPI

func (w *WindowSingle[A]) PhysicalDPI() float32

func (*WindowSingle[A]) Position

func (w *WindowSingle[A]) Position() image.Point

func (*WindowSingle[A]) Raise

func (w *WindowSingle[A]) Raise()

func (*WindowSingle[A]) Screen

func (w *WindowSingle[A]) Screen() *goosi.Screen

func (*WindowSingle[A]) SetGeom

func (w *WindowSingle[A]) SetGeom(pos image.Point, sz image.Point)

func (*WindowSingle[A]) SetLogicalDPI

func (w *WindowSingle[A]) SetLogicalDPI(dpi float32)

func (*WindowSingle[A]) SetPos

func (w *WindowSingle[A]) SetPos(pos image.Point)

func (*WindowSingle[A]) SetSize

func (w *WindowSingle[A]) SetSize(sz image.Point)

func (*WindowSingle[A]) SetWinSize

func (w *WindowSingle[A]) SetWinSize(sz image.Point)

func (*WindowSingle[A]) Size

func (w *WindowSingle[A]) Size() image.Point

func (*WindowSingle[A]) WinSize

func (w *WindowSingle[A]) WinSize() image.Point

Jump to

Keyboard shortcuts

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