Added support for defining applications as objects
This commit is contained in:
parent
4d157756eb
commit
a06f94e41b
|
@ -0,0 +1,113 @@
|
|||
package tomo
|
||||
|
||||
import "image"
|
||||
|
||||
// Application represents an application object.
|
||||
type Application interface {
|
||||
// Describe returns a description of the application.
|
||||
Describe () ApplicationDescription
|
||||
|
||||
// Init performs the initial setup of the application.
|
||||
Init ()
|
||||
}
|
||||
|
||||
// ApplicationDescription describes the name and type of an application.
|
||||
type ApplicationDescription struct {
|
||||
// The name or ID of the application.
|
||||
Name string
|
||||
|
||||
// Role describes what the application does.
|
||||
Role ApplicationRole
|
||||
}
|
||||
|
||||
// String satisfies the fmt.Stringer interface.
|
||||
func (application ApplicationDescription) String () string {
|
||||
if application.Name == "" {
|
||||
return application.Role.String()
|
||||
} else {
|
||||
return application.Name
|
||||
}
|
||||
}
|
||||
|
||||
// ApplicationRole describes what an application does.
|
||||
type ApplicationRole int; const (
|
||||
RoleUnknown ApplicationRole = iota
|
||||
|
||||
RoleWebBrowser
|
||||
RoleMesssanger
|
||||
RolePhone
|
||||
RoleMail
|
||||
|
||||
RoleTerminalEmulator
|
||||
RoleFileBrowser
|
||||
RoleTextEditor
|
||||
|
||||
RoleDocumentViewer
|
||||
RoleWordProcessor
|
||||
RoleSpreadsheet
|
||||
RoleSlideshow
|
||||
RoleCalculator
|
||||
|
||||
RolePreferences
|
||||
RoleProcessManager
|
||||
RoleSystemInformation
|
||||
RoleManual
|
||||
|
||||
RoleCamera
|
||||
RoleImageViewer
|
||||
RoleMediaPlayer
|
||||
RoleImageEditor
|
||||
RoleAudioEditor
|
||||
RoleVideoEditor
|
||||
|
||||
RoleClock
|
||||
RoleCalendar
|
||||
RoleChecklist
|
||||
)
|
||||
|
||||
// String satisfies the fmt.Stringer interface.
|
||||
func (role ApplicationRole) String () string {
|
||||
switch role {
|
||||
case RoleWebBrowser: return "Web Browser"
|
||||
case RoleMesssanger: return "Messsanger"
|
||||
case RolePhone: return "Phone"
|
||||
case RoleMail: return "Mail"
|
||||
case RoleTerminalEmulator: return "Terminal Emulator"
|
||||
case RoleFileBrowser: return "File Browser"
|
||||
case RoleTextEditor: return "Text Editor"
|
||||
case RoleDocumentViewer: return "Document Viewer"
|
||||
case RoleWordProcessor: return "Word Processor"
|
||||
case RoleSpreadsheet: return "Spreadsheet"
|
||||
case RoleSlideshow: return "Slideshow"
|
||||
case RoleCalculator: return "Calculator"
|
||||
case RolePreferences: return "Preferences"
|
||||
case RoleProcessManager: return "Process Manager"
|
||||
case RoleSystemInformation: return "System Information"
|
||||
case RoleManual: return "Manual"
|
||||
case RoleCamera: return "Camera"
|
||||
case RoleImageViewer: return "Image Viewer"
|
||||
case RoleMediaPlayer: return "Media Player"
|
||||
case RoleImageEditor: return "Image Editor"
|
||||
case RoleAudioEditor: return "Audio Editor"
|
||||
case RoleVideoEditor: return "Video Editor"
|
||||
case RoleClock: return "Clock"
|
||||
case RoleCalendar: return "Calendar"
|
||||
case RoleChecklist: return "Checklist"
|
||||
default: return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// RunApplication is like Run, but runs an application.
|
||||
func RunApplication (application Application) error {
|
||||
return Run(application.Init)
|
||||
}
|
||||
|
||||
// NewApplicationWindow creates a window for an application. It will
|
||||
// automatically set window information to signal to the OS that the window is
|
||||
// owned by the application.
|
||||
func NewApplicationWindow (application Application, bounds image.Rectangle) (Window, error) {
|
||||
window, err := NewWindow(bounds)
|
||||
if err != nil { return nil, err }
|
||||
window.SetTitle(application.Describe().String())
|
||||
return window, nil
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package theme
|
||||
|
||||
import "git.tebibyte.media/tomo/tomo"
|
||||
import "git.tebibyte.media/tomo/tomo/data"
|
||||
import "git.tebibyte.media/tomo/tomo/canvas"
|
||||
|
||||
|
@ -430,96 +431,10 @@ func MimeIcon (mime data.Mime, size IconSize) canvas.Texture {
|
|||
}
|
||||
|
||||
// ApplicationIcon describes the icon of the application.
|
||||
type ApplicationIcon struct {
|
||||
// The name or ID of the application. If applicable, this should
|
||||
// correspond to the file name (without the path or extension) of the
|
||||
// icon on the system. This field is optional.
|
||||
Name string
|
||||
|
||||
// Role describes what the application does. If a specific icon file
|
||||
// cannot be found, a generic one is picked using this field.
|
||||
Role ApplicationRole
|
||||
}
|
||||
|
||||
// String satisfies the fmt.Stringer interface.
|
||||
func (application ApplicationIcon) String () string {
|
||||
if application.Name == "" {
|
||||
return application.Role.String()
|
||||
} else {
|
||||
return application.Name
|
||||
}
|
||||
}
|
||||
type ApplicationIcon tomo.ApplicationDescription
|
||||
|
||||
// Texture returns a texture of the corresponding icon ID.
|
||||
func (icon ApplicationIcon) Texture (size IconSize) canvas.Texture {
|
||||
if current == nil { return nil }
|
||||
return current.ApplicationIcon(icon, size)
|
||||
}
|
||||
|
||||
// ApplicationRole describes what an application does.
|
||||
type ApplicationRole int; const (
|
||||
RoleUnknown ApplicationRole = iota
|
||||
|
||||
RoleWebBrowser
|
||||
RoleMesssanger
|
||||
RolePhone
|
||||
RoleMail
|
||||
|
||||
RoleTerminalEmulator
|
||||
RoleFileBrowser
|
||||
RoleTextEditor
|
||||
|
||||
RoleDocumentViewer
|
||||
RoleWordProcessor
|
||||
RoleSpreadsheet
|
||||
RoleSlideshow
|
||||
RoleCalculator
|
||||
|
||||
RolePreferences
|
||||
RoleProcessManager
|
||||
RoleSystemInformation
|
||||
RoleManual
|
||||
|
||||
RoleCamera
|
||||
RoleImageViewer
|
||||
RoleMediaPlayer
|
||||
RoleImageEditor
|
||||
RoleAudioEditor
|
||||
RoleVideoEditor
|
||||
|
||||
RoleClock
|
||||
RoleCalendar
|
||||
RoleChecklist
|
||||
)
|
||||
|
||||
// String satisfies the fmt.Stringer interface.
|
||||
func (role ApplicationRole) String () string {
|
||||
switch role {
|
||||
case RoleWebBrowser: return "Web Browser"
|
||||
case RoleMesssanger: return "Messsanger"
|
||||
case RolePhone: return "Phone"
|
||||
case RoleMail: return "Mail"
|
||||
case RoleTerminalEmulator: return "Terminal Emulator"
|
||||
case RoleFileBrowser: return "File Browser"
|
||||
case RoleTextEditor: return "Text Editor"
|
||||
case RoleDocumentViewer: return "Document Viewer"
|
||||
case RoleWordProcessor: return "Word Processor"
|
||||
case RoleSpreadsheet: return "Spreadsheet"
|
||||
case RoleSlideshow: return "Slideshow"
|
||||
case RoleCalculator: return "Calculator"
|
||||
case RolePreferences: return "Preferences"
|
||||
case RoleProcessManager: return "Process Manager"
|
||||
case RoleSystemInformation: return "System Information"
|
||||
case RoleManual: return "Manual"
|
||||
case RoleCamera: return "Camera"
|
||||
case RoleImageViewer: return "Image Viewer"
|
||||
case RoleMediaPlayer: return "Media Player"
|
||||
case RoleImageEditor: return "Image Editor"
|
||||
case RoleAudioEditor: return "Audio Editor"
|
||||
case RoleVideoEditor: return "Video Editor"
|
||||
case RoleClock: return "Clock"
|
||||
case RoleCalendar: return "Calendar"
|
||||
case RoleChecklist: return "Checklist"
|
||||
default: return "unknown"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,4 +110,3 @@ func Apply (object tomo.Object, role Role) event.Cookie {
|
|||
if current == nil { return event.NoCookie { } }
|
||||
return current.Apply(object, role)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue