Changed the main ColorPicker listener

This commit is contained in:
anoshenko 2023-04-23 18:27:04 +03:00
parent 2a480cc6ac
commit 763de29698
3 changed files with 32 additions and 16 deletions

View File

@ -3300,13 +3300,21 @@ TimeChangedEvent). Основной слушатель события имее
Для отслеживания изменения выбранного цвета используется событие "color-changed" (константа Для отслеживания изменения выбранного цвета используется событие "color-changed" (константа
ColorChangedEvent). Основной слушатель события имеет следующий формат: ColorChangedEvent). Основной слушатель события имеет следующий формат:
func(picker ColorPicker, newColor Color) func(picker ColorPicker, newColor, oldColor Color)
где второй аргумент это новое значение цвета где второй аргумент это новое значение цвета, третий аргумент - предыдущее значение цвета.
Дополнительные слушатели события могут иметь следующий формат
func(picker ColorPicker, newColor string)
func(newColor, oldColor string)
func(newColor string)
func(picker ColorPicker)
func()
Получить текущий список слушателей изменения даты можно с помощью функции Получить текущий список слушателей изменения даты можно с помощью функции
func GetColorChangedListeners(view View, subviewID ...string) []func(ColorPicker, Color) func GetColorChangedListeners(view View, subviewID ...string) []func(ColorPicker, Color, Color)
## FilePicker ## FilePicker

View File

@ -3073,7 +3073,7 @@ The main event listener has the following format:
func(EditView, string, string) func(EditView, string, string)
where the second argument is the new text value the third argument is the previous text value. where the second argument is the new text value, the third argument is the previous text value.
Additional event listeners can have the following format Additional event listeners can have the following format
@ -3265,13 +3265,21 @@ The value of the property "color-picker-value" can also be read using the functi
The "color-changed" event (ColorChangedEvent constant) is used to track the change in the selected color. The "color-changed" event (ColorChangedEvent constant) is used to track the change in the selected color.
The main event listener has the following format: The main event listener has the following format:
func(picker ColorPicker, newColor Color) func(picker ColorPicker, newColor, oldColor Color)
where the second argument is the new color value where the second argument is the new color value, the third argument is the previous color value.
Additional event listeners can have the following format
func(picker ColorPicker, newColor string)
func(newColor, oldColor string)
func(newColor string)
func(picker ColorPicker)
func()
You can get the current list of date change listeners using the function You can get the current list of date change listeners using the function
func GetColorChangedListeners(view View, subviewID ...string) []func(ColorPicker, Color) func GetColorChangedListeners(view View, subviewID ...string) []func(ColorPicker, Color, Color)
## FilePicker ## FilePicker

View File

@ -16,7 +16,7 @@ type ColorPicker interface {
type colorPickerData struct { type colorPickerData struct {
viewData viewData
colorChangedListeners []func(ColorPicker, Color) colorChangedListeners []func(ColorPicker, Color, Color)
} }
// NewColorPicker create new ColorPicker object and return it // NewColorPicker create new ColorPicker object and return it
@ -34,7 +34,7 @@ func newColorPicker(session Session) View {
func (picker *colorPickerData) init(session Session) { func (picker *colorPickerData) init(session Session) {
picker.viewData.init(session) picker.viewData.init(session)
picker.tag = "ColorPicker" picker.tag = "ColorPicker"
picker.colorChangedListeners = []func(ColorPicker, Color){} picker.colorChangedListeners = []func(ColorPicker, Color, Color){}
picker.properties[Padding] = Px(0) picker.properties[Padding] = Px(0)
} }
@ -60,7 +60,7 @@ func (picker *colorPickerData) remove(tag string) {
switch tag { switch tag {
case ColorChangedEvent: case ColorChangedEvent:
if len(picker.colorChangedListeners) > 0 { if len(picker.colorChangedListeners) > 0 {
picker.colorChangedListeners = []func(ColorPicker, Color){} picker.colorChangedListeners = []func(ColorPicker, Color, Color){}
picker.propertyChangedEvent(tag) picker.propertyChangedEvent(tag)
} }
@ -86,12 +86,12 @@ func (picker *colorPickerData) set(tag string, value any) bool {
switch tag { switch tag {
case ColorChangedEvent: case ColorChangedEvent:
listeners, ok := valueToEventListeners[ColorPicker, Color](value) listeners, ok := valueToEventWithOldListeners[ColorPicker, Color](value)
if !ok { if !ok {
notCompatibleType(tag, value) notCompatibleType(tag, value)
return false return false
} else if listeners == nil { } else if listeners == nil {
listeners = []func(ColorPicker, Color){} listeners = []func(ColorPicker, Color, Color){}
} }
picker.colorChangedListeners = listeners picker.colorChangedListeners = listeners
picker.propertyChangedEvent(tag) picker.propertyChangedEvent(tag)
@ -116,7 +116,7 @@ func (picker *colorPickerData) colorChanged(oldColor Color) {
picker.session.callFunc("setInputValue", picker.htmlID(), newColor.rgbString()) picker.session.callFunc("setInputValue", picker.htmlID(), newColor.rgbString())
} }
for _, listener := range picker.colorChangedListeners { for _, listener := range picker.colorChangedListeners {
listener(picker, newColor) listener(picker, newColor, oldColor)
} }
picker.propertyChangedEvent(ColorTag) picker.propertyChangedEvent(ColorTag)
} }
@ -169,7 +169,7 @@ func (picker *colorPickerData) handleCommand(self View, command string, data Dat
picker.properties[ColorPickerValue] = color picker.properties[ColorPickerValue] = color
if color != oldColor { if color != oldColor {
for _, listener := range picker.colorChangedListeners { for _, listener := range picker.colorChangedListeners {
listener(picker, color) listener(picker, color, oldColor)
} }
} }
} }
@ -204,6 +204,6 @@ func GetColorPickerValue(view View, subviewID ...string) Color {
// GetColorChangedListeners returns the ColorChangedListener list of an ColorPicker subview. // GetColorChangedListeners returns the ColorChangedListener list of an ColorPicker subview.
// If there are no listeners then the empty list is returned // If there are no listeners then the empty list is returned
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned. // If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetColorChangedListeners(view View, subviewID ...string) []func(ColorPicker, Color) { func GetColorChangedListeners(view View, subviewID ...string) []func(ColorPicker, Color, Color) {
return getEventListeners[ColorPicker, Color](view, subviewID, ColorChangedEvent) return getEventWithOldListeners[ColorPicker, Color](view, subviewID, ColorChangedEvent)
} }