@@ -28,8 +28,7 @@ type Context struct {
2828 numberEdit WidgetID
2929
3030 idStack []WidgetID
31- commandList []* command
32- rootList []* container
31+ rootContainers []* container
3332 containerStack []* container
3433 usedContainers map [WidgetID ]struct {}
3534 clipStack []image.Rectangle
@@ -69,8 +68,10 @@ func (c *Context) update(f func(ctx *Context) error) (err error) {
6968}
7069
7170func (c * Context ) begin () {
72- c .commandList = slices .Delete (c .commandList , 0 , len (c .commandList ))
73- c .rootList = slices .Delete (c .rootList , 0 , len (c .rootList ))
71+ for _ , cnt := range c .rootContainers {
72+ cnt .commandList = slices .Delete (cnt .commandList , 0 , len (cnt .commandList ))
73+ }
74+ c .rootContainers = slices .Delete (c .rootContainers , 0 , len (c .rootContainers ))
7475 c .scrollTarget = nil
7576 c .hoverRoot = c .nextHoverRoot
7677 c .nextHoverRoot = nil
@@ -116,34 +117,10 @@ func (c *Context) end() error {
116117 c .lastPointingPos = c .pointingPosition ()
117118
118119 // sort root containers by zindex
119- sort .SliceStable (c .rootList , func (i , j int ) bool {
120- return c .rootList [i ].zIndex < c .rootList [j ].zIndex
120+ sort .SliceStable (c .rootContainers , func (i , j int ) bool {
121+ return c .rootContainers [i ].zIndex < c .rootContainers [j ].zIndex
121122 })
122123
123- // set root container jump commands
124- for i := range c .rootList {
125- cnt := c .rootList [i ]
126- // if this is the first container then make the first command jump to it.
127- // otherwise set the previous container's tail to jump to this one
128- if i == 0 {
129- cmd := c .commandList [0 ]
130- if cmd .typ != commandJump {
131- panic ("debugui: expected jump command" )
132- }
133- cmd .jump .dstIdx = cnt .headIdx + 1
134- if cnt .headIdx >= len (c .commandList ) {
135- panic ("debugui: invalid head index" )
136- }
137- } else {
138- prev := c .rootList [i - 1 ]
139- c .commandList [prev .tailIdx ].jump .dstIdx = cnt .headIdx + 1
140- }
141- // make the last container's tail jump to the end of command list
142- if i == len (c .rootList )- 1 {
143- c .commandList [cnt .tailIdx ].jump .dstIdx = len (c .commandList )
144- }
145- }
146-
147124 for id := range c .idToContainer {
148125 if _ , ok := c .usedContainers [id ]; ! ok {
149126 delete (c .idToContainer , id )
0 commit comments