Beispiel #1
0
func NewColorPicker(parent Widget, colors ...nanovgo.Color) *ColorPicker {
	var color nanovgo.Color
	switch len(colors) {
	case 0:
		color = nanovgo.RGBAf(1.0, 0.0, 0.0, 1.0)
	case 1:
		color = colors[0]
	default:
		panic("NewColorPicker can accept only one extra parameter (color)")
	}

	colorPicker := &ColorPicker{}

	// init PopupButton member
	colorPicker.chevronIcon = IconRightOpen
	colorPicker.SetIconPosition(ButtonIconLeftCentered)
	colorPicker.SetFlags(ToggleButtonType | PopupButtonType)
	parentWindow := parent.FindWindow()

	colorPicker.popup = NewPopup(parentWindow.Parent(), parentWindow)
	colorPicker.popup.panel.SetLayout(NewGroupLayout())

	colorPicker.colorWheel = NewColorWheel(colorPicker.popup.panel)

	colorPicker.pickButton = NewButton(colorPicker.popup.panel, "Pick")
	colorPicker.pickButton.SetFixedSize(100, 25)

	InitWidget(colorPicker, parent)

	colorPicker.SetColor(color)

	colorPicker.PopupButton.SetChangeCallback(func(flag bool) {
		colorPicker.SetColor(colorPicker.BackgroundColor())
		if colorPicker.callback != nil {
			colorPicker.callback(colorPicker.BackgroundColor())
		}
	})

	colorPicker.colorWheel.SetCallback(func(color nanovgo.Color) {
		colorPicker.pickButton.SetBackgroundColor(color)
		colorPicker.pickButton.SetTextColor(color.ContrastingColor())
	})

	colorPicker.pickButton.SetCallback(func() {
		color := colorPicker.colorWheel.Color()
		colorPicker.SetPushed(false)
		colorPicker.SetColor(color)
		if colorPicker.callback != nil {
			colorPicker.callback(colorPicker.BackgroundColor())
		}
	})

	return colorPicker
}
Beispiel #2
0
func NewColorWheel(parent Widget, colors ...nanovgo.Color) *ColorWheel {
	var color nanovgo.Color
	switch len(colors) {
	case 0:
		color = nanovgo.RGBAf(1.0, 0.0, 0.0, 1.0)
	case 1:
		color = colors[0]
	default:
		panic("NewColorWheel can accept only one extra parameter (color)")
	}
	colorWheel := &ColorWheel{
		dragRegion: RegionNone,
	}
	InitWidget(colorWheel, parent)
	colorWheel.SetColor(color)
	return colorWheel
}