base

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 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 system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(a system.App, ab *App)

Init does basic initialization steps of the given App. It should be called by platform-specific implementations of Init with their platform-specific app instance and its base App field. Other platform-specific initial configuration steps can be called before this. Platform-specific implementations of Init are always called by a lowercase init function in system/driver/driver_{platform}.go.

Types

type App

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

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

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

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

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

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

	// QuitCleanFuncs are functions to call when the app is about to quit
	QuitCleanFuncs []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 system.App.

func (*App) AddQuitCleanFunc

func (a *App) AddQuitCleanFunc(fun func())

func (*App) AppDataDir

func (a *App) AppDataDir() string

func (*App) Clipboard

func (a *App) Clipboard(win system.Window) system.Clipboard

func (*App) CogentCoreDataDir

func (a *App) CogentCoreDataDir() string

func (*App) Cursor

func (a *App) Cursor(win system.Window) system.Cursor

func (*App) GetScreens

func (a *App) GetScreens()

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) SetName

func (a *App) SetName(name string)

func (*App) SetQuitReqFunc

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

func (*App) ShowVirtualKeyboard

func (a *App) ShowVirtualKeyboard(typ styles.VirtualKeyboards)

func (*App) StopMain

func (a *App) StopMain()

StopMain stops the main loop and thus terminates the app

func (*App) SystemInfo added in v0.2.0

func (a *App) SystemInfo() string

func (*App) SystemPlatform

func (a *App) SystemPlatform() system.Platforms

type AppMulti

type AppMulti[W system.Window] struct {
	App

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

	// Screens are the screens associated with the app
	Screens []*system.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 []*system.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 system.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 system.Window. The system.Window type should embed WindowMulti.

func NewAppMulti

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

NewAppMulti makes a new AppMulti.

func (*AppMulti[W]) ContextWindow

func (a *AppMulti[W]) ContextWindow() system.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() bool

func (*AppMulti[W]) RemoveWindow

func (a *AppMulti[W]) RemoveWindow(w system.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) *system.Screen

func (*AppMulti[W]) ScreenByName

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

func (*AppMulti[W]) Window

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

func (*AppMulti[W]) WindowByName

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

func (*AppMulti[W]) WindowInFocus

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

type AppSingle

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

	// Event is the event manager for the app.
	Event events.Source `label:"Events"`

	// Draw is the single [system.Drawer] used for the app.
	Draw D `label:"Drawer"`

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

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

	// Insets are the size of any insets on the sides of the screen.
	Insets styles.Sides[int]
}

AppSingle contains the data and logic common to all implementations of system.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 system.Drawer and system.Window. The system.Window type should embed WindowSingle.

func NewAppSingle

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

NewAppSingle makes a new AppSingle.

func (*AppSingle[D, W]) ContextWindow

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

func (*AppSingle[D, W]) Drawer

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

func (*AppSingle[D, W]) Events added in v0.1.1

func (a *AppSingle[D, W]) Events() *events.Source

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() bool

func (*AppSingle[D, W]) RemoveWindow

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

func (*AppSingle[D, W]) RenderGeom

func (a *AppSingle[D, W]) RenderGeom() math32.Geom2DInt

func (*AppSingle[D, W]) Screen

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

func (*AppSingle[D, W]) ScreenByName

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

func (*AppSingle[D, W]) Window

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

func (*AppSingle[D, W]) WindowByName

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

func (*AppSingle[D, W]) WindowInFocus

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

type AppSingler

type AppSingler interface {
	system.App

	// Events returns the single [events.Source] associated with this app.
	Events() *events.Source

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

	// RenderGeom returns the actual effective geometry of the window used
	// for rendering content, which may be different from {0, [system.Screen.PixSize]}
	// due to insets caused by things like status bars and button overlays.
	RenderGeom() math32.Geom2DInt
}

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 system.App] struct {

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

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

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

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

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

	// CloseCleanFunc is the function to call to close the window
	CloseCleanFunc func(win system.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 system.WindowFlags `label:"Flags" table:"-"`

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

	// 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 system.Window. A Window is associated with a corresponding system.App type.

func NewWindow

func NewWindow[A system.App](a A, opts *system.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]) Flags

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

func (*Window[A]) Is

func (w *Window[A]) Is(flag system.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]) Name

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

func (*Window[A]) RenderGeom

func (w *Window[A]) RenderGeom() math32.Geom2DInt

func (*Window[A]) SetCloseCleanFunc

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

func (*Window[A]) SetCloseReqFunc

func (w *Window[A]) SetCloseReqFunc(fun func(win system.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]) SetIcon

func (w *Window[A]) SetIcon(images []image.Image)

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 system.App, D system.Drawer] struct {
	Window[A]

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

	// Draw is the [system.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 system.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 system.App type. The system.App type should embed AppMulti.

func NewWindowMulti

func NewWindowMulti[A system.App, D system.Drawer](a A, opts *system.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() system.Drawer

func (*WindowMulti[A, D]) Events added in v0.1.1

func (w *WindowMulti[A, D]) Events() *events.Source

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 system.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 *system.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() system.Drawer

func (*WindowSingle[A]) Events added in v0.1.1

func (w *WindowSingle[A]) Events() *events.Source

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]) RenderGeom

func (w *WindowSingle[A]) RenderGeom() math32.Geom2DInt

func (*WindowSingle[A]) Screen

func (w *WindowSingle[A]) Screen() *system.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