Debian Codegraph @

shiny/widget/uniform.go

raw symbols SCIP
1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package widget
6
7 import (
8 "image"
9 "image/draw"
10
11 "golang.org/x/exp/shiny/widget/node"
12 "golang.org/x/exp/shiny/widget/theme"
13 )
14
15 // Uniform is a shell widget that paints a uniform color, analogous to an
16 // image.Uniform.
17 type Uniform struct {
18 node.ShellEmbed
19 ThemeColor theme.Color
20 }
21
22 // NewUniform returns a new Uniform widget of the given color.
23 func NewUniform(c theme.Color, inner node.Node) *Uniform {
24 w := &Uniform{
25 ThemeColor: c,
26 }
27 w.Wrapper = w
28 if inner != nil {
29 w.Insert(inner, nil)
30 }
31 return w
32 }
33
34 func (w *Uniform) PaintBase(ctx *node.PaintBaseContext, origin image.Point) error {
35 w.Marks.UnmarkNeedsPaintBase()
36 if w.ThemeColor != nil {
37 src := w.ThemeColor.Uniform(ctx.Theme)
38 // TODO: should draw.Src be draw.Over?
39 draw.Draw(ctx.Dst, w.Rect.Add(origin), src, image.Point{}, draw.Src)
40 }
41 if c := w.FirstChild; c != nil {
42 return c.Wrapper.PaintBase(ctx, origin.Add(w.Rect.Min))
43 }
44 return nil
45 }