Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 341eea5b5d | |||
| 453953bbcd | |||
| 31ce286bc7 | |||
| 26cf1f4a88 | |||
| 6ef1f7ba78 | |||
| d7093be696 | |||
| 64bf8f3b2d | |||
| 50cbac17a9 | |||
| d096d40c57 | |||
| 34358da6eb | |||
| be1b9d77e8 | |||
| d71ac02748 | |||
| 2bbf85ebd8 | |||
| 320535e7f3 | |||
| 775fb84e9b |
10
backend.go
10
backend.go
@@ -17,18 +17,22 @@ type Backend interface {
|
||||
NewSurfaceBox () (SurfaceBox, error)
|
||||
NewContainerBox () ContainerBox
|
||||
|
||||
// NewWindow creates a normal MainWindow and returns it.
|
||||
NewWindow (image.Rectangle) (MainWindow, error)
|
||||
// NewWindow creates a normal Window and returns it.
|
||||
NewWindow (image.Rectangle) (Window, error)
|
||||
|
||||
// NewPlainWindow creates an undecorated window that does not appear in
|
||||
// window lists and returns it. This is intended for making things like
|
||||
// panels, docks, etc.
|
||||
NewPlainWindow (image.Rectangle) (MainWindow, error)
|
||||
NewPlainWindow (image.Rectangle) (Window, error)
|
||||
|
||||
// NewTexture creates a new texture from an image. The backend must
|
||||
// reject any texture that was not made by it.
|
||||
NewTexture (image.Image) canvas.TextureCloser
|
||||
|
||||
// NewCanvas creates a new canvas with the specified bounds. The backend
|
||||
// must reject any canvas that was not made by it.
|
||||
NewCanvas (image.Rectangle) canvas.CanvasCloser
|
||||
|
||||
// Run runs the event loop until Stop() is called, or the backend
|
||||
// experiences a fatal error.
|
||||
Run () error
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// primitives.
|
||||
package canvas
|
||||
|
||||
import "io"
|
||||
import "image"
|
||||
import "image/draw"
|
||||
import "image/color"
|
||||
@@ -77,6 +78,13 @@ type Canvas interface {
|
||||
SubCanvas (image.Rectangle) Canvas
|
||||
}
|
||||
|
||||
// CanvasCloser is a canvas that can be closed. Anything that receives a
|
||||
// CanvasCloser must close it after use.
|
||||
type CanvasCloser interface {
|
||||
Canvas
|
||||
io.Closer
|
||||
}
|
||||
|
||||
// Drawer can draw to a canvas.
|
||||
type Drawer interface {
|
||||
// Draw draws to the given canvas.
|
||||
|
||||
3
go.sum
3
go.sum
@@ -1,8 +1,6 @@
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/image v0.8.0 h1:agUcRXV/+w6L9ryntYYsF2x9fQTMd4T8fiiYXAVW6Jg=
|
||||
golang.org/x/image v0.8.0/go.mod h1:PwLxp3opCYg4WR2WO9P0L6ESnsD6bLTWcw8zanLMVFM=
|
||||
golang.org/x/image v0.11.0 h1:ds2RoQvBvYTiJkwpSFDwCcDFNX7DqjL2WsUgTNk0Ooo=
|
||||
golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
@@ -27,7 +25,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
|
||||
41
icon.go
41
icon.go
@@ -35,19 +35,9 @@ const (
|
||||
IconCallStart Icon = "CallStart"
|
||||
IconCallStop Icon = "CallStop"
|
||||
IconContactNew Icon = "ContactNew"
|
||||
// actions: file
|
||||
IconFileNew Icon = "FileNew"
|
||||
IconDirectoryNew Icon = "DirectoryNew"
|
||||
IconFileOpen Icon = "FileOpen"
|
||||
IconFileOpenRecent Icon = "FileOpenRecent"
|
||||
IconFilePageSetup Icon = "FilePageSetup"
|
||||
IconFilePrint Icon = "FilePrint"
|
||||
IconFilePrintPreview Icon = "FilePrintPreview"
|
||||
IconFileProperties Icon = "FileProperties"
|
||||
IconFileRevert Icon = "FileRevert"
|
||||
IconFileSave Icon = "FileSave"
|
||||
IconFileSaveAs Icon = "FileSaveAs"
|
||||
IconFileSend Icon = "FileSend"
|
||||
// actions: dialog
|
||||
IconDialogOkay Icon = "DialogOkay"
|
||||
IconDialogCancel Icon = "DialogCancel"
|
||||
// actions: edit
|
||||
IconEditClear Icon = "EditClear"
|
||||
IconEditCopy Icon = "EditCopy"
|
||||
@@ -59,6 +49,21 @@ const (
|
||||
IconEditRedo Icon = "EditRedo"
|
||||
IconEditSelectAll Icon = "EditSelectAll"
|
||||
IconEditUndo Icon = "EditUndo"
|
||||
// actions: file
|
||||
IconFileNew Icon = "FileNew"
|
||||
IconDirectoryNew Icon = "DirectoryNew"
|
||||
IconFileOpen Icon = "FileOpen"
|
||||
IconFileOpenRecent Icon = "FileOpenRecent"
|
||||
IconFilePageSetup Icon = "FilePageSetup"
|
||||
IconFilePrint Icon = "FilePrint"
|
||||
IconFilePrintPreview Icon = "FilePrintPreview"
|
||||
IconFilePermissions Icon = "FilePermissions"
|
||||
IconFileProperties Icon = "FileProperties"
|
||||
IconFileRename Icon = "FileRename"
|
||||
IconFileRevert Icon = "FileRevert"
|
||||
IconFileSave Icon = "FileSave"
|
||||
IconFileSaveAs Icon = "FileSaveAs"
|
||||
IconFileSend Icon = "FileSend"
|
||||
// actions: format
|
||||
IconFormatIndentLess Icon = "FormatIndentLess"
|
||||
IconFormatIndentMore Icon = "FormatIndentMore"
|
||||
@@ -73,7 +78,6 @@ const (
|
||||
IconFormatTextUnderline Icon = "FormatTextUnderline"
|
||||
IconFormatTextStrikethrough Icon = "FormatTextStrikethrough"
|
||||
// actions: go
|
||||
IconGo Icon = "Go"
|
||||
IconGoBottom Icon = "GoBottom"
|
||||
IconGoDown Icon = "GoDown"
|
||||
IconGoFirst Icon = "GoFirst"
|
||||
@@ -134,6 +138,10 @@ const (
|
||||
IconSystemShutdown Icon = "SystemShutdown"
|
||||
// actions: tools
|
||||
IconToolsCheckSpelling Icon = "ToolsCheckSpelling"
|
||||
// actions: value
|
||||
IconValueIncrement Icon = "ValueIncrement"
|
||||
IconValueDecrement Icon = "ValueDecrement"
|
||||
IconValueReset Icon = "ValueReset"
|
||||
// actions: view
|
||||
IconViewFullscreen Icon = "ViewFullscreen"
|
||||
IconViewRefresh Icon = "ViewRefresh"
|
||||
@@ -192,7 +200,6 @@ const (
|
||||
IconApplicationsSystem Icon = "ApplicationsSystem"
|
||||
IconApplicationsUtilities Icon = "ApplicationsUtilities"
|
||||
// categories: preferences
|
||||
|
||||
IconPreferences Icon = "Preferences"
|
||||
IconPreferencesDesktop Icon = "PreferencesDesktop"
|
||||
IconPreferencesPeripherals Icon = "PreferencesPeripherals"
|
||||
@@ -224,6 +231,7 @@ const (
|
||||
IconPowerBattery Icon = "PowerBattery"
|
||||
// devices: storage
|
||||
IconStorageHardDisk Icon = "StorageHardDisk"
|
||||
IconStorageFloppyDisk Icon = "StorageFloppyDisk"
|
||||
IconStorageSolidState Icon = "StorageSolidState"
|
||||
IconStorageOptical Icon = "StorageOptical"
|
||||
IconStorageFlashStick Icon = "StorageFlashStick"
|
||||
@@ -277,6 +285,9 @@ const (
|
||||
IconPlaceHistory Icon = "PlaceHistory"
|
||||
IconPlacePreferences Icon = "PlacePreferences"
|
||||
|
||||
// status: checkbox
|
||||
IconCheckboxChecked Icon = "CheckboxChecked"
|
||||
IconCheckboxUnchecked Icon = "CheckboxUnchecked"
|
||||
// status: appointments
|
||||
IconAppointmentMissed Icon = "AppointmentMissed"
|
||||
IconAppointmentSoon Icon = "AppointmentSoon"
|
||||
|
||||
40
object.go
40
object.go
@@ -144,6 +144,8 @@ type Box interface {
|
||||
// internal content that does not overflow, the size of that is also
|
||||
// taken into account here.
|
||||
MinimumSize () image.Point
|
||||
// Role returns this Box's role as set by SetRole.
|
||||
Role () Role
|
||||
// SetBounds sets the bounding rectangle of this Box relative to the
|
||||
// Window.
|
||||
SetBounds (image.Rectangle)
|
||||
@@ -168,12 +170,9 @@ type Box interface {
|
||||
// SetPadding sets the padding between the Box's innermost Border and
|
||||
// its content.
|
||||
SetPadding (Inset)
|
||||
// SetVisible sets whether or not this box is visible. If invisible,
|
||||
// it will not be drawn and no space will be created for it in the
|
||||
// layout. Boxes are visible by default.
|
||||
SetVisible (bool)
|
||||
// Visible returns whether or not this box is visible.
|
||||
Visible () bool
|
||||
// SetRole sets what role this Box takes on. It is used to apply styling
|
||||
// from a theme.
|
||||
SetRole (Role)
|
||||
|
||||
// SetDNDData sets the data that will be picked up if this Box is
|
||||
// dragged. If this is nil (which is the default), this Box will not be
|
||||
@@ -250,9 +249,16 @@ type SurfaceBox interface {
|
||||
// expected type was not found.
|
||||
Surface () any
|
||||
|
||||
// Invalidate causes the Box's area to be redrawn at the end of the
|
||||
// event cycle, even if it wouldn't be otherwise.
|
||||
// Invalidate causes the data within the surface to be pushed to the
|
||||
// screen at the end of the event cycle, even if it wouldn't be
|
||||
// otherwise.
|
||||
Invalidate ()
|
||||
|
||||
// OnSizeChange specifies a function to be called when the size of the
|
||||
// Box is changed, or the surface is re-allocated. The application must
|
||||
// call Surface() each time this event fires in order to not draw to a
|
||||
// closed surface.
|
||||
OnSizeChange (func ())
|
||||
}
|
||||
|
||||
// ContentBox is a box that has some kind of content.
|
||||
@@ -376,12 +382,17 @@ type Window interface {
|
||||
SetTitle (string)
|
||||
// SetIcon sets the icon of the window. When multiple icon sizes are
|
||||
// provided, the best fitting one is chosen for display.
|
||||
SetIcon (... image.Image)
|
||||
SetIcon (... canvas.Texture)
|
||||
// Widget returns a window representing a smaller iconified form of this
|
||||
// window. How exactly this window is used depends on the platform.
|
||||
// Subsequent calls to this method on the same window will return the
|
||||
// same window object.
|
||||
Widget () (Window, error)
|
||||
// NewChild creates a new window that is semantically a child of this
|
||||
// window. It does not actually reside within this window, but it may be
|
||||
// linked to it via some other means. This is intended for things like
|
||||
// toolboxes and tear-off menus.
|
||||
NewChild (image.Rectangle) (Window, error)
|
||||
// NewMenu creates a new menu window. This window is undecorated and
|
||||
// will close once the user clicks outside of it.
|
||||
NewMenu (image.Rectangle) (Window, error)
|
||||
@@ -403,14 +414,3 @@ type Window interface {
|
||||
// OnClose specifies a function to be called when the window is closed.
|
||||
OnClose (func ()) event.Cookie
|
||||
}
|
||||
|
||||
// MainWindow is a top-level operating system window.
|
||||
type MainWindow interface {
|
||||
Window
|
||||
|
||||
// NewChild creates a new window that is semantically a child of this
|
||||
// window. It does not actually reside within this window, but it may be
|
||||
// linked to it via some other means. This is intended for things like
|
||||
// toolboxes and tear-off menus.
|
||||
NewChild (image.Rectangle) (Window, error)
|
||||
}
|
||||
|
||||
25
theme.go
25
theme.go
@@ -77,18 +77,21 @@ type Theme interface {
|
||||
//
|
||||
// As such, textures returned by these methods must be protected.
|
||||
|
||||
// Apply applies the theme to the given object, according to the given
|
||||
// role. This may register event listeners with the given object;
|
||||
// closing the returned cookie must remove them.
|
||||
Apply (Object, Role) event.Cookie
|
||||
// Apply applies the theme to the given object, according to its role.
|
||||
// This may register event listeners with the given object; closing the
|
||||
// returned cookie must remove them.
|
||||
Apply (Object) event.Cookie
|
||||
|
||||
// RGBA returns the RGBA values of the corresponding color ID.
|
||||
RGBA (Color) (r, g, b, a uint32)
|
||||
|
||||
// Icon returns a texture of the corresponding icon ID.
|
||||
// Icon returns a texture of the corresponding icon ID. If there is no
|
||||
// suitable option, it should return nil.
|
||||
Icon (Icon, IconSize) canvas.Texture
|
||||
|
||||
// MimeIcon returns an icon corresponding to a MIME type.
|
||||
// MimeIcon returns a texture of an icon corresponding to a MIME type.
|
||||
// If there is no suitable specific option, it should return a more
|
||||
// generic icon or a plain file icon.
|
||||
MimeIcon (data.Mime, IconSize) canvas.Texture
|
||||
}
|
||||
|
||||
@@ -99,10 +102,10 @@ func SetTheme (them Theme) {
|
||||
theme = them
|
||||
}
|
||||
|
||||
// Apply applies the current theme to the given object, according to the given
|
||||
// role. This may register event listeners with the given object; closing the
|
||||
// returned cookie will remove them.
|
||||
func Apply (object Object, role Role) event.Cookie {
|
||||
// Apply applies the current theme to the given object, according its role. This
|
||||
// may register event listeners with the given object; closing the returned
|
||||
// cookie will remove them.
|
||||
func Apply (object Object) event.Cookie {
|
||||
if theme == nil { return event.NoCookie { } }
|
||||
return theme.Apply(object, role)
|
||||
return theme.Apply(object)
|
||||
}
|
||||
|
||||
11
tomo.go
11
tomo.go
@@ -50,7 +50,7 @@ func Do (callback func ()) {
|
||||
}
|
||||
|
||||
// NewWindow creates and returns a window within the specified bounds on screen.
|
||||
func NewWindow (bounds image.Rectangle) (MainWindow, error) {
|
||||
func NewWindow (bounds image.Rectangle) (Window, error) {
|
||||
assertBackend()
|
||||
return backend.NewWindow(bounds)
|
||||
}
|
||||
@@ -58,7 +58,7 @@ func NewWindow (bounds image.Rectangle) (MainWindow, error) {
|
||||
// NewPlainWindow is like NewWindow, but it creates an undecorated window that
|
||||
// does not appear in window lists. It is intended for creating things like
|
||||
// docks, panels, etc.
|
||||
func NewPlainWindow (bounds image.Rectangle) (MainWindow, error) {
|
||||
func NewPlainWindow (bounds image.Rectangle) (Window, error) {
|
||||
assertBackend()
|
||||
return backend.NewPlainWindow(bounds)
|
||||
}
|
||||
@@ -93,3 +93,10 @@ func NewTexture (source image.Image) canvas.TextureCloser {
|
||||
assertBackend()
|
||||
return backend.NewTexture(source)
|
||||
}
|
||||
|
||||
// NewCanvas creates a new canvas with the specified bounds. When no longer in
|
||||
// use, it must be freed using Close().
|
||||
func NewCanvas (bounds image.Rectangle) canvas.CanvasCloser {
|
||||
assertBackend()
|
||||
return backend.NewCanvas(bounds)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user