2022-11-13 20:28:44 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "os"
|
2022-11-19 16:00:47 -07:00
|
|
|
import "fmt"
|
2022-11-13 20:28:44 -07:00
|
|
|
import "image"
|
|
|
|
import _ "image/png"
|
|
|
|
import "git.tebibyte.media/sashakoshka/stone"
|
|
|
|
import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
|
|
|
|
|
|
|
|
var application = &stone.Application { }
|
2022-11-19 16:00:47 -07:00
|
|
|
var caretX = 0
|
|
|
|
var caretY = 2
|
|
|
|
var page = 1
|
2022-11-13 20:28:44 -07:00
|
|
|
|
|
|
|
func main () {
|
|
|
|
application.SetTitle("hellorld")
|
2022-11-19 16:00:47 -07:00
|
|
|
application.SetSize(32, 28)
|
2022-11-13 20:28:44 -07:00
|
|
|
|
|
|
|
iconFile16, err := os.Open("assets/scaffold16.png")
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
icon16, _, err := image.Decode(iconFile16)
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
iconFile16.Close()
|
|
|
|
iconFile32, err := os.Open("assets/scaffold32.png")
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
icon32, _, err := image.Decode(iconFile32)
|
|
|
|
if err != nil { panic(err) }
|
|
|
|
iconFile16.Close()
|
|
|
|
|
|
|
|
application.SetIcon([]image.Image { icon16, icon32 })
|
2022-11-19 16:00:47 -07:00
|
|
|
application.OnStart(redraw)
|
|
|
|
application.OnPress(onPress)
|
|
|
|
application.OnResize(redraw)
|
2022-11-13 20:28:44 -07:00
|
|
|
|
2022-11-19 16:00:47 -07:00
|
|
|
err = application.Run()
|
2022-11-13 20:28:44 -07:00
|
|
|
if err != nil { panic(err) }
|
|
|
|
|
|
|
|
application.Draw()
|
2022-11-19 16:00:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func redraw () {
|
|
|
|
application.Clear()
|
|
|
|
_, height := application.Size()
|
|
|
|
application.SetDot(0, 0)
|
|
|
|
fmt.Fprint(application, "type some text below:")
|
|
|
|
caretX = 0
|
|
|
|
caretY = 2
|
|
|
|
application.SetDot(0, height - 1)
|
|
|
|
fmt.Fprintf(application, "page %d", page)
|
|
|
|
drawCaret()
|
|
|
|
}
|
|
|
|
|
|
|
|
func drawCaret () {
|
|
|
|
application.SetRune(caretX, caretY, '+')
|
|
|
|
application.SetColor(caretX, caretY, stone.ColorDim)
|
|
|
|
}
|
2022-11-13 20:28:44 -07:00
|
|
|
|
2022-11-21 22:21:35 -07:00
|
|
|
func onPress (button stone.Button, modifiers stone.Modifiers) {
|
2022-11-19 16:00:47 -07:00
|
|
|
width, height := application.Size()
|
|
|
|
|
|
|
|
if button == stone.KeyEnter {
|
|
|
|
application.SetRune(caretX, caretY, 0)
|
|
|
|
caretX = 0
|
|
|
|
caretY ++
|
|
|
|
|
|
|
|
} else if button.Printable() {
|
|
|
|
application.SetRune(caretX, caretY, rune(button))
|
|
|
|
application.SetColor(caretX, caretY, stone.ColorForeground)
|
|
|
|
caretX ++
|
|
|
|
|
|
|
|
if caretX >= width {
|
|
|
|
caretX = 0
|
|
|
|
caretY ++
|
2022-11-13 20:28:44 -07:00
|
|
|
}
|
|
|
|
}
|
2022-11-19 16:00:47 -07:00
|
|
|
|
|
|
|
if caretY >= height - 2 {
|
|
|
|
page ++
|
|
|
|
redraw()
|
|
|
|
}
|
|
|
|
|
|
|
|
drawCaret()
|
|
|
|
application.Draw()
|
2022-11-13 20:28:44 -07:00
|
|
|
}
|