From 2fa4cc8da42bfca9e3b37f1040663a4e9f08f9bf Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Tue, 29 Nov 2022 00:26:26 -0500 Subject: [PATCH] Created a style test (that does nothing as of now) --- examples/style/main.go | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 examples/style/main.go diff --git a/examples/style/main.go b/examples/style/main.go new file mode 100644 index 0000000..6f19035 --- /dev/null +++ b/examples/style/main.go @@ -0,0 +1,62 @@ +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 { } + +func main () { + application.SetTitle("style demo") + application.SetSize(9, 7) + + 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 }) + + application.OnStart(redraw) + application.OnResize(redraw) + + err = application.Run() + if err != nil { panic(err) } +} + +func redraw () { + width, _ := application.Size() + application.SetDot(0, 0) + fmt.Fprint ( + application, + "normal\n", + "bold\n", + "italic\n", + "underline\n", + "all 3\n", + "highlighted\n", + "all 4\n") + fillStyle(0, width, stone.StyleNormal) + fillStyle(1, width, stone.StyleBold) + fillStyle(2, width, stone.StyleItalic) + fillStyle(3, width, stone.StyleUnderline) + fillStyle(4, width, stone.StyleBoldItalic | stone.StyleUnderline) + fillStyle(5, width, stone.StyleHighlight) + fillStyle(6, width, stone.StyleBoldItalic | stone.StyleUnderline | + stone.StyleHighlight) +} + +func fillStyle (yOffset, width int, style stone.Style) { + for x := 0; x < width; x ++ { + application.SetStyle(x, yOffset, style) + } +}