Created
July 17, 2024 14:27
-
-
Save gesellix/df55e71bc20e870320cd1c74a962bd68 to your computer and use it in GitHub Desktop.
Gioui reproducer for https://todo.sr.ht/~eliasnaur/gio/602
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module demo | |
go 1.22 | |
require gioui.org v0.7.1 | |
require ( | |
gioui.org/cpu v0.0.0-20220412190645-f1e9e8c3b1f7 // indirect | |
gioui.org/shader v1.0.8 // indirect | |
github.com/go-text/typesetting v0.1.1 // indirect | |
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 // indirect | |
golang.org/x/exp/shiny v0.0.0-20240707233637-46b078467d37 // indirect | |
golang.org/x/image v0.18.0 // indirect | |
golang.org/x/sys v0.22.0 // indirect | |
golang.org/x/text v0.16.0 // indirect | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"gioui.org/io/system" | |
"image/color" | |
"log" | |
"os" | |
"gioui.org/app" | |
"gioui.org/op" | |
"gioui.org/text" | |
"gioui.org/widget/material" | |
) | |
func main() { | |
go func() { | |
window := new(app.Window) | |
window.Perform(system.ActionCenter) | |
err := run(window) | |
if err != nil { | |
log.Fatal(err) | |
} | |
os.Exit(0) | |
}() | |
app.Main() | |
} | |
func run(window *app.Window) error { | |
theme := material.NewTheme() | |
var ops op.Ops | |
for { | |
switch e := window.Event().(type) { | |
case app.DestroyEvent: | |
return e.Err | |
case app.FrameEvent: | |
// This graphics context is used for managing the rendering state. | |
gtx := app.NewContext(&ops, e) | |
// Define an large label with an appropriate text: | |
title := material.H1(theme, "Hello, Gio") | |
// Change the color of the label. | |
maroon := color.NRGBA{R: 127, G: 0, B: 0, A: 255} | |
title.Color = maroon | |
// Change the position of the label. | |
title.Alignment = text.Middle | |
// Draw the label to the graphics context. | |
title.Layout(gtx) | |
// Pass the drawing operations to the GPU. | |
e.Frame(gtx.Ops) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment