Updated examples and added more documentation
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
package main
|
||||
|
||||
import "os"
|
||||
import "fmt"
|
||||
import "image"
|
||||
import _ "image/png"
|
||||
import "git.tebibyte.media/sashakoshka/stone"
|
||||
import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
|
||||
|
||||
var application = &stone.Application { }
|
||||
var caret = 0
|
||||
var caretX = 0
|
||||
var caretY = 2
|
||||
var page = 1
|
||||
|
||||
func main () {
|
||||
application.SetTitle("hellorld")
|
||||
application.SetSize(32, 16)
|
||||
application.SetSize(32, 28)
|
||||
|
||||
iconFile16, err := os.Open("assets/scaffold16.png")
|
||||
if err != nil { panic(err) }
|
||||
@@ -25,32 +28,57 @@ func main () {
|
||||
iconFile16.Close()
|
||||
|
||||
application.SetIcon([]image.Image { icon16, icon32 })
|
||||
application.OnStart(redraw)
|
||||
application.OnPress(onPress)
|
||||
application.OnResize(redraw)
|
||||
|
||||
channel, err := application.Run()
|
||||
err = application.Run()
|
||||
if err != nil { panic(err) }
|
||||
|
||||
application.Draw()
|
||||
}
|
||||
|
||||
for {
|
||||
event := <- channel
|
||||
switch event.(type) {
|
||||
case stone.EventQuit:
|
||||
os.Exit(0)
|
||||
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()
|
||||
}
|
||||
|
||||
case stone.EventPress:
|
||||
button := event.(stone.EventPress).Button
|
||||
if button.Printable() {
|
||||
application.SetRune(caret, 0, rune(button))
|
||||
caret ++
|
||||
width, _ := application.Size()
|
||||
if caret >= width {
|
||||
caret = 0
|
||||
}
|
||||
application.Draw()
|
||||
}
|
||||
func drawCaret () {
|
||||
application.SetRune(caretX, caretY, '+')
|
||||
application.SetColor(caretX, caretY, stone.ColorDim)
|
||||
}
|
||||
|
||||
case stone.EventResize:
|
||||
application.Draw()
|
||||
func onPress (button stone.Button) {
|
||||
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 ++
|
||||
}
|
||||
}
|
||||
|
||||
if caretY >= height - 2 {
|
||||
page ++
|
||||
redraw()
|
||||
}
|
||||
|
||||
drawCaret()
|
||||
application.Draw()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user