Skip to content

Instantly share code, notes, and snippets.

@inkeliz
Forked from chmike/GIOExample1.go
Last active October 5, 2021 15:32
Show Gist options
  • Select an option

  • Save inkeliz/ec4e95c7397a2ac166d58205e824e226 to your computer and use it in GitHub Desktop.

Select an option

Save inkeliz/ec4e95c7397a2ac166d58205e824e226 to your computer and use it in GitHub Desktop.

Revisions

  1. inkeliz revised this gist Oct 5, 2021. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions GIOExample1.go
    Original 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 {
    paint.FillShape(gtx.Ops, color.NRGBA{G: 255}, clip.Rect(gtx.Constraints).Op())
    // 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()
    }
    }
  2. @chmike chmike revised this gist Oct 5, 2021. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion GIOExample1.go
    Original 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{
  3. @chmike chmike created this gist Oct 5, 2021.
    100 changes: 100 additions & 0 deletions GIOExample1.go
    Original 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()
    }