Improved DetailsView

This commit is contained in:
Alexei Anoshenko 2024-11-21 08:25:46 +02:00
parent 7d4b90769f
commit 84a00af595
14 changed files with 54 additions and 40 deletions

View File

@ -35,7 +35,7 @@ func (layout *absoluteLayoutData) htmlSubviews(self View, buffer *strings.Builde
if layout.views != nil { if layout.views != nil {
for _, view := range layout.views { for _, view := range layout.views {
view.addToCSSStyle(map[string]string{`position`: `absolute`}) view.addToCSSStyle(map[string]string{`position`: `absolute`})
viewHTML(view, buffer) viewHTML(view, buffer, "")
} }
} }
} }

View File

@ -142,11 +142,15 @@ func (detailsView *detailsViewData) htmlSubviews(self View, buffer *strings.Buil
buffer.WriteString("</summary>") buffer.WriteString("</summary>")
case View: case View:
if value.htmlTag() == "div" {
viewHTML(value, buffer, "summary")
} else {
buffer.WriteString(`<summary><div style="display: inline-block;">`) buffer.WriteString(`<summary><div style="display: inline-block;">`)
viewHTML(value, buffer) viewHTML(value, buffer, "")
buffer.WriteString("</div></summary>") buffer.WriteString("</div></summary>")
} }
} }
}
detailsView.viewsContainerData.htmlSubviews(self, buffer) detailsView.viewsContainerData.htmlSubviews(self, buffer)
} }

View File

@ -163,7 +163,7 @@ func (listLayout *listLayoutData) htmlSubviews(self View, buffer *strings.Builde
if listLayout.views != nil { if listLayout.views != nil {
for _, view := range listLayout.views { for _, view := range listLayout.views {
view.addToCSSStyle(map[string]string{`flex`: `0 0 auto`}) view.addToCSSStyle(map[string]string{`flex`: `0 0 auto`})
viewHTML(view, buffer) viewHTML(view, buffer, "")
} }
} }
} }

View File

@ -659,7 +659,7 @@ func (listView *listViewData) checkboxSubviews(adapter ListAdapter, buffer *stri
if view := listView.getItemView(adapter, i); view != nil { if view := listView.getItemView(adapter, i); view != nil {
//view.setNoResizeEvent() //view.setNoResizeEvent()
viewHTML(view, buffer) viewHTML(view, buffer, "")
} else { } else {
buffer.WriteString("ERROR: invalid item view") buffer.WriteString("ERROR: invalid item view")
} }
@ -706,7 +706,7 @@ func (listView *listViewData) noneCheckboxSubviews(adapter ListAdapter, buffer *
if view := listView.getItemView(adapter, i); view != nil { if view := listView.getItemView(adapter, i); view != nil {
//view.setNoResizeEvent() //view.setNoResizeEvent()
viewHTML(view, buffer) viewHTML(view, buffer, "")
} else { } else {
buffer.WriteString("ERROR: invalid item view") buffer.WriteString("ERROR: invalid item view")
} }
@ -737,7 +737,7 @@ func (listView *listViewData) updateCheckboxItem(index int, checked bool) {
if adapter := listView.getAdapter(); adapter != nil { if adapter := listView.getAdapter(); adapter != nil {
if view := listView.getItemView(adapter, index); view != nil { if view := listView.getItemView(adapter, index); view != nil {
view.setNoResizeEvent() view.setNoResizeEvent()
viewHTML(view, buffer) viewHTML(view, buffer, "")
} else { } else {
buffer.WriteString("ERROR: invalid item view") buffer.WriteString("ERROR: invalid item view")
} }

View File

@ -720,7 +720,7 @@ func (popup *popupData) Show() {
func (popup *popupData) html(buffer *strings.Builder) { func (popup *popupData) html(buffer *strings.Builder) {
viewHTML(popup.layerView, buffer) viewHTML(popup.layerView, buffer, "")
} }
func (popup *popupData) viewByHTMLID(id string) View { func (popup *popupData) viewByHTMLID(id string) View {

View File

@ -431,6 +431,6 @@ func (resizable *resizableData) htmlSubviews(self View, buffer *strings.Builder)
"grid-row-start": strconv.Itoa(top), "grid-row-start": strconv.Itoa(top),
"grid-row-end": strconv.Itoa(top + 1), "grid-row-end": strconv.Itoa(top + 1),
}) })
viewHTML(view, buffer) viewHTML(view, buffer, "")
} }
} }

View File

@ -329,7 +329,7 @@ func (session *sessionData) writeInitScript(writer *strings.Builder) {
writer.WriteString(`document.getElementById('ruiRootView').innerHTML = '`) writer.WriteString(`document.getElementById('ruiRootView').innerHTML = '`)
buffer := allocStringBuilder() buffer := allocStringBuilder()
defer freeStringBuilder(buffer) defer freeStringBuilder(buffer)
viewHTML(session.rootView, buffer) viewHTML(session.rootView, buffer, "")
text := strings.ReplaceAll(buffer.String(), "'", `\'`) text := strings.ReplaceAll(buffer.String(), "'", `\'`)
writer.WriteString(text) writer.WriteString(text)
writer.WriteString("';\nscanElementsSize();") writer.WriteString("';\nscanElementsSize();")
@ -360,7 +360,7 @@ func (session *sessionData) reload() {
buffer := allocStringBuilder() buffer := allocStringBuilder()
defer freeStringBuilder(buffer) defer freeStringBuilder(buffer)
viewHTML(session.rootView, buffer) viewHTML(session.rootView, buffer, "")
session.bridge.updateInnerHTML("ruiRootView", buffer.String()) session.bridge.updateInnerHTML("ruiRootView", buffer.String())
session.bridge.callFunc("scanElementsSize") session.bridge.callFunc("scanElementsSize")
} }

View File

@ -339,7 +339,7 @@ func (session *sessionData) SetLanguage(lang string) {
buffer := allocStringBuilder() buffer := allocStringBuilder()
defer freeStringBuilder(buffer) defer freeStringBuilder(buffer)
viewHTML(session.rootView, buffer) viewHTML(session.rootView, buffer, "")
session.bridge.updateInnerHTML("ruiRootView", buffer.String()) session.bridge.updateInnerHTML("ruiRootView", buffer.String())
} }
} }

View File

@ -345,7 +345,7 @@ func (layout *stackLayoutData) Push(view View, animation int, onPushFinished fun
buffer.WriteString(`1s ease;">`) buffer.WriteString(`1s ease;">`)
viewHTML(layout.pushView, buffer) viewHTML(layout.pushView, buffer, "")
buffer.WriteString(`</div>`) buffer.WriteString(`</div>`)
session.appendToInnerHTML(htmlID, buffer.String()) session.appendToInnerHTML(htmlID, buffer.String())
@ -386,7 +386,7 @@ func (layout *stackLayoutData) Pop(animation int, onPopFinished func(View)) bool
buffer.WriteString(`', 'ruiPop', event)" ontransitioncancel="stackTransitionEndEvent('`) buffer.WriteString(`', 'ruiPop', event)" ontransitioncancel="stackTransitionEndEvent('`)
buffer.WriteString(htmlID) buffer.WriteString(htmlID)
buffer.WriteString(`', 'ruiPop', event)" style="transition: transform 1s ease;">`) buffer.WriteString(`', 'ruiPop', event)" style="transition: transform 1s ease;">`)
viewHTML(layout.popView, buffer) viewHTML(layout.popView, buffer, "")
buffer.WriteString(`</div>`) buffer.WriteString(`</div>`)
session.appendToInnerHTML(htmlID, buffer.String()) session.appendToInnerHTML(htmlID, buffer.String())
@ -429,7 +429,7 @@ func (layout *stackLayoutData) htmlSubviews(self View, buffer *strings.Builder)
buffer.WriteString(` style="visibility: hidden;"`) buffer.WriteString(` style="visibility: hidden;"`)
} }
buffer.WriteString(`>`) buffer.WriteString(`>`)
viewHTML(view, buffer) viewHTML(view, buffer, "")
buffer.WriteString(`</div>`) buffer.WriteString(`</div>`)
} }
} }

View File

@ -1559,7 +1559,7 @@ func (table *tableViewData) writeCellHtml(adapter TableAdapter, row, column int,
buffer.WriteString(value) buffer.WriteString(value)
case View: case View:
viewHTML(value, buffer) viewHTML(value, buffer, "")
table.cellViews = append(table.cellViews, value) table.cellViews = append(table.cellViews, value)
case Color: case Color:

View File

@ -861,7 +861,7 @@ func (tabsLayout *tabsLayoutData) htmlSubviews(self View, buffer *strings.Builde
buffer.WriteString(`grid-row-start: 1; grid-row-end: 2; grid-column-start: 1; grid-column-end: 2;">`) buffer.WriteString(`grid-row-start: 1; grid-row-end: 2; grid-column-start: 1; grid-column-end: 2;">`)
} }
viewHTML(view, buffer) viewHTML(view, buffer, "")
buffer.WriteString(`</div>`) buffer.WriteString(`</div>`)
} }
} }

11
view.go
View File

@ -836,10 +836,13 @@ func (view *viewData) htmlProperties(self View, buffer *strings.Builder) {
} }
} }
func viewHTML(view View, buffer *strings.Builder) { func viewHTML(view View, buffer *strings.Builder, htmlTag string) {
viewHTMLTag := view.htmlTag() if htmlTag == "" {
htmlTag = view.htmlTag()
}
//viewHTMLTag := view.htmlTag()
buffer.WriteRune('<') buffer.WriteRune('<')
buffer.WriteString(viewHTMLTag) buffer.WriteString(htmlTag)
buffer.WriteString(` id="`) buffer.WriteString(` id="`)
buffer.WriteString(view.htmlID()) buffer.WriteString(view.htmlID())
buffer.WriteRune('"') buffer.WriteRune('"')
@ -907,7 +910,7 @@ func viewHTML(view View, buffer *strings.Builder) {
view.htmlSubviews(view, buffer) view.htmlSubviews(view, buffer)
if view.closeHTMLTag() { if view.closeHTMLTag() {
buffer.WriteString(`</`) buffer.WriteString(`</`)
buffer.WriteString(viewHTMLTag) buffer.WriteString(htmlTag)
buffer.WriteRune('>') buffer.WriteRune('>')
} }
} }

View File

@ -372,23 +372,7 @@ func GetAccentColor(view View, subviewID ...string) Color {
// GetFontName returns the subview font. // GetFontName returns the subview font.
// 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 GetFontName(view View, subviewID ...string) string { func GetFontName(view View, subviewID ...string) string {
if len(subviewID) > 0 && subviewID[0] != "" { return stringStyledProperty(view, nil, FontName, true)
view = ViewByID(view, subviewID[0])
}
if view != nil {
if font, ok := stringProperty(view, FontName, view.Session()); ok {
return font
}
if value := valueFromStyle(view, FontName); value != nil {
if font, ok := value.(string); ok {
return font
}
}
if parent := view.Parent(); parent != nil {
return GetFontName(parent)
}
}
return ""
} }
// GetTextColor returns a text color of the subview. // GetTextColor returns a text color of the subview.
@ -725,6 +709,29 @@ func valueFromStyle(view View, tag PropertyName) any {
return getValue(Style) return getValue(Style)
} }
func stringStyledProperty(view View, subviewID []string, tag PropertyName, inherit bool) string {
if len(subviewID) > 0 && subviewID[0] != "" {
view = ViewByID(view, subviewID[0])
}
if view != nil {
if text, ok := stringProperty(view, tag, view.Session()); ok {
return text
}
if value := valueFromStyle(view, tag); value != nil {
if text, ok := value.(string); ok {
return text
}
}
if inherit {
if parent := view.Parent(); parent != nil {
return stringStyledProperty(parent, nil, tag, true)
}
}
}
return ""
}
func sizeStyledProperty(view View, subviewID []string, tag PropertyName, inherit bool) SizeUnit { func sizeStyledProperty(view View, subviewID []string, tag PropertyName, inherit bool) SizeUnit {
if len(subviewID) > 0 && subviewID[0] != "" { if len(subviewID) > 0 && subviewID[0] != "" {
view = ViewByID(view, subviewID[0]) view = ViewByID(view, subviewID[0])

View File

@ -146,7 +146,7 @@ func (container *viewsContainerData) cssStyle(self View, builder cssBuilder) {
func (container *viewsContainerData) htmlSubviews(self View, buffer *strings.Builder) { func (container *viewsContainerData) htmlSubviews(self View, buffer *strings.Builder) {
if container.views != nil { if container.views != nil {
for _, view := range container.views { for _, view := range container.views {
viewHTML(view, buffer) viewHTML(view, buffer, "")
} }
} }
} }