2019-12-28 00:06:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.kirsle.net/go/render"
|
2020-03-10 00:32:28 +00:00
|
|
|
"git.kirsle.net/go/render/sdl"
|
2019-12-28 00:06:24 +00:00
|
|
|
"git.kirsle.net/go/ui"
|
|
|
|
)
|
|
|
|
|
2020-03-10 00:32:28 +00:00
|
|
|
func init() {
|
|
|
|
sdl.DefaultFontFilename = "../DejaVuSans.ttf"
|
|
|
|
}
|
|
|
|
|
2019-12-28 00:06:24 +00:00
|
|
|
func main() {
|
|
|
|
mw, err := ui.NewMainWindow("Hello World")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
mw.SetBackground(render.White)
|
|
|
|
|
|
|
|
// Draw a label.
|
|
|
|
label := ui.NewLabel(ui.Label{
|
|
|
|
Text: "Hello, world!",
|
|
|
|
Font: render.Text{
|
2020-03-10 00:32:28 +00:00
|
|
|
Size: 32,
|
|
|
|
Color: render.SkyBlue,
|
|
|
|
Shadow: render.SkyBlue.Darken(40),
|
2019-12-28 00:06:24 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
mw.Pack(label, ui.Pack{
|
2019-12-29 05:47:46 +00:00
|
|
|
Side: ui.N,
|
|
|
|
PadY: 12,
|
2019-12-28 00:06:24 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Draw a button.
|
|
|
|
button := ui.NewButton("My Button", ui.NewLabel(ui.Label{
|
|
|
|
Text: "Click me!",
|
|
|
|
Font: render.Text{
|
|
|
|
FontFilename: "../DejaVuSans.ttf",
|
|
|
|
Size: 12,
|
|
|
|
Color: render.Red,
|
|
|
|
Padding: 4,
|
|
|
|
},
|
|
|
|
}))
|
2020-03-10 00:13:33 +00:00
|
|
|
button.Handle(ui.Click, func(ed ui.EventData) {
|
2019-12-28 00:06:24 +00:00
|
|
|
fmt.Println("I've been clicked!")
|
|
|
|
})
|
|
|
|
mw.Pack(button, ui.Pack{
|
2019-12-29 05:47:46 +00:00
|
|
|
Side: ui.N,
|
2019-12-28 00:06:24 +00:00
|
|
|
})
|
|
|
|
|
2020-03-10 00:32:28 +00:00
|
|
|
// Add a mouse-over tooltip to the button.
|
|
|
|
ui.NewTooltip(button, ui.Tooltip{
|
|
|
|
Text: "You know you want to click this button",
|
|
|
|
Edge: ui.Right,
|
|
|
|
})
|
|
|
|
|
2019-12-28 00:06:24 +00:00
|
|
|
mw.MainLoop()
|
|
|
|
}
|