Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ilidemi/14968570222b105a50554550c54d9f67 to your computer and use it in GitHub Desktop.
Save ilidemi/14968570222b105a50554550c54d9f67 to your computer and use it in GitHub Desktop.
gioui spacer bug
module spacerbug
go 1.18
require (
eliasnaur.com/font v0.0.0-20230308162249-dd43949cb42d
gioui.org v0.0.0-20230323230643-51b11486c5b8
// gioui.org v0.0.0-20230323230841-d7b1c7c33b33
)
require (
gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 // indirect
gioui.org/shader v1.0.6 // indirect
github.com/benoitkugler/textlayout v0.3.0 // indirect
github.com/go-text/typesetting v0.0.0-20221214153724-0399769901d5 // indirect
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 // indirect
golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 // indirect
golang.org/x/image v0.0.0-20220722155232-062f8c9fd539 // indirect
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 // indirect
golang.org/x/text v0.7.0 // indirect
)
package main
import (
"image/color"
"log"
"os"
"gioui.org/app"
"gioui.org/font/gofont"
"gioui.org/io/system"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/unit"
"gioui.org/widget"
"gioui.org/widget/material"
)
type C = layout.Context
type D = layout.Dimensions
func main() {
go func() {
w := app.NewWindow(
app.Title("Test"),
app.Size(unit.Dp(512), unit.Dp(64)),
)
err := Run(w)
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}()
app.Main()
}
func Run(w *app.Window) error {
var ops op.Ops
th := material.NewTheme(gofont.Collection())
red := color.NRGBA{R: 255, A: 255}
lightGray := color.NRGBA{192, 192, 192, 255}
for e := range w.Events() {
switch e := e.(type) {
case system.FrameEvent:
gtx := layout.NewContext(&ops, e)
layout.UniformInset(unit.Dp(12)).Layout(gtx, func(gtx C) D {
return layout.Flex{
Axis: layout.Horizontal,
Alignment: layout.Baseline,
}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return widget.Border{
Color: lightGray,
Width: 1,
}.Layout(gtx, func(gtx C) D {
return layout.UniformInset(unit.Dp(8)).Layout(gtx, func(gtx C) D {
return material.Label(th, unit.Sp(16), "Left").Layout(gtx)
})
})
}),
layout.Rigid(func(gtx C) D {
return widget.Border{
Color: red,
Width: 1,
}.Layout(gtx, func(gtx C) D {
return layout.Spacer{Width: unit.Dp(12)}.Layout(gtx)
})
}),
layout.Rigid(func(gtx C) D {
return widget.Border{
Color: lightGray,
Width: 1,
}.Layout(gtx, func(gtx C) D {
return layout.UniformInset(unit.Dp(8)).Layout(gtx, func(gtx C) D {
return material.Label(th, unit.Sp(16), "Right").Layout(gtx)
})
})
}),
)
})
e.Frame(gtx.Ops)
case system.DestroyEvent:
return e.Err
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment