| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 16 |
|
| 17 |
type Uniform struct { |
| 18 |
node.ShellEmbed |
| 19 |
ThemeColor theme.Color |
| 20 |
} |
| 21 |
|
| 22 |
|
| 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 |
|
| 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 |
} |