An easy way to write applications with Tomo.
assets | ||
config | ||
internal | ||
.editorconfig | ||
application.go | ||
go.mod | ||
go.sum | ||
LICENSE | ||
manager.go | ||
path_unix.go | ||
path.go | ||
README.md |
nasin
Nasin builds an application framework on top of Tomo to ease and encourage the development of consistent and stable application software. It has these wonderful features, and more:
- Use the Application interface to create applications with relatively low boilerplate
- CLI argument parsing and URI opening
- Automatic setup/teardown of the backend
- Advanced configuration system that can watch config files for changes
- Default style and icon set, as well as a fully featured stylesheet language for creating custom styles, and support for XDG icon themes
Getting Started
Here is a basic "hello world" application, with explanations as comments:
package main
import "image"
import "git.tebibyte.media/tomo/nasin"
import "git.tebibyte.media/tomo/objects"
import "git.tebibyte.media/tomo/objects/layouts"
func main () {
nasin.RunApplication(new(Application))
}
type Application struct { }
// Describe returns the application's name and ID, and optionally what type of
// application it is.
func (this *Application) Describe () nasin.ApplicationDescription {
return nasin.ApplicationDescription {
// This is the name of the application. New application windows
// will have this as their title by default.
Name: "Example",
// This is a "well-known" name, which typically is a domain name
// owned by the application author.
ID: "com.example.Example",
}
}
// Init performs initial setup of the application. Since this is a single-window
// application that doesn't open any files, we create the window here.
func (this *Application) Init () error {
// Passing an empty rectangle when creating a new window will cause it
// to auto-expand to fit the minimum size of its contents.
window, err := nasin.NewApplicationWindow(this, image.Rectangle { })
if err != nil { return err }
// Here we create a new container with a basic vertical layout, place a
// text label that says "Hello world!" in it, and set it as the root
// object of the window.
window.SetRoot(objects.NewOuterContainer (
layouts.ContractVertical,
objects.NewLabel("Hello world!")))
window.SetVisible(true)
// Nasin will not exit until all windows it is "waiting for" have
// been closed.
nasin.WaitFor(window)
return nil
}
// Stop cleanly closes things like system resources or background tasks. We do
// not have any here, so nothing is done.
func (this *Application) Stop () { }
To learn more, take a look at the examples directory and the online documentation.