Added Properties interface implementation to Popup interface

This commit is contained in:
Alexei Anoshenko 2025-07-01 17:34:31 +03:00
parent c3c8b9e858
commit 00ef0b3624
7 changed files with 730 additions and 362 deletions

View File

@ -282,6 +282,15 @@ func (customView *CustomViewData) RemoveView(index int) View {
return nil return nil
} }
func (customView *CustomViewData) RemoveViewByID(id string) View {
if customView.superView != nil {
if container, ok := customView.superView.(ViewsContainer); ok {
return container.RemoveViewByID(id)
}
}
return nil
}
// Remove removes a view from the list of a view children and return it // Remove removes a view from the list of a view children and return it
func (customView *CustomViewData) ViewIndex(view View) int { func (customView *CustomViewData) ViewIndex(view View) int {
if customView.superView != nil { if customView.superView != nil {

View File

@ -1,6 +1,8 @@
package rui package rui
import "sort" import (
"slices"
)
// Params defines a type of a parameters list // Params defines a type of a parameters list
type Params map[PropertyName]any type Params map[PropertyName]any
@ -51,9 +53,7 @@ func (params Params) AllTags() []PropertyName {
for t := range params { for t := range params {
tags = append(tags, t) tags = append(tags, t)
} }
sort.Slice(tags, func(i, j int) bool { slices.Sort(tags)
return tags[i] < tags[j]
})
return tags return tags
} }

993
popup.go

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
package rui package rui
import ( import (
"sort" "slices"
"strings" "strings"
) )
@ -33,9 +33,6 @@ type Properties interface {
type propertyList struct { type propertyList struct {
properties map[PropertyName]any properties map[PropertyName]any
normalize func(PropertyName) PropertyName normalize func(PropertyName) PropertyName
//getFunc func(PropertyName) any
//set func(Properties, PropertyName, any) []PropertyName
//remove func(Properties, PropertyName) []PropertyName
} }
type dataProperty struct { type dataProperty struct {
@ -91,9 +88,7 @@ func (properties *propertyList) AllTags() []PropertyName {
for tag := range properties.properties { for tag := range properties.properties {
tags = append(tags, tag) tags = append(tags, tag)
} }
sort.Slice(tags, func(i, j int) bool { slices.Sort(tags)
return tags[i] < tags[j]
})
return tags return tags
} }
@ -157,7 +152,7 @@ func (data *dataProperty) init() {
} }
func (data *dataProperty) Get(tag PropertyName) any { func (data *dataProperty) Get(tag PropertyName) any {
return propertiesGet(data, data.normalize(tag)) return data.get(data, data.normalize(tag))
} }
func (data *dataProperty) Remove(tag PropertyName) { func (data *dataProperty) Remove(tag PropertyName) {

View File

@ -84,6 +84,7 @@ var intProperties = []PropertyName{
var floatProperties = map[PropertyName]struct{ min, max float64 }{ var floatProperties = map[PropertyName]struct{ min, max float64 }{
Opacity: {min: 0, max: 1}, Opacity: {min: 0, max: 1},
ShowOpacity: {min: 0, max: 1},
NumberPickerMax: {min: -math.MaxFloat64, max: math.MaxFloat64}, NumberPickerMax: {min: -math.MaxFloat64, max: math.MaxFloat64},
NumberPickerMin: {min: -math.MaxFloat64, max: math.MaxFloat64}, NumberPickerMin: {min: -math.MaxFloat64, max: math.MaxFloat64},
NumberPickerStep: {min: -math.MaxFloat64, max: math.MaxFloat64}, NumberPickerStep: {min: -math.MaxFloat64, max: math.MaxFloat64},
@ -93,6 +94,7 @@ var floatProperties = map[PropertyName]struct{ min, max float64 }{
VideoWidth: {min: 0, max: 10000}, VideoWidth: {min: 0, max: 10000},
VideoHeight: {min: 0, max: 10000}, VideoHeight: {min: 0, max: 10000},
PushDuration: {min: 0, max: math.MaxFloat64}, PushDuration: {min: 0, max: math.MaxFloat64},
ShowDuration: {min: 0, max: math.MaxFloat64},
DragImageXOffset: {min: -math.MaxFloat64, max: math.MaxFloat64}, DragImageXOffset: {min: -math.MaxFloat64, max: math.MaxFloat64},
DragImageYOffset: {min: -math.MaxFloat64, max: math.MaxFloat64}, DragImageYOffset: {min: -math.MaxFloat64, max: math.MaxFloat64},
} }
@ -167,6 +169,9 @@ var sizeProperties = map[PropertyName]string{
ItemHeight: string(ItemHeight), ItemHeight: string(ItemHeight),
CenterX: string(CenterX), CenterX: string(CenterX),
CenterY: string(CenterX), CenterY: string(CenterX),
ArrowSize: "",
ArrowWidth: "",
ArrowOffset: "",
} }
type enumPropertyData struct { type enumPropertyData struct {
@ -885,11 +890,9 @@ func (data *dataProperty) Set(tag PropertyName, value any) bool {
} }
tag = data.normalize(tag) tag = data.normalize(tag)
for _, supported := range data.supportedProperties { if slices.Contains(data.supportedProperties, tag) {
if tag == supported {
return data.set(data, tag, value) != nil return data.set(data, tag, value) != nil
} }
}
ErrorLogF(`"%s" property is not supported`, string(tag)) ErrorLogF(`"%s" property is not supported`, string(tag))
return false return false

View File

@ -976,7 +976,7 @@ func (view *viewData) propertyChanged(tag PropertyName) {
} }
default: default:
if cssTag, ok := sizeProperties[tag]; ok { if cssTag, ok := sizeProperties[tag]; ok && cssTag != "" {
if size, ok := sizeProperty(view, tag, session); ok { if size, ok := sizeProperty(view, tag, session); ok {
session.updateCSSProperty(htmlID, cssTag, size.cssString("", session)) session.updateCSSProperty(htmlID, cssTag, size.cssString("", session))
} else { } else {

View File

@ -22,6 +22,9 @@ type ViewsContainer interface {
// Remove removes a view from the list of a view children and return it // Remove removes a view from the list of a view children and return it
RemoveView(index int) View RemoveView(index int) View
// Remove removes a view from the list of a view children and return it
RemoveViewByID(id string) View
// ViewIndex returns the index of view, -1 overwise // ViewIndex returns the index of view, -1 overwise
ViewIndex(view View) int ViewIndex(view View) int
@ -155,6 +158,15 @@ func (container *viewsContainerData) RemoveView(index int) View {
return view return view
} }
func (container *viewsContainerData) RemoveViewByID(id string) View {
for index, view := range container.views {
if view.ID() == id {
return container.RemoveView(index)
}
}
return nil
}
func (container *viewsContainerData) ViewIndex(view View) int { func (container *viewsContainerData) ViewIndex(view View) int {
for index, v := range container.views { for index, v := range container.views {
if v == view { if v == view {