forked from mbk-lab/rui_orig
2
0
Fork 0

Changed the main TimePicker listener

This commit is contained in:
anoshenko 2023-04-23 18:54:53 +03:00
parent 4e7dd37f6a
commit f3c9bf7f56
3 changed files with 33 additions and 16 deletions

View File

@ -3286,13 +3286,21 @@ DateChangedEvent). Основной слушатель события имее
Для отслеживания изменения вводимого значения используется событие "time-changed" (константа Для отслеживания изменения вводимого значения используется событие "time-changed" (константа
TimeChangedEvent). Основной слушатель события имеет следующий формат: TimeChangedEvent). Основной слушатель события имеет следующий формат:
func(picker TimePicker, newTime time.Time) func(picker TimePicker, newTime, oldTime time.Time)
где второй аргумент это новое значение времени где второй аргумент это новое значение времени, третий аргумент - предыдущее значение времени.
Дополнительные слушатели события могут иметь следующий формат
func(picker TimePicker, newTime time.Time)
func(newTime, oldTime time.Time)
func(newTime time.Time)
func(picker TimePicker)
func()
Получить текущий список слушателей изменения даты можно с помощью функции Получить текущий список слушателей изменения даты можно с помощью функции
func GetTimeChangedListeners(view View, subviewID ...string) []func(TimePicker, time.Time) func GetTimeChangedListeners(view View, subviewID ...string) []func(TimePicker, time.Time, time.Time)
## ColorPicker ## ColorPicker

View File

@ -3251,13 +3251,21 @@ You can read the values of these properties using the functions:
The "time-changed" event (TimeChangedEvent constant) is used to track the change in the entered value. The "time-changed" event (TimeChangedEvent constant) is used to track the change in the entered value.
The main event listener has the following format: The main event listener has the following format:
func(picker TimePicker, newTime time.Time) func(picker TimePicker, newTime, oldTime time.Time)
where the second argument is the new time value where the second argument is the new time value, the third argument is the previous time value.
Additional event listeners can have the following format
func(picker TimePicker, newTime time.Time)
func(newTime, oldTime time.Time)
func(newTime time.Time)
func(picker TimePicker)
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 GetTimeChangedListeners(view View, subviewID ...string) []func(TimePicker, time.Time) func GetTimeChangedListeners(view View, subviewID ...string) []func(TimePicker, time.Time, time.Time)
## ColorPicker ## ColorPicker

View File

@ -22,7 +22,7 @@ type TimePicker interface {
type timePickerData struct { type timePickerData struct {
viewData viewData
timeChangedListeners []func(TimePicker, time.Time) timeChangedListeners []func(TimePicker, time.Time, time.Time)
} }
// NewTimePicker create new TimePicker object and return it // NewTimePicker create new TimePicker object and return it
@ -40,7 +40,7 @@ func newTimePicker(session Session) View {
func (picker *timePickerData) init(session Session) { func (picker *timePickerData) init(session Session) {
picker.viewData.init(session) picker.viewData.init(session)
picker.tag = "TimePicker" picker.tag = "TimePicker"
picker.timeChangedListeners = []func(TimePicker, time.Time){} picker.timeChangedListeners = []func(TimePicker, time.Time, time.Time){}
} }
func (picker *timePickerData) String() string { func (picker *timePickerData) String() string {
@ -69,7 +69,7 @@ func (picker *timePickerData) remove(tag string) {
switch tag { switch tag {
case TimeChangedEvent: case TimeChangedEvent:
if len(picker.timeChangedListeners) > 0 { if len(picker.timeChangedListeners) > 0 {
picker.timeChangedListeners = []func(TimePicker, time.Time){} picker.timeChangedListeners = []func(TimePicker, time.Time, time.Time){}
picker.propertyChangedEvent(tag) picker.propertyChangedEvent(tag)
} }
return return
@ -94,13 +94,14 @@ func (picker *timePickerData) remove(tag string) {
case TimePickerValue: case TimePickerValue:
if _, ok := picker.properties[TimePickerValue]; ok { if _, ok := picker.properties[TimePickerValue]; ok {
oldTime := GetTimePickerValue(picker)
delete(picker.properties, TimePickerValue) delete(picker.properties, TimePickerValue)
time := GetTimePickerValue(picker) time := GetTimePickerValue(picker)
if picker.created { if picker.created {
picker.session.callFunc("setInputValue", picker.htmlID(), time.Format(timeFormat)) picker.session.callFunc("setInputValue", picker.htmlID(), time.Format(timeFormat))
} }
for _, listener := range picker.timeChangedListeners { for _, listener := range picker.timeChangedListeners {
listener(picker, time) listener(picker, time, oldTime)
} }
} else { } else {
return return
@ -214,7 +215,7 @@ func (picker *timePickerData) set(tag string, value any) bool {
picker.session.callFunc("setInputValue", picker.htmlID(), time.Format(timeFormat)) picker.session.callFunc("setInputValue", picker.htmlID(), time.Format(timeFormat))
} }
for _, listener := range picker.timeChangedListeners { for _, listener := range picker.timeChangedListeners {
listener(picker, time) listener(picker, time, oldTime)
} }
picker.propertyChangedEvent(tag) picker.propertyChangedEvent(tag)
} }
@ -222,12 +223,12 @@ func (picker *timePickerData) set(tag string, value any) bool {
} }
case TimeChangedEvent: case TimeChangedEvent:
listeners, ok := valueToEventListeners[TimePicker, time.Time](value) listeners, ok := valueToEventWithOldListeners[TimePicker, time.Time](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(TimePicker, time.Time){} listeners = []func(TimePicker, time.Time, time.Time){}
} }
picker.timeChangedListeners = listeners picker.timeChangedListeners = listeners
picker.propertyChangedEvent(tag) picker.propertyChangedEvent(tag)
@ -306,7 +307,7 @@ func (picker *timePickerData) handleCommand(self View, command string, data Data
picker.properties[TimePickerValue] = value picker.properties[TimePickerValue] = value
if value != oldValue { if value != oldValue {
for _, listener := range picker.timeChangedListeners { for _, listener := range picker.timeChangedListeners {
listener(picker, value) listener(picker, value, oldValue)
} }
} }
} }
@ -398,6 +399,6 @@ func GetTimePickerValue(view View, subviewID ...string) time.Time {
// GetTimeChangedListeners returns the TimeChangedListener list of an TimePicker subview. // GetTimeChangedListeners returns the TimeChangedListener list of an TimePicker 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 GetTimeChangedListeners(view View, subviewID ...string) []func(TimePicker, time.Time) { func GetTimeChangedListeners(view View, subviewID ...string) []func(TimePicker, time.Time, time.Time) {
return getEventListeners[TimePicker, time.Time](view, subviewID, TimeChangedEvent) return getEventWithOldListeners[TimePicker, time.Time](view, subviewID, TimeChangedEvent)
} }