Archived
1
0
This repository has been archived on 2025-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
kos_go/example/example.go

80 lines
1.2 KiB
Go
Raw Permalink Normal View History

2023-06-11 03:21:00 +03:00
package example
import (
"colors"
"../kos"
)
const (
Btn1 = 2
Btn2 = 3
BtnExit = 1
)
type Button struct {
label string
x int
y int
id int
}
func NewButton(label string, x int, y int, id int) Button {
return Button{
label: label,
x: x,
y: y,
id: id,
}
}
func (button *Button) make() {
kos.CreateButton(button.x, button.y, len(button.label)*15, 30, button.id, colors.Blue)
kos.WriteText(button.x, button.y, 0x11000000|colors.White, button.label)
}
func RedrawAll(barPos int) {
kos.Redraw(1)
kos.Window(500, 250, 420, 200, "GoLang")
kos.DrawLine(32, 80, 150, 80, colors.Green)
kos.DrawBar(barPos, 90, 100, 30, colors.Red)
str1 := "123"
str2 := "222"
if str1 == str2 || str2 == "222" {
kos.WriteText(50,50,0,"==")
} else {
kos.WriteText(50,50,0,"!=")
}
b1 := NewButton(" <- ", 32, 128, Btn1)
b1.make()
b2 := NewButton(" -> ", 310, 128, Btn2)
b2.make()
}
func Main() {
pos := 160
for {
switch kos.Event() {
case kos.EVENT_REDRAW:
RedrawAll(pos)
case kos.EVENT_BUTTON:
switch kos.GetButtonID() {
case Btn1:
pos -= 32
RedrawAll(pos)
case Btn2:
pos += 32
RedrawAll(pos)
case BtnExit:
kos.Exit()
}
}
}
}