This commit is contained in:
Alexei Anoshenko 2026-07-14 11:25:58 +03:00
parent 9a4f20f824
commit ea930e7b73
6 changed files with 35 additions and 10 deletions

View File

@ -1,6 +1,9 @@
package rui package rui
import "strings" import (
"iter"
"strings"
)
// Constants for [DetailsView] specific properties and events // Constants for [DetailsView] specific properties and events
const ( const (
@ -80,6 +83,29 @@ func (detailsView *detailsViewData) Views() []View {
return views return views
} }
func (detailsView *detailsViewData) ViewSeq() iter.Seq[View] {
if detailsView.views == nil {
detailsView.views = []View{}
}
return func(yield func(View) bool) {
if summary := detailsView.Get(Summary); summary != nil {
switch summary := summary.(type) {
case View:
if !yield(summary) {
return
}
}
}
for _, view := range detailsView.views {
if !yield(view) {
return
}
}
}
}
func (detailsView *detailsViewData) setFunc(tag PropertyName, value any) []PropertyName { func (detailsView *detailsViewData) setFunc(tag PropertyName, value any) []PropertyName {
switch tag { switch tag {
case Summary: case Summary:

View File

@ -3,6 +3,7 @@ package rui
import ( import (
"fmt" "fmt"
"iter" "iter"
"slices"
"strconv" "strconv"
"strings" "strings"
) )
@ -159,7 +160,7 @@ func (listView *listViewData) init(session Session) {
} }
func (listView *listViewData) Views() []View { func (listView *listViewData) Views() []View {
return listView.items return slices.Clone(listView.items)
} }
func (listView *listViewData) ViewSeq() iter.Seq[View] { func (listView *listViewData) ViewSeq() iter.Seq[View] {

View File

@ -45,7 +45,7 @@ func viewByHTMLID(id string, startView View) View {
return startView return startView
} }
if container, ok := startView.(ParentView); ok { if container, ok := startView.(ParentView); ok {
for _, view := range container.Views() { for view := range container.ViewSeq() {
if view != nil { if view != nil {
if v := viewByHTMLID(id, view); v != nil { if v := viewByHTMLID(id, view); v != nil {
return v return v

View File

@ -3,6 +3,7 @@ package rui
import ( import (
"fmt" "fmt"
"iter" "iter"
"slices"
"strconv" "strconv"
"strings" "strings"
) )
@ -1692,7 +1693,7 @@ func (table *tableViewData) ReloadCell(row, column int) {
} }
func (table *tableViewData) Views() []View { func (table *tableViewData) Views() []View {
return table.cellViews return slices.Clone(table.cellViews)
} }
func (table *tableViewData) ViewSeq() iter.Seq[View] { func (table *tableViewData) ViewSeq() iter.Seq[View] {

View File

@ -44,7 +44,7 @@ func ViewByID(rootView View, id string, ids ...string) View {
} }
func viewByID(rootView ParentView, id string) View { func viewByID(rootView ParentView, id string) View {
for _, view := range rootView.Views() { for view := range rootView.ViewSeq() {
if view != nil { if view != nil {
if view.ID() == id { if view.ID() == id {
return view return view

View File

@ -2,6 +2,7 @@ package rui
import ( import (
"iter" "iter"
"slices"
"strings" "strings"
) )
@ -68,12 +69,8 @@ func (container *viewsContainerData) setParentID(parentID string) {
func (container *viewsContainerData) Views() []View { func (container *viewsContainerData) Views() []View {
if container.views == nil { if container.views == nil {
container.views = []View{} container.views = []View{}
} else if count := len(container.views); count > 0 {
views := make([]View, count)
copy(views, container.views)
return views
} }
return []View{} return slices.Clone(container.views)
} }
func (container *viewsContainerData) ViewSeq() iter.Seq[View] { func (container *viewsContainerData) ViewSeq() iter.Seq[View] {