diff --git a/CHANGELOG.md b/CHANGELOG.md index 8910e02..f1e396e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Added functions: GetWhiteSpace, GetWordBreak, ScrollIntoViewIfNeeded * Added Popups, PopupShowAnimation, and SetPopupShowAnimation methods to Session interface * Added DismissWithoutAnimation add SetHotKey methods to Popup interface +* Added ViewSeq add ViewCount methods to ParentView interface * Added ToBoundsProperty method to Bounds struct # v0.20.0 diff --git a/listView.go b/listView.go index edf0e2b..2455b7a 100644 --- a/listView.go +++ b/listView.go @@ -2,6 +2,7 @@ package rui import ( "fmt" + "iter" "strconv" "strings" ) @@ -161,6 +162,20 @@ func (listView *listViewData) Views() []View { return listView.items } +func (listView *listViewData) ViewSeq() iter.Seq[View] { + return func(yield func(View) bool) { + for _, view := range listView.items { + if !yield(view) { + return + } + } + } +} + +func (listView *listViewData) ViewCount() int { + return len(listView.items) +} + func normalizeListViewTag(tag PropertyName) PropertyName { tag = defaultNormalize(tag) switch tag { diff --git a/resizable.go b/resizable.go index 84b44e8..bce4410 100644 --- a/resizable.go +++ b/resizable.go @@ -2,6 +2,7 @@ package rui import ( "fmt" + "iter" "strconv" "strings" ) @@ -91,6 +92,21 @@ func (resizable *resizableData) Views() []View { return []View{} } +func (resizable *resizableData) ViewSeq() iter.Seq[View] { + return func(yield func(View) bool) { + if view := resizable.content(); view != nil { + yield(view) + } + } +} + +func (resizable *resizableData) ViewCount() int { + if resizable.content() != nil { + return 1 + } + return 0 +} + func (resizable *resizableData) content() View { if value := resizable.getRaw(Content); value != nil { if content, ok := value.(View); ok { diff --git a/tableView.go b/tableView.go index 01840c5..50344cd 100644 --- a/tableView.go +++ b/tableView.go @@ -2,6 +2,7 @@ package rui import ( "fmt" + "iter" "strconv" "strings" ) @@ -1694,6 +1695,20 @@ func (table *tableViewData) Views() []View { return table.cellViews } +func (table *tableViewData) ViewSeq() iter.Seq[View] { + return func(yield func(View) bool) { + for _, view := range table.cellViews { + if !yield(view) { + return + } + } + } +} + +func (table *tableViewData) ViewCount() int { + return len(table.cellViews) +} + func (table *tableViewData) handleCommand(self View, command PropertyName, data DataObject) bool { switch command { case "currentRow": diff --git a/viewsContainer.go b/viewsContainer.go index d925653..42e50ad 100644 --- a/viewsContainer.go +++ b/viewsContainer.go @@ -1,11 +1,20 @@ package rui -import "strings" +import ( + "iter" + "strings" +) // ParentView describe a view which can have a child views type ParentView interface { - // Views return a list of child views + // Views returns a list of child views Views() []View + + // ViewSeq returns an iterator over all child views + ViewSeq() iter.Seq[View] + + // ViewCount returns a number of child views + ViewCount() int } // ViewsContainer represent a mutable list-container of views @@ -67,6 +76,24 @@ func (container *viewsContainerData) Views() []View { return []View{} } +func (container *viewsContainerData) ViewSeq() iter.Seq[View] { + if container.views == nil { + container.views = []View{} + } + + return func(yield func(View) bool) { + for _, view := range container.views { + if !yield(view) { + return + } + } + } +} + +func (container *viewsContainerData) ViewCount() int { + return len(container.views) +} + func (container *viewsContainerData) append(view View) bool { if view != nil { view.setParentID(container.htmlID())