Color
A swatch that opens a color editor, or the editor in place.
Loading the live example…
import (
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
)
type brandColors struct {
primary, accent ui.Color
}
func (b *brandColors) View(c *ui.Context) {
t := c.Theme()
ui.Column(c).Gap(16).AlignItems(ui.Center).Children(func() {
ui.Row(c).Gap(12).AlignItems(ui.Center).Children(func() {
components.ColorPicker(c, &b.primary).Label("Primary color")
components.ColorPicker(c, &b.accent).Label("Accent color").
Size(40, 40).Radius(20).Padding(0)
})
ui.Box(c).Width(220).Height(40).Radius(t.Radius).
LinearGradient(ui.LinearGradient{From: b.primary, To: b.accent, Angle: 90})
})
}components.ColorPicker is a swatch that opens the editor in a popover. Change its shape with Size, Radius, Border and Padding.
Editor
components.ColorView edits a color in place: a saturation and brightness plane, hue and opacity sliders, and RGB, HSB or HSL fields with a hex field. Its menu copies the color as text.
Loading the live example…
import (
"github.com/egoist/mygo/ui"
"github.com/oneo-me/onevra/source/components"
)
type paint struct {
color ui.Color
}
func (p *paint) View(c *ui.Context) {
components.ColorView(c, &p.color).Label("Color")
}API
ColorPicker
func ColorPicker(c *ui.Context, value *ui.Color) *ColorControlColorPicker creates a rectangular color swatch opening ColorView in a dismissible Popover. Size, Border (stroke width/color), Radius and Padding can be customized on the returned Element. Use Label for its accessible name. Enter/Space activate; Escape/outside press dismiss. Changed reports edits, not opening/closing. Key or disable a parent, not the returned element.
pkg.go.devColorView
func ColorView(c *ui.Context, value *ui.Color) *ColorControlColorView edits an application-owned sRGB color in place. It includes a saturation/brightness plane, hue and opacity sliders, RGBA/HSBA/HSLA selection, RGB byte or HSB/HSL degree/percent fields, a six-digit Hex field (also accepts eight-digit RRGGBBAA), and opacity percent. Mode changes do not change the color or report Changed. The Copy color native menu copies RGBA, HSBA, HSLA or HEX text, including alpha. Numeric prefixes scrub horizontally by one unit per theme-scaled DIP and support arrow keys and Home/End. Hex uses a plain text field with a decorative prefix, without numeric stepping or scrubbing. Unsupported text is rejected; valid text applies immediately. Incomplete drafts survive while focused and reset on submission or blur. External changes replace drafts. Hue is retained through gray/black edits. RGB/HSV edits map wide-gamut inputs to sRGB; opacity-only edits preserve their gamut. Disable or key a parent before construction. The plane supports arrow keys; sliders retain MyGo keyboard/accessibility input.
pkg.go.devColorControl
ColorControl exposes layout and an input-driven Changed result. Keep this handle when applying Element layout methods, which return ui.Element.
Prop
Type
Methods
func (c *ColorControl) Changed() boolChanged reports a color value changed by input during this build.