mirror of https://github.com/anoshenko/rui.git
Excluding default properties of CustomView from the result of String()
This commit is contained in:
parent
918fbf3473
commit
b1628023f7
|
@ -27,7 +27,7 @@ func (player *audioPlayerData) init(session Session) {
|
|||
}
|
||||
|
||||
func (player *audioPlayerData) String() string {
|
||||
return getViewString(player)
|
||||
return getViewString(player, nil)
|
||||
}
|
||||
|
||||
func (player *audioPlayerData) htmlTag() string {
|
||||
|
|
|
@ -37,7 +37,7 @@ func (canvasView *canvasViewData) init(session Session) {
|
|||
}
|
||||
|
||||
func (canvasView *canvasViewData) String() string {
|
||||
return getViewString(canvasView)
|
||||
return getViewString(canvasView, nil)
|
||||
}
|
||||
|
||||
func (canvasView *canvasViewData) normalizeTag(tag string) string {
|
||||
|
|
|
@ -43,7 +43,7 @@ func (button *checkboxData) init(session Session) {
|
|||
}
|
||||
|
||||
func (button *checkboxData) String() string {
|
||||
return getViewString(button)
|
||||
return getViewString(button, nil)
|
||||
}
|
||||
|
||||
func (button *checkboxData) Focusable() bool {
|
||||
|
|
|
@ -40,7 +40,7 @@ func (picker *colorPickerData) init(session Session) {
|
|||
}
|
||||
|
||||
func (picker *colorPickerData) String() string {
|
||||
return getViewString(picker)
|
||||
return getViewString(picker, nil)
|
||||
}
|
||||
|
||||
func (picker *colorPickerData) normalizeTag(tag string) string {
|
||||
|
|
|
@ -81,7 +81,7 @@ func (ColumnLayout *columnLayoutData) init(session Session) {
|
|||
}
|
||||
|
||||
func (columnLayout *columnLayoutData) String() string {
|
||||
return getViewString(columnLayout)
|
||||
return getViewString(columnLayout, nil)
|
||||
}
|
||||
|
||||
func (columnLayout *columnLayoutData) normalizeTag(tag string) string {
|
||||
|
|
|
@ -13,8 +13,9 @@ type CustomView interface {
|
|||
|
||||
// CustomViewData defines a data of a basic custom view
|
||||
type CustomViewData struct {
|
||||
tag string
|
||||
superView View
|
||||
tag string
|
||||
superView View
|
||||
defaultParams Params
|
||||
}
|
||||
|
||||
// InitCustomView initializes fields of CustomView by default values
|
||||
|
@ -37,6 +38,12 @@ func (customView *CustomViewData) SuperView() View {
|
|||
|
||||
func (customView *CustomViewData) setSuperView(view View) {
|
||||
customView.superView = view
|
||||
customView.defaultParams = Params{}
|
||||
for _, tag := range view.AllTags() {
|
||||
if value := view.getRaw(tag); value != nil {
|
||||
customView.defaultParams[tag] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (customView *CustomViewData) setTag(tag string) {
|
||||
|
@ -252,9 +259,22 @@ func (customView *CustomViewData) ViewIndex(view View) int {
|
|||
return -1
|
||||
}
|
||||
|
||||
func (customView *CustomViewData) exscludeTags() []string {
|
||||
if customView.superView != nil {
|
||||
exsclude := []string{}
|
||||
for tag, value := range customView.defaultParams {
|
||||
if value == customView.superView.getRaw(tag) {
|
||||
exsclude = append(exsclude, tag)
|
||||
}
|
||||
}
|
||||
return exsclude
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (customView *CustomViewData) String() string {
|
||||
if customView.superView != nil {
|
||||
return getViewString(customView)
|
||||
return getViewString(customView, customView.exscludeTags())
|
||||
}
|
||||
return customView.tag + " { }"
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ func (picker *datePickerData) init(session Session) {
|
|||
}
|
||||
|
||||
func (picker *datePickerData) String() string {
|
||||
return getViewString(picker)
|
||||
return getViewString(picker, nil)
|
||||
}
|
||||
|
||||
func (picker *datePickerData) Focusable() bool {
|
||||
|
|
|
@ -46,7 +46,7 @@ func (list *dropDownListData) init(session Session) {
|
|||
}
|
||||
|
||||
func (list *dropDownListData) String() string {
|
||||
return getViewString(list)
|
||||
return getViewString(list, nil)
|
||||
}
|
||||
|
||||
func (list *dropDownListData) Focusable() bool {
|
||||
|
|
|
@ -64,7 +64,7 @@ func (edit *editViewData) init(session Session) {
|
|||
}
|
||||
|
||||
func (edit *editViewData) String() string {
|
||||
return getViewString(edit)
|
||||
return getViewString(edit, nil)
|
||||
}
|
||||
|
||||
func (edit *editViewData) Focusable() bool {
|
||||
|
|
|
@ -90,7 +90,7 @@ func (picker *filePickerData) init(session Session) {
|
|||
}
|
||||
|
||||
func (picker *filePickerData) String() string {
|
||||
return getViewString(picker)
|
||||
return getViewString(picker, nil)
|
||||
}
|
||||
|
||||
func (picker *filePickerData) Focusable() bool {
|
||||
|
|
|
@ -72,7 +72,7 @@ func (gridLayout *gridLayoutData) init(session Session) {
|
|||
}
|
||||
|
||||
func (gridLayout *gridLayoutData) String() string {
|
||||
return getViewString(gridLayout)
|
||||
return getViewString(gridLayout, nil)
|
||||
}
|
||||
|
||||
func (style *viewStyle) setGridCellSize(tag string, value any) bool {
|
||||
|
|
|
@ -71,7 +71,7 @@ func (imageView *imageViewData) init(session Session) {
|
|||
}
|
||||
|
||||
func (imageView *imageViewData) String() string {
|
||||
return getViewString(imageView)
|
||||
return getViewString(imageView, nil)
|
||||
}
|
||||
|
||||
func (imageView *imageViewData) normalizeTag(tag string) string {
|
||||
|
|
|
@ -56,7 +56,7 @@ func (listLayout *listLayoutData) init(session Session) {
|
|||
}
|
||||
|
||||
func (listLayout *listLayoutData) String() string {
|
||||
return getViewString(listLayout)
|
||||
return getViewString(listLayout, nil)
|
||||
}
|
||||
|
||||
func (listLayout *listLayoutData) normalizeTag(tag string) string {
|
||||
|
|
|
@ -97,7 +97,7 @@ func (listView *listViewData) init(session Session) {
|
|||
}
|
||||
|
||||
func (listView *listViewData) String() string {
|
||||
return getViewString(listView)
|
||||
return getViewString(listView, nil)
|
||||
}
|
||||
|
||||
func (listView *listViewData) Views() []View {
|
||||
|
|
|
@ -211,7 +211,7 @@ func (player *mediaPlayerData) init(session Session) {
|
|||
}
|
||||
|
||||
func (player *mediaPlayerData) String() string {
|
||||
return getViewString(player)
|
||||
return getViewString(player, nil)
|
||||
}
|
||||
|
||||
func (player *mediaPlayerData) Focusable() bool {
|
||||
|
|
|
@ -72,7 +72,7 @@ func (picker *numberPickerData) init(session Session) {
|
|||
}
|
||||
|
||||
func (picker *numberPickerData) String() string {
|
||||
return getViewString(picker)
|
||||
return getViewString(picker, nil)
|
||||
}
|
||||
|
||||
func (picker *numberPickerData) Focusable() bool {
|
||||
|
|
|
@ -37,7 +37,7 @@ func (progress *progressBarData) init(session Session) {
|
|||
}
|
||||
|
||||
func (progress *progressBarData) String() string {
|
||||
return getViewString(progress)
|
||||
return getViewString(progress, nil)
|
||||
}
|
||||
|
||||
func (progress *progressBarData) normalizeTag(tag string) string {
|
||||
|
|
|
@ -63,7 +63,7 @@ func (resizable *resizableData) init(session Session) {
|
|||
}
|
||||
|
||||
func (resizable *resizableData) String() string {
|
||||
return getViewString(resizable)
|
||||
return getViewString(resizable, nil)
|
||||
}
|
||||
|
||||
func (resizable *resizableData) Views() []View {
|
||||
|
|
|
@ -82,7 +82,7 @@ func (layout *stackLayoutData) init(session Session) {
|
|||
}
|
||||
|
||||
func (layout *stackLayoutData) String() string {
|
||||
return getViewString(layout)
|
||||
return getViewString(layout, nil)
|
||||
}
|
||||
|
||||
func (layout *stackLayoutData) pushFinished(view View, tag string) {
|
||||
|
|
|
@ -36,7 +36,7 @@ func (imageView *svgImageViewData) init(session Session) {
|
|||
}
|
||||
|
||||
func (imageView *svgImageViewData) String() string {
|
||||
return getViewString(imageView)
|
||||
return getViewString(imageView, nil)
|
||||
}
|
||||
|
||||
func (imageView *svgImageViewData) normalizeTag(tag string) string {
|
||||
|
|
|
@ -270,7 +270,7 @@ func (table *tableViewData) init(session Session) {
|
|||
}
|
||||
|
||||
func (table *tableViewData) String() string {
|
||||
return getViewString(table)
|
||||
return getViewString(table, nil)
|
||||
}
|
||||
|
||||
func (table *tableViewData) normalizeTag(tag string) string {
|
||||
|
|
|
@ -99,7 +99,7 @@ func (tabsLayout *tabsLayoutData) init(session Session) {
|
|||
}
|
||||
|
||||
func (tabsLayout *tabsLayoutData) String() string {
|
||||
return getViewString(tabsLayout)
|
||||
return getViewString(tabsLayout, nil)
|
||||
}
|
||||
|
||||
func (tabsLayout *tabsLayoutData) currentItem(defaultValue int) int {
|
||||
|
|
|
@ -33,7 +33,7 @@ func (textView *textViewData) init(session Session) {
|
|||
}
|
||||
|
||||
func (textView *textViewData) String() string {
|
||||
return getViewString(textView)
|
||||
return getViewString(textView, nil)
|
||||
}
|
||||
|
||||
func (textView *textViewData) Get(tag string) any {
|
||||
|
|
4
theme.go
4
theme.go
|
@ -933,7 +933,7 @@ func (theme *theme) String() string {
|
|||
for _, tag := range tags {
|
||||
if style, ok := styles[tag]; ok && len(style.AllTags()) > 0 {
|
||||
buffer.WriteString("\t\t")
|
||||
writeViewStyle(tag, style, buffer, "\t\t")
|
||||
writeViewStyle(tag, style, buffer, "\t\t", nil)
|
||||
buffer.WriteString(",\n")
|
||||
}
|
||||
}
|
||||
|
@ -984,7 +984,7 @@ func (theme *theme) String() string {
|
|||
for _, tag := range tags {
|
||||
if style, ok := media.styles[tag]; ok && len(style.AllTags()) > 0 {
|
||||
buffer.WriteString("\t\t")
|
||||
writeViewStyle(tag, style, buffer, "\t\t")
|
||||
writeViewStyle(tag, style, buffer, "\t\t", nil)
|
||||
buffer.WriteString(",\n")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ func (picker *timePickerData) init(session Session) {
|
|||
}
|
||||
|
||||
func (picker *timePickerData) String() string {
|
||||
return getViewString(picker)
|
||||
return getViewString(picker, nil)
|
||||
}
|
||||
|
||||
func (picker *timePickerData) Focusable() bool {
|
||||
|
|
|
@ -47,7 +47,7 @@ func (player *videoPlayerData) init(session Session) {
|
|||
}
|
||||
|
||||
func (player *videoPlayerData) String() string {
|
||||
return getViewString(player)
|
||||
return getViewString(player, nil)
|
||||
}
|
||||
|
||||
func (player *videoPlayerData) htmlTag() string {
|
||||
|
|
7
view.go
7
view.go
|
@ -76,6 +76,7 @@ type View interface {
|
|||
htmlProperties(self View, buffer *strings.Builder)
|
||||
cssStyle(self View, builder cssBuilder)
|
||||
addToCSSStyle(addCSS map[string]string)
|
||||
exscludeTags() []string
|
||||
|
||||
onResize(self View, x, y, width, height float64)
|
||||
onItemResize(self View, index string, x, y, width, height float64)
|
||||
|
@ -999,5 +1000,9 @@ func (view *viewData) HasFocus() bool {
|
|||
}
|
||||
|
||||
func (view *viewData) String() string {
|
||||
return getViewString(view)
|
||||
return getViewString(view, nil)
|
||||
}
|
||||
|
||||
func (view *viewData) exscludeTags() []string {
|
||||
return nil
|
||||
}
|
||||
|
|
16
viewStyle.go
16
viewStyle.go
|
@ -710,14 +710,14 @@ func writePropertyValue(buffer *strings.Builder, tag string, value any, indent s
|
|||
buffer.WriteString("[]")
|
||||
|
||||
case 1:
|
||||
writeViewStyle(value[0].Tag(), value[0], buffer, indent)
|
||||
writeViewStyle(value[0].Tag(), value[0], buffer, indent, value[0].exscludeTags())
|
||||
|
||||
default:
|
||||
buffer.WriteString("[\n")
|
||||
indent2 := indent + "\t"
|
||||
for _, v := range value {
|
||||
buffer.WriteString(indent2)
|
||||
writeViewStyle(v.Tag(), v, buffer, indent2)
|
||||
writeViewStyle(v.Tag(), v, buffer, indent2, v.exscludeTags())
|
||||
buffer.WriteString(",\n")
|
||||
}
|
||||
|
||||
|
@ -819,12 +819,18 @@ func writePropertyValue(buffer *strings.Builder, tag string, value any, indent s
|
|||
}
|
||||
}
|
||||
|
||||
func writeViewStyle(name string, view ViewStyle, buffer *strings.Builder, indent string) {
|
||||
func writeViewStyle(name string, view ViewStyle, buffer *strings.Builder, indent string, excludeTags []string) {
|
||||
buffer.WriteString(name)
|
||||
buffer.WriteString(" {\n")
|
||||
indent += "\t"
|
||||
|
||||
writeProperty := func(tag string, value any) {
|
||||
for _, exclude := range excludeTags {
|
||||
if exclude == tag {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if supportedPropertyValue(value) {
|
||||
buffer.WriteString(indent)
|
||||
buffer.WriteString(tag)
|
||||
|
@ -896,10 +902,10 @@ func writeViewStyle(name string, view ViewStyle, buffer *strings.Builder, indent
|
|||
buffer.WriteString("}")
|
||||
}
|
||||
|
||||
func getViewString(view View) string {
|
||||
func getViewString(view View, excludeTags []string) string {
|
||||
buffer := allocStringBuilder()
|
||||
defer freeStringBuilder(buffer)
|
||||
writeViewStyle(view.Tag(), view, buffer, "")
|
||||
writeViewStyle(view.Tag(), view, buffer, "", excludeTags)
|
||||
return buffer.String()
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ func (container *viewsContainerData) init(session Session) {
|
|||
}
|
||||
|
||||
func (container *viewsContainerData) String() string {
|
||||
return getViewString(container)
|
||||
return getViewString(container, nil)
|
||||
}
|
||||
|
||||
func (container *viewsContainerData) setParentID(parentID string) {
|
||||
|
|
Loading…
Reference in New Issue