| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
package main |
| 15 |
|
| 16 |
import ( |
| 17 |
"image" |
| 18 |
"image/color" |
| 19 |
"image/draw" |
| 20 |
"log" |
| 21 |
|
| 22 |
"golang.org/x/exp/shiny/driver" |
| 23 |
"golang.org/x/exp/shiny/gesture" |
| 24 |
"golang.org/x/exp/shiny/screen" |
| 25 |
"golang.org/x/exp/shiny/widget" |
| 26 |
"golang.org/x/exp/shiny/widget/node" |
| 27 |
) |
| 28 |
|
| 29 |
var uniforms = [...]*image.Uniform{ |
| 30 |
image.NewUniform(color.RGBA{0xbf, 0x00, 0x00, 0xff}), |
| 31 |
image.NewUniform(color.RGBA{0x9f, 0x9f, 0x00, 0xff}), |
| 32 |
image.NewUniform(color.RGBA{0x00, 0xbf, 0x00, 0xff}), |
| 33 |
image.NewUniform(color.RGBA{0x00, 0x9f, 0x9f, 0xff}), |
| 34 |
image.NewUniform(color.RGBA{0x00, 0x00, 0xbf, 0xff}), |
| 35 |
image.NewUniform(color.RGBA{0x9f, 0x00, 0x9f, 0xff}), |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
type custom struct { |
| 40 |
node.LeafEmbed |
| 41 |
index int |
| 42 |
} |
| 43 |
|
| 44 |
func newCustom() *custom { |
| 45 |
w := &custom{} |
| 46 |
w.Wrapper = w |
| 47 |
return w |
| 48 |
} |
| 49 |
|
| 50 |
func (w *custom) OnInputEvent(e interface{}, origin image.Point) node.EventHandled { |
| 51 |
switch e := e.(type) { |
| 52 |
case gesture.Event: |
| 53 |
if e.Type != gesture.TypeTap { |
| 54 |
break |
| 55 |
} |
| 56 |
w.index++ |
| 57 |
if w.index == len(uniforms) { |
| 58 |
w.index = 0 |
| 59 |
} |
| 60 |
w.Mark(node.MarkNeedsPaintBase) |
| 61 |
} |
| 62 |
return node.Handled |
| 63 |
} |
| 64 |
|
| 65 |
func (w *custom) PaintBase(ctx *node.PaintBaseContext, origin image.Point) error { |
| 66 |
w.Marks.UnmarkNeedsPaintBase() |
| 67 |
draw.Draw(ctx.Dst, w.Rect.Add(origin), uniforms[w.index], image.Point{}, draw.Src) |
| 68 |
return nil |
| 69 |
} |
| 70 |
|
| 71 |
func main() { |
| 72 |
log.SetFlags(0) |
| 73 |
driver.Main(func(s screen.Screen) { |
| 74 |
|
| 75 |
w := widget.NewSheet(newCustom()) |
| 76 |
if err := widget.RunWindow(s, w, &widget.RunWindowOptions{ |
| 77 |
NewWindowOptions: screen.NewWindowOptions{ |
| 78 |
Title: "WidgetGallery Shiny Example", |
| 79 |
}, |
| 80 |
}); err != nil { |
| 81 |
log.Fatal(err) |
| 82 |
} |
| 83 |
}) |
| 84 |
} |