Updated the style example with more stuff

This commit is contained in:
Sasha Koshka 2022-11-29 00:50:23 -05:00
parent 2fa4cc8da4
commit 0462afdf11
2 changed files with 18 additions and 3 deletions

View File

@ -44,7 +44,7 @@ func (cell Cell) Color () (color Color) {
}
// Style returns the styling information associated with the cell
func (cell Cell) Style (style Style) {
func (cell Cell) Style () (style Style) {
style = cell.style
return
}

View File

@ -3,6 +3,7 @@ package main
import "os"
import "fmt"
import "image"
import "math/rand"
import _ "image/png"
import "git.tebibyte.media/sashakoshka/stone"
import _ "git.tebibyte.media/sashakoshka/stone/backends/x"
@ -11,7 +12,7 @@ var application = &stone.Application { }
func main () {
application.SetTitle("style demo")
application.SetSize(9, 7)
application.SetSize(11, 8)
iconFile16, err := os.Open("assets/scaffold16.png")
if err != nil { panic(err) }
@ -28,11 +29,17 @@ func main () {
application.OnStart(redraw)
application.OnResize(redraw)
application.OnPress(onPress)
err = application.Run()
if err != nil { panic(err) }
}
func onPress (button stone.Button, modifiers stone.Modifiers) {
redraw()
application.Draw()
}
func redraw () {
width, _ := application.Size()
application.SetDot(0, 0)
@ -44,7 +51,8 @@ func redraw () {
"underline\n",
"all 3\n",
"highlighted\n",
"all 4\n")
"all 4\n",
"highlight?")
fillStyle(0, width, stone.StyleNormal)
fillStyle(1, width, stone.StyleBold)
fillStyle(2, width, stone.StyleItalic)
@ -53,10 +61,17 @@ func redraw () {
fillStyle(5, width, stone.StyleHighlight)
fillStyle(6, width, stone.StyleBoldItalic | stone.StyleUnderline |
stone.StyleHighlight)
if rand.Int() % 2 == 0 {
fillStyle(7, width, stone.StyleNormal)
} else {
fillStyle(7, width, stone.StyleHighlight)
}
}
func fillStyle (yOffset, width int, style stone.Style) {
for x := 0; x < width; x ++ {
application.SetStyle(x, yOffset, style)
application.SetColor(x, yOffset, stone.Color(x % 7 + 1))
}
}