Added ViewSeq add ViewCount methods to ParentView interface

This commit is contained in:
Alexei Anoshenko 2026-06-16 11:53:02 +03:00
parent 69a4d1e712
commit 7214eda01d
5 changed files with 76 additions and 2 deletions

View File

@ -5,6 +5,7 @@
* Added functions: GetWhiteSpace, GetWordBreak, ScrollIntoViewIfNeeded * Added functions: GetWhiteSpace, GetWordBreak, ScrollIntoViewIfNeeded
* Added Popups, PopupShowAnimation, and SetPopupShowAnimation methods to Session interface * Added Popups, PopupShowAnimation, and SetPopupShowAnimation methods to Session interface
* Added DismissWithoutAnimation add SetHotKey methods to Popup interface * Added DismissWithoutAnimation add SetHotKey methods to Popup interface
* Added ViewSeq add ViewCount methods to ParentView interface
* Added ToBoundsProperty method to Bounds struct * Added ToBoundsProperty method to Bounds struct
# v0.20.0 # v0.20.0

View File

@ -2,6 +2,7 @@ package rui
import ( import (
"fmt" "fmt"
"iter"
"strconv" "strconv"
"strings" "strings"
) )
@ -161,6 +162,20 @@ func (listView *listViewData) Views() []View {
return listView.items 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 { func normalizeListViewTag(tag PropertyName) PropertyName {
tag = defaultNormalize(tag) tag = defaultNormalize(tag)
switch tag { switch tag {

View File

@ -2,6 +2,7 @@ package rui
import ( import (
"fmt" "fmt"
"iter"
"strconv" "strconv"
"strings" "strings"
) )
@ -91,6 +92,21 @@ func (resizable *resizableData) Views() []View {
return []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 { func (resizable *resizableData) content() View {
if value := resizable.getRaw(Content); value != nil { if value := resizable.getRaw(Content); value != nil {
if content, ok := value.(View); ok { if content, ok := value.(View); ok {

View File

@ -2,6 +2,7 @@ package rui
import ( import (
"fmt" "fmt"
"iter"
"strconv" "strconv"
"strings" "strings"
) )
@ -1694,6 +1695,20 @@ func (table *tableViewData) Views() []View {
return table.cellViews 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 { func (table *tableViewData) handleCommand(self View, command PropertyName, data DataObject) bool {
switch command { switch command {
case "currentRow": case "currentRow":

View File

@ -1,11 +1,20 @@
package rui package rui
import "strings" import (
"iter"
"strings"
)
// ParentView describe a view which can have a child views // ParentView describe a view which can have a child views
type ParentView interface { type ParentView interface {
// Views return a list of child views // Views returns a list of child views
Views() []View 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 // ViewsContainer represent a mutable list-container of views
@ -67,6 +76,24 @@ func (container *viewsContainerData) Views() []View {
return []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 { func (container *viewsContainerData) append(view View) bool {
if view != nil { if view != nil {
view.setParentID(container.htmlID()) view.setParentID(container.htmlID())