nasin/README.md

81 lines
3.0 KiB
Markdown
Raw Permalink Normal View History

2024-04-28 22:47:50 -06:00
# nasin
2024-04-29 22:31:02 -06:00
[![Go Reference](https://pkg.go.dev/badge/git.tebibyte.media/tomo/nasin.svg)](https://pkg.go.dev/git.tebibyte.media/tomo/nasin)
2024-08-23 00:23:04 -06:00
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:
```go
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](examples) directory and the
2024-05-14 10:49:22 -06:00
[online documentation](https://pkg.go.dev/git.tebibyte.media/tomo/nasin).
2024-05-14 10:48:44 -06:00
2024-08-23 00:23:04 -06:00
## Related Repositories
2024-05-14 10:50:49 -06:00
- [Tomo API](https://git.tebibyte.media/tomo/tomo): The API that all other parts
2024-05-14 10:48:44 -06:00
of the toolkit agree on
2024-05-14 10:50:49 -06:00
- [Objects](https://git.tebibyte.media/tomo/objects): A standard collection of
2024-05-14 10:48:44 -06:00
re-usable objects and other GUI components
2024-08-23 00:23:04 -06:00
- [Backend](https://git.tebibyte.media/tomo/backend): The software responsible
for managing and rendering things behind the scenes