Add ColorOpt to giowrap.Label.

This commit is contained in:
Greg 2019-08-22 18:15:14 -04:00
parent 014ace99a6
commit 62d0ceef66

View File

@ -86,11 +86,13 @@ func Align(x text.Alignment) AlignOpt { return AlignOpt { x } }
type LabelOpts struct {
FaceOpt
c *color.RGBA
AlignOpt
}
type LabelOption interface { DoLabelOption(*LabelOpts) }
func (x FaceOpt) DoLabelOption(o *LabelOpts) { o.face = x.face }
func (x AlignOpt) DoLabelOption(o *LabelOpts) { o.alignment = x.alignment }
func (x ColorOpt) DoLabelOption(o *LabelOpts) { o.c = &x.c; }
func NewLabel(t string, lops ...LabelOption) *Label {
ret := &Label{}
@ -101,6 +103,12 @@ func NewLabel(t string, lops ...LabelOption) *Label {
Text: t,
Alignment: opts.alignment,
}
if opts.c != nil { // got a color option...
ops := new(ui.Ops)
ret.l.Material.Record(ops)
paint.ColorOp{Color: *opts.c}.Add(ops)
ret.l.Material.Stop()
}
return ret
}