-
-
Save inkeliz/ec4e95c7397a2ac166d58205e824e226 to your computer and use it in GitHub Desktop.
Revisions
-
inkeliz revised this gist
Oct 5, 2021 . 1 changed file with 10 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -52,7 +52,15 @@ func loop(w *app.Window) { Right: unit.Dp(25), Left: unit.Dp(25), }.Layout(gtx, func(gtx C) D { // Option 1: // gtx.Constraints.Min = image.Point{} // paint.FillShape(gtx.Ops, color.NRGBA{G: 255, A: 255}, clip.Rect(gtx.Constraints).Op()) // Option 2: paint.FillShape(gtx.Ops, color.NRGBA{G: 255, A: 255}, clip.Rect{Max: gtx.Constraints.Max}.Op()) // Remain unchanged: return layout.Dimensions{Size: gtx.Constraints.Max} }) }, @@ -98,4 +106,4 @@ func main() { app.MinSize(unit.Dp(230), unit.Dp(200)), )) app.Main() } -
chmike revised this gist
Oct 5, 2021 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -55,7 +55,8 @@ func loop(w *app.Window) { paint.FillShape(gtx.Ops, color.NRGBA{G: 255}, clip.Rect(gtx.Constraints).Op()) return layout.Dimensions{Size: gtx.Constraints.Max} }) }, ), layout.Rigid( func(gtx C) D { return layout.Inset{ -
chmike created this gist
Oct 5, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,100 @@ package main import ( "fmt" "image/color" "os" "gioui.org/app" "gioui.org/font/gofont" "gioui.org/io/system" "gioui.org/layout" "gioui.org/op" "gioui.org/op/clip" "gioui.org/op/paint" "gioui.org/unit" "gioui.org/widget" "gioui.org/widget/material" ) type C = layout.Context type D = layout.Dimensions func loop(w *app.Window) { th := material.NewTheme(gofont.Collection()) var okButton, cancelButton widget.Clickable var ops op.Ops for e := range w.Events() { switch e := e.(type) { case system.DestroyEvent: if e.Err != nil { panic(e.Err) } os.Exit(0) return case system.FrameEvent: if okButton.Clicked() { fmt.Println("clicked ok") } gtx := layout.NewContext(&ops, e) layout.Flex{ Axis: layout.Vertical, Spacing: layout.SpaceStart, }.Layout(gtx, layout.Flexed(50, func(gtx C) D { return layout.Inset{ Top: unit.Dp(25), Bottom: unit.Dp(0), Right: unit.Dp(25), Left: unit.Dp(25), }.Layout(gtx, func(gtx C) D { paint.FillShape(gtx.Ops, color.NRGBA{G: 255}, clip.Rect(gtx.Constraints).Op()) return layout.Dimensions{Size: gtx.Constraints.Max} }) }), layout.Rigid( func(gtx C) D { return layout.Inset{ Top: unit.Dp(25), Bottom: unit.Dp(25), Right: unit.Dp(25), Left: unit.Dp(25), }.Layout(gtx, func(gtx C) D { btnWidth := gtx.Px(unit.Dp(80)) return layout.Flex{ Alignment: layout.Middle, Spacing: layout.SpaceBetween, }.Layout(gtx, layout.Rigid(func(gtx C) D { gtx.Constraints.Min.X = btnWidth return material.Button(th, &cancelButton, "Cancel").Layout(gtx) }), layout.Rigid(func(gtx C) D { gtx.Queue = nil // disable button gtx.Constraints.Min.X = btnWidth return material.Button(th, &okButton, "OK").Layout(gtx) }), ) }, ) }, ), ) e.Frame(gtx.Ops) } } } func main() { go loop(app.NewWindow( app.Title("Example"), app.Size(unit.Dp(400), unit.Dp(600)), app.MinSize(unit.Dp(230), unit.Dp(200)), )) app.Main() }