mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
app/hello: add explicit WindowOptions, extract message, color text
Signed-off-by: Anthony Starks <ajstarks@gmail.com> Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+6
-5
@@ -20,8 +20,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := app.CreateWindow(nil)
|
wopt := app.WindowOptions{Width: ui.Px(612), Height: ui.Px(792), Title: "Hello"}
|
||||||
if err != nil {
|
if err := app.CreateWindow(&wopt); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
app.Main()
|
app.Main()
|
||||||
@@ -43,15 +43,16 @@ func loop(w *app.Window) {
|
|||||||
panic("failed to load font")
|
panic("failed to load font")
|
||||||
}
|
}
|
||||||
var faces measure.Faces
|
var faces measure.Faces
|
||||||
black := &image.Uniform{color.Black}
|
maroon := &image.Uniform{color.RGBA{127, 0, 0, 255}}
|
||||||
face := faces.For(regular, ui.Dp(50))
|
face := faces.For(regular, ui.Sp(72))
|
||||||
|
message := "Hello, Gio"
|
||||||
for w.IsAlive() {
|
for w.IsAlive() {
|
||||||
e := <-w.Events()
|
e := <-w.Events()
|
||||||
switch e := e.(type) {
|
switch e := e.(type) {
|
||||||
case app.Draw:
|
case app.Draw:
|
||||||
faces.Cfg = e.Config
|
faces.Cfg = e.Config
|
||||||
cs := layout.ExactConstraints(w.Size())
|
cs := layout.ExactConstraints(w.Size())
|
||||||
root, _ := (text.Label{Src: black, Face: face, Text: "Hello, World!"}).Layout(cs)
|
root, _ := (text.Label{Src: maroon, Face: face, Alignment: text.Center, Text: message}).Layout(cs)
|
||||||
w.Draw(root)
|
w.Draw(root)
|
||||||
faces.Frame()
|
faces.Frame()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user