mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
example/kitchen: add ProgressBar example
Updates the kitchen example codebase showing ProgressBar functionality. Signed-off-by: metaclips <utimichael9@gmail.com>
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ module gioui.org/example
|
|||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gioui.org v0.0.0-20200401111706-a08674dbcaca
|
gioui.org v0.0.0-20200402190513-da01fbdea784
|
||||||
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7
|
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7
|
||||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72
|
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72
|
||||||
github.com/google/go-github/v24 v24.0.1
|
github.com/google/go-github/v24 v24.0.1
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||||
gioui.org v0.0.0-20200401111706-a08674dbcaca h1:3yyshrXY2S0bXVRpzm2agRLzKnuwSDRCedi67WwqalQ=
|
gioui.org v0.0.0-20200402190513-da01fbdea784 h1:gH0+2HCtuzxAdK6sd0BeCxZLAkCbhptF607odwS5QY0=
|
||||||
gioui.org v0.0.0-20200401111706-a08674dbcaca/go.mod h1:AHI9rFr6AEEHCb8EPVtb/p5M+NMJRKH58IOp8O3Je04=
|
gioui.org v0.0.0-20200402190513-da01fbdea784/go.mod h1:AHI9rFr6AEEHCb8EPVtb/p5M+NMJRKH58IOp8O3Je04=
|
||||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||||
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw=
|
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw=
|
||||||
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
|
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
|
||||||
|
|||||||
+37
-13
@@ -48,6 +48,7 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
icon = ic
|
icon = ic
|
||||||
|
progressIncrementer = make(chan int)
|
||||||
gofont.Register()
|
gofont.Register()
|
||||||
if *screenshot != "" {
|
if *screenshot != "" {
|
||||||
if err := saveScreenshot(*screenshot); err != nil {
|
if err := saveScreenshot(*screenshot); err != nil {
|
||||||
@@ -56,8 +57,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
w := app.NewWindow()
|
for {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
progressIncrementer <- 10
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
w := app.NewWindow(app.Size(unit.Dp(800), unit.Dp(650)))
|
||||||
if err := loop(w); err != nil {
|
if err := loop(w); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -91,15 +100,24 @@ func saveScreenshot(f string) error {
|
|||||||
func loop(w *app.Window) error {
|
func loop(w *app.Window) error {
|
||||||
th := material.NewTheme()
|
th := material.NewTheme()
|
||||||
gtx := layout.NewContext(w.Queue())
|
gtx := layout.NewContext(w.Queue())
|
||||||
|
|
||||||
for {
|
for {
|
||||||
e := <-w.Events()
|
select {
|
||||||
switch e := e.(type) {
|
case e := <-w.Events():
|
||||||
case system.DestroyEvent:
|
switch e := e.(type) {
|
||||||
return e.Err
|
case system.DestroyEvent:
|
||||||
case system.FrameEvent:
|
return e.Err
|
||||||
gtx.Reset(e.Config, e.Size)
|
case system.FrameEvent:
|
||||||
kitchen(gtx, th)
|
gtx.Reset(e.Config, e.Size)
|
||||||
e.Frame(gtx.Ops)
|
kitchen(gtx, th)
|
||||||
|
e.Frame(gtx.Ops)
|
||||||
|
}
|
||||||
|
case p := <-progressIncrementer:
|
||||||
|
progress += p
|
||||||
|
if progress > 100 {
|
||||||
|
progress = 0
|
||||||
|
}
|
||||||
|
w.Invalidate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,10 +136,12 @@ var (
|
|||||||
list = &layout.List{
|
list = &layout.List{
|
||||||
Axis: layout.Vertical,
|
Axis: layout.Vertical,
|
||||||
}
|
}
|
||||||
green = true
|
progress = 0
|
||||||
topLabel = "Hello, Gio"
|
progressIncrementer chan int
|
||||||
icon *material.Icon
|
green = true
|
||||||
checkbox = new(widget.CheckBox)
|
topLabel = "Hello, Gio"
|
||||||
|
icon *material.Icon
|
||||||
|
checkbox = new(widget.CheckBox)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (b iconAndTextButton) Layout(gtx *layout.Context, button *widget.Button, icon *material.Icon, word string) {
|
func (b iconAndTextButton) Layout(gtx *layout.Context, button *widget.Button, icon *material.Icon, word string) {
|
||||||
@@ -204,6 +224,9 @@ func kitchen(gtx *layout.Context, th *material.Theme) {
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
func() {
|
||||||
|
th.ProgressBar().Layout(gtx, progress)
|
||||||
|
},
|
||||||
func() {
|
func() {
|
||||||
th.CheckBox("Checkbox").Layout(gtx, checkbox)
|
th.CheckBox("Checkbox").Layout(gtx, checkbox)
|
||||||
},
|
},
|
||||||
@@ -221,6 +244,7 @@ func kitchen(gtx *layout.Context, th *material.Theme) {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
list.Layout(gtx, len(widgets), func(i int) {
|
list.Layout(gtx, len(widgets), func(i int) {
|
||||||
layout.UniformInset(unit.Dp(16)).Layout(gtx, widgets[i])
|
layout.UniformInset(unit.Dp(16)).Layout(gtx, widgets[i])
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user