From b1628023f733924d33c499fc1de42eeb21868ef0 Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko Date: Thu, 2 May 2024 15:07:57 +0300 Subject: [PATCH] Excluding default properties of CustomView from the result of String() --- audioPlayer.go | 2 +- canvasView.go | 2 +- checkbox.go | 2 +- colorPicker.go | 2 +- columnLayout.go | 2 +- customView.go | 26 +++++++++++++++++++++++--- datePicker.go | 2 +- dropDownList.go | 2 +- editView.go | 2 +- filePicker.go | 2 +- gridLayout.go | 2 +- imageView.go | 2 +- listLayout.go | 2 +- listView.go | 2 +- mediaPlayer.go | 2 +- numberPicker.go | 2 +- progressBar.go | 2 +- resizable.go | 2 +- stackLayout.go | 2 +- svgImageView.go | 2 +- tableView.go | 2 +- tabsLayout.go | 2 +- textView.go | 2 +- theme.go | 4 ++-- timePicker.go | 2 +- videoPlayer.go | 2 +- view.go | 7 ++++++- viewStyle.go | 16 +++++++++++----- viewsContainer.go | 2 +- 29 files changed, 67 insertions(+), 36 deletions(-) diff --git a/audioPlayer.go b/audioPlayer.go index a7cecc3..035c501 100644 --- a/audioPlayer.go +++ b/audioPlayer.go @@ -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 { diff --git a/canvasView.go b/canvasView.go index 6dbde8f..473bda4 100644 --- a/canvasView.go +++ b/canvasView.go @@ -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 { diff --git a/checkbox.go b/checkbox.go index 8a3605f..39691ec 100644 --- a/checkbox.go +++ b/checkbox.go @@ -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 { diff --git a/colorPicker.go b/colorPicker.go index bde5c6e..3b63b6a 100644 --- a/colorPicker.go +++ b/colorPicker.go @@ -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 { diff --git a/columnLayout.go b/columnLayout.go index 1a883f7..b0d468c 100644 --- a/columnLayout.go +++ b/columnLayout.go @@ -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 { diff --git a/customView.go b/customView.go index a846916..d74e9ed 100644 --- a/customView.go +++ b/customView.go @@ -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 + " { }" } diff --git a/datePicker.go b/datePicker.go index 404144c..983ffd6 100644 --- a/datePicker.go +++ b/datePicker.go @@ -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 { diff --git a/dropDownList.go b/dropDownList.go index a62a80a..a2d6159 100644 --- a/dropDownList.go +++ b/dropDownList.go @@ -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 { diff --git a/editView.go b/editView.go index 36b283f..627ac71 100644 --- a/editView.go +++ b/editView.go @@ -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 { diff --git a/filePicker.go b/filePicker.go index cf2b357..b3e759d 100644 --- a/filePicker.go +++ b/filePicker.go @@ -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 { diff --git a/gridLayout.go b/gridLayout.go index 20dbb10..e0e83e4 100644 --- a/gridLayout.go +++ b/gridLayout.go @@ -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 { diff --git a/imageView.go b/imageView.go index 8c52098..d87f3e9 100644 --- a/imageView.go +++ b/imageView.go @@ -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 { diff --git a/listLayout.go b/listLayout.go index 6bdcac2..c244e75 100644 --- a/listLayout.go +++ b/listLayout.go @@ -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 { diff --git a/listView.go b/listView.go index ab70396..b32407e 100644 --- a/listView.go +++ b/listView.go @@ -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 { diff --git a/mediaPlayer.go b/mediaPlayer.go index 2eee66b..445be0a 100644 --- a/mediaPlayer.go +++ b/mediaPlayer.go @@ -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 { diff --git a/numberPicker.go b/numberPicker.go index 0db087a..e41f9e1 100644 --- a/numberPicker.go +++ b/numberPicker.go @@ -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 { diff --git a/progressBar.go b/progressBar.go index f42b5e6..a5dac46 100644 --- a/progressBar.go +++ b/progressBar.go @@ -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 { diff --git a/resizable.go b/resizable.go index a183ea5..c504f26 100644 --- a/resizable.go +++ b/resizable.go @@ -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 { diff --git a/stackLayout.go b/stackLayout.go index 1c0a78f..960bcb9 100644 --- a/stackLayout.go +++ b/stackLayout.go @@ -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) { diff --git a/svgImageView.go b/svgImageView.go index f2a6c7f..b1a7e06 100644 --- a/svgImageView.go +++ b/svgImageView.go @@ -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 { diff --git a/tableView.go b/tableView.go index 01fcdc1..33c5110 100644 --- a/tableView.go +++ b/tableView.go @@ -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 { diff --git a/tabsLayout.go b/tabsLayout.go index 881f485..0f28558 100644 --- a/tabsLayout.go +++ b/tabsLayout.go @@ -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 { diff --git a/textView.go b/textView.go index 90f2026..21d9995 100644 --- a/textView.go +++ b/textView.go @@ -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 { diff --git a/theme.go b/theme.go index 2de69f7..fee0f16 100644 --- a/theme.go +++ b/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") } } diff --git a/timePicker.go b/timePicker.go index feab2ad..9be94b8 100644 --- a/timePicker.go +++ b/timePicker.go @@ -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 { diff --git a/videoPlayer.go b/videoPlayer.go index ca8d2fd..0369fa2 100644 --- a/videoPlayer.go +++ b/videoPlayer.go @@ -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 { diff --git a/view.go b/view.go index 4d0d8ff..66ea1f1 100644 --- a/view.go +++ b/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 } diff --git a/viewStyle.go b/viewStyle.go index 4c6d6e6..2a5682e 100644 --- a/viewStyle.go +++ b/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() } diff --git a/viewsContainer.go b/viewsContainer.go index e1520f5..facd0e3 100644 --- a/viewsContainer.go +++ b/viewsContainer.go @@ -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) {