forked from mbk-lab/rui_orig
Changed the main NumberPicker listener
This commit is contained in:
parent
763de29698
commit
05fa725003
14
README-ru.md
14
README-ru.md
|
@ -3178,13 +3178,21 @@ NumberPicker может работать в двух режимах: редак
|
||||||
Для отслеживания изменения вводимого значения используется событие "number-changed" (константа
|
Для отслеживания изменения вводимого значения используется событие "number-changed" (константа
|
||||||
NumberChangedEvent). Основной слушатель события имеет следующий формат:
|
NumberChangedEvent). Основной слушатель события имеет следующий формат:
|
||||||
|
|
||||||
func(picker NumberPicker, newValue float64)
|
func(picker NumberPicker, newValue, oldValue float64)
|
||||||
|
|
||||||
где второй аргумент это новое значение
|
где второй аргумент это новое значение, третий аргумент - предыдущее значение.
|
||||||
|
|
||||||
|
Дополнительные слушатели события могут иметь следующий формат
|
||||||
|
|
||||||
|
func(picker NumberPicker, newValue string)
|
||||||
|
func(newValue, oldValue string)
|
||||||
|
func(newValue string)
|
||||||
|
func(picker NumberPicker)
|
||||||
|
func()
|
||||||
|
|
||||||
Получить текущий список слушателей изменения значения можно с помощью функции
|
Получить текущий список слушателей изменения значения можно с помощью функции
|
||||||
|
|
||||||
func GetNumberChangedListeners(view View, subviewID ...string) []func(NumberPicker, float64)
|
func GetNumberChangedListeners(view View, subviewID ...string) []func(NumberPicker, float64, float64)
|
||||||
|
|
||||||
## DatePicker
|
## DatePicker
|
||||||
|
|
||||||
|
|
30
README.md
30
README.md
|
@ -769,7 +769,7 @@ equivalent to
|
||||||
view.Set(rui.Border, NewBorder(rui.Params{
|
view.Set(rui.Border, NewBorder(rui.Params{
|
||||||
rui.Style : rui.SolidBorder,
|
rui.Style : rui.SolidBorder,
|
||||||
rui.Width : rui.Px(1),
|
rui.Width : rui.Px(1),
|
||||||
rui.ColorProperty: rui.Black,
|
rui.ColorTag: rui.Black,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
The BorderProperty interface can be converted to a ViewBorders structure using the Border function.
|
The BorderProperty interface can be converted to a ViewBorders structure using the Border function.
|
||||||
|
@ -833,7 +833,7 @@ equivalent to
|
||||||
view.Set(rui.Border, NewBorder(rui.Params{
|
view.Set(rui.Border, NewBorder(rui.Params{
|
||||||
rui.Style : rui.SolidBorder,
|
rui.Style : rui.SolidBorder,
|
||||||
rui.Width : rui.Px(1),
|
rui.Width : rui.Px(1),
|
||||||
rui.ColorProperty: rui.Black,
|
rui.ColorTag: rui.Black,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
### "outline" and "outline-offset" properties
|
### "outline" and "outline-offset" properties
|
||||||
|
@ -1012,7 +1012,7 @@ The shadow has the following properties:
|
||||||
|
|
||||||
| Property | Constant | Type | Description |
|
| Property | Constant | Type | Description |
|
||||||
|-----------------|---------------|----------|-----------------------------------------------------------------------|
|
|-----------------|---------------|----------|-----------------------------------------------------------------------|
|
||||||
| "color" | ColorProperty | Color | Shadow color |
|
| "color" | ColorTag | Color | Shadow color |
|
||||||
| "inset" | Inset | bool | true - the shadow inside the View, false - outside |
|
| "inset" | Inset | bool | true - the shadow inside the View, false - outside |
|
||||||
| "x-offset" | XOffset | SizeUnit | Offset the shadow along the X axis |
|
| "x-offset" | XOffset | SizeUnit | Offset the shadow along the X axis |
|
||||||
| "y-offset" | YOffset | SizeUnit | Offset the shadow along the Y axis |
|
| "y-offset" | YOffset | SizeUnit | Offset the shadow along the Y axis |
|
||||||
|
@ -1031,7 +1031,7 @@ The NewShadowWithParams function is used when constants must be used as paramete
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
shadow := NewShadowWithParams(rui.Params{
|
shadow := NewShadowWithParams(rui.Params{
|
||||||
rui.ColorProperty : "@shadowColor",
|
rui.ColorTag : "@shadowColor",
|
||||||
rui.BlurRadius: 8.0,
|
rui.BlurRadius: 8.0,
|
||||||
rui.Dilation : 16.0,
|
rui.Dilation : 16.0,
|
||||||
})
|
})
|
||||||
|
@ -1652,7 +1652,7 @@ To create a ViewShadow for the text shadow, the following functions are used:
|
||||||
The NewShadowWithParams function is used when constants must be used as parameters. For example:
|
The NewShadowWithParams function is used when constants must be used as parameters. For example:
|
||||||
|
|
||||||
shadow := NewShadowWithParams(rui.Params{
|
shadow := NewShadowWithParams(rui.Params{
|
||||||
rui.ColorProperty : "@shadowColor",
|
rui.ColorTag : "@shadowColor",
|
||||||
rui.BlurRadius: 8.0,
|
rui.BlurRadius: 8.0,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -2530,10 +2530,10 @@ The value of the "column-separator" property is stored as the ColumnSeparatorPro
|
||||||
which implements the Properties interface (see above). ColumnSeparatorProperty can contain the following properties:
|
which implements the Properties interface (see above). ColumnSeparatorProperty can contain the following properties:
|
||||||
|
|
||||||
| Property | Constant | Type | Description |
|
| Property | Constant | Type | Description |
|
||||||
|----------|---------------|----------|----------------|
|
|----------|-----------|----------|----------------|
|
||||||
| "style" | Style | int | Line style |
|
| "style" | Style | int | Line style |
|
||||||
| "width" | Width | SizeUnit | Line thickness |
|
| "width" | Width | SizeUnit | Line thickness |
|
||||||
| "color" | ColorProperty | Color | Line color |
|
| "color" | ColorTag | Color | Line color |
|
||||||
|
|
||||||
Line style can take the following values:
|
Line style can take the following values:
|
||||||
|
|
||||||
|
@ -2589,7 +2589,7 @@ equivalent to
|
||||||
view.Set(rui.ColumnSeparator, ColumnSeparatorProperty(rui.Params{
|
view.Set(rui.ColumnSeparator, ColumnSeparatorProperty(rui.Params{
|
||||||
rui.Style : rui.SolidBorder,
|
rui.Style : rui.SolidBorder,
|
||||||
rui.Width : rui.Px(1),
|
rui.Width : rui.Px(1),
|
||||||
rui.ColorProperty: rui.Black,
|
rui.ColorTag: rui.Black,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
### "column-fill" property
|
### "column-fill" property
|
||||||
|
@ -3141,13 +3141,21 @@ You can read the values of these properties using the functions:
|
||||||
The "number-changed" event (NumberChangedEvent constant) is used to track the change in the entered value.
|
The "number-changed" event (NumberChangedEvent 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 NumberPicker, newValue float64)
|
func(picker NumberPicker, newValue, oldValue float64)
|
||||||
|
|
||||||
where the second argument is the new value
|
where the second argument is the new value, the third argument is the previous value.
|
||||||
|
|
||||||
|
Additional event listeners can have the following format
|
||||||
|
|
||||||
|
func(picker NumberPicker, newValue string)
|
||||||
|
func(newValue, oldValue string)
|
||||||
|
func(newValue string)
|
||||||
|
func(picker NumberPicker)
|
||||||
|
func()
|
||||||
|
|
||||||
You can get the current list of value change listeners using the function
|
You can get the current list of value change listeners using the function
|
||||||
|
|
||||||
func GetNumberChangedListeners(view View, subviewID ...string) []func(NumberPicker, float64)
|
func GetNumberChangedListeners(view View, subviewID ...string) []func(NumberPicker, float64, float64)
|
||||||
|
|
||||||
## DatePicker
|
## DatePicker
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ type NumberPicker interface {
|
||||||
|
|
||||||
type numberPickerData struct {
|
type numberPickerData struct {
|
||||||
viewData
|
viewData
|
||||||
numberChangedListeners []func(NumberPicker, float64)
|
numberChangedListeners []func(NumberPicker, float64, float64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNumberPicker create new NumberPicker object and return it
|
// NewNumberPicker create new NumberPicker object and return it
|
||||||
|
@ -47,7 +47,7 @@ func newNumberPicker(session Session) View {
|
||||||
func (picker *numberPickerData) init(session Session) {
|
func (picker *numberPickerData) init(session Session) {
|
||||||
picker.viewData.init(session)
|
picker.viewData.init(session)
|
||||||
picker.tag = "NumberPicker"
|
picker.tag = "NumberPicker"
|
||||||
picker.numberChangedListeners = []func(NumberPicker, float64){}
|
picker.numberChangedListeners = []func(NumberPicker, float64, float64){}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (picker *numberPickerData) String() string {
|
func (picker *numberPickerData) String() string {
|
||||||
|
@ -76,7 +76,20 @@ func (picker *numberPickerData) remove(tag string) {
|
||||||
switch tag {
|
switch tag {
|
||||||
case NumberChangedEvent:
|
case NumberChangedEvent:
|
||||||
if len(picker.numberChangedListeners) > 0 {
|
if len(picker.numberChangedListeners) > 0 {
|
||||||
picker.numberChangedListeners = []func(NumberPicker, float64){}
|
picker.numberChangedListeners = []func(NumberPicker, float64, float64){}
|
||||||
|
picker.propertyChangedEvent(tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
case NumberPickerValue:
|
||||||
|
oldValue := GetNumberPickerValue(picker)
|
||||||
|
picker.viewData.remove(tag)
|
||||||
|
if oldValue != 0 {
|
||||||
|
if picker.created {
|
||||||
|
picker.session.callFunc("setInputValue", picker.htmlID(), 0)
|
||||||
|
}
|
||||||
|
for _, listener := range picker.numberChangedListeners {
|
||||||
|
listener(picker, 0, oldValue)
|
||||||
|
}
|
||||||
picker.propertyChangedEvent(tag)
|
picker.propertyChangedEvent(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,12 +111,12 @@ func (picker *numberPickerData) set(tag string, value any) bool {
|
||||||
|
|
||||||
switch tag {
|
switch tag {
|
||||||
case NumberChangedEvent:
|
case NumberChangedEvent:
|
||||||
listeners, ok := valueToEventListeners[NumberPicker, float64](value)
|
listeners, ok := valueToEventWithOldListeners[NumberPicker, float64](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(NumberPicker, float64){}
|
listeners = []func(NumberPicker, float64, float64){}
|
||||||
}
|
}
|
||||||
picker.numberChangedListeners = listeners
|
picker.numberChangedListeners = listeners
|
||||||
picker.propertyChangedEvent(tag)
|
picker.propertyChangedEvent(tag)
|
||||||
|
@ -119,7 +132,7 @@ func (picker *numberPickerData) set(tag string, value any) bool {
|
||||||
picker.session.callFunc("setInputValue", picker.htmlID(), newValue)
|
picker.session.callFunc("setInputValue", picker.htmlID(), newValue)
|
||||||
}
|
}
|
||||||
for _, listener := range picker.numberChangedListeners {
|
for _, listener := range picker.numberChangedListeners {
|
||||||
listener(picker, f)
|
listener(picker, f, oldValue)
|
||||||
}
|
}
|
||||||
picker.propertyChangedEvent(tag)
|
picker.propertyChangedEvent(tag)
|
||||||
}
|
}
|
||||||
|
@ -159,13 +172,6 @@ func (picker *numberPickerData) propertyChanged(tag string) {
|
||||||
} else {
|
} else {
|
||||||
picker.session.updateProperty(picker.htmlID(), Step, "any")
|
picker.session.updateProperty(picker.htmlID(), Step, "any")
|
||||||
}
|
}
|
||||||
|
|
||||||
case NumberPickerValue:
|
|
||||||
value := GetNumberPickerValue(picker)
|
|
||||||
picker.session.callFunc("setInputValue", picker.htmlID(), value)
|
|
||||||
for _, listener := range picker.numberChangedListeners {
|
|
||||||
listener(picker, value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,7 +248,7 @@ func (picker *numberPickerData) handleCommand(self View, command string, data Da
|
||||||
picker.properties[NumberPickerValue] = text
|
picker.properties[NumberPickerValue] = text
|
||||||
if value != oldValue {
|
if value != oldValue {
|
||||||
for _, listener := range picker.numberChangedListeners {
|
for _, listener := range picker.numberChangedListeners {
|
||||||
listener(picker, value)
|
listener(picker, value, oldValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,6 +329,6 @@ func GetNumberPickerValue(view View, subviewID ...string) float64 {
|
||||||
// GetNumberChangedListeners returns the NumberChangedListener list of an NumberPicker subview.
|
// GetNumberChangedListeners returns the NumberChangedListener list of an NumberPicker 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 GetNumberChangedListeners(view View, subviewID ...string) []func(NumberPicker, float64) {
|
func GetNumberChangedListeners(view View, subviewID ...string) []func(NumberPicker, float64, float64) {
|
||||||
return getEventListeners[NumberPicker, float64](view, subviewID, NumberChangedEvent)
|
return getEventWithOldListeners[NumberPicker, float64](view, subviewID, NumberChangedEvent)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue