@@ -17,8 +17,8 @@ type container struct {
1717 open bool
1818 collapsed bool
1919
20- toggledIDs map [widgetID ]struct {}
21- textInputTextFields map [widgetID ]* textinput.Field
20+ toggledIDs map [WidgetID ]struct {}
21+ textInputTextFields map [WidgetID ]* textinput.Field
2222}
2323
2424// ContainerLayout represents the layout of a container widget.
@@ -37,7 +37,7 @@ type ContainerLayout struct {
3737 ScrollOffset image.Point
3838}
3939
40- func (c * Context ) container (id widgetID , opt option ) * container {
40+ func (c * Context ) container (id WidgetID , opt option ) * container {
4141 if container , ok := c .idToContainer [id ]; ok {
4242 c .addUsedContainer (id )
4343 return container
@@ -48,7 +48,7 @@ func (c *Context) container(id widgetID, opt option) *container {
4848 }
4949
5050 if c .idToContainer == nil {
51- c .idToContainer = map [widgetID ]* container {}
51+ c .idToContainer = map [WidgetID ]* container {}
5252 }
5353 cnt := & container {
5454 headIdx : - 1 ,
@@ -76,15 +76,15 @@ func (c *Context) Window(title string, rect image.Rectangle, f func(layout Conta
7676 })
7777}
7878
79- func (c * Context ) window (title string , bounds image.Rectangle , opt option , id widgetID , f func (layout ContainerLayout )) error {
79+ func (c * Context ) window (title string , bounds image.Rectangle , opt option , id WidgetID , f func (layout ContainerLayout )) error {
8080 var err error
8181 c .idScopeFromID (id , func () {
8282 err = c .doWindow (title , bounds , opt , id , f )
8383 })
8484 return err
8585}
8686
87- func (c * Context ) doWindow (title string , bounds image.Rectangle , opt option , id widgetID , f func (layout ContainerLayout )) (err error ) {
87+ func (c * Context ) doWindow (title string , bounds image.Rectangle , opt option , id WidgetID , f func (layout ContainerLayout )) (err error ) {
8888 cnt := c .container (id , opt )
8989 if cnt == nil || ! cnt .open {
9090 return nil
@@ -296,31 +296,34 @@ func (c *Context) SetScroll(scroll image.Point) {
296296 c .currentContainer ().layout .ScrollOffset = scroll
297297}
298298
299- func (c * container ) textInputTextField (id widgetID ) * textinput.Field {
299+ func (c * container ) textInputTextField (id WidgetID , createIfNeeded bool ) * textinput.Field {
300300 if id == emptyWidgetID {
301301 return nil
302302 }
303303 if _ , ok := c .textInputTextFields [id ]; ! ok {
304+ if ! createIfNeeded {
305+ return nil
306+ }
304307 if c .textInputTextFields == nil {
305- c .textInputTextFields = make (map [widgetID ]* textinput.Field )
308+ c .textInputTextFields = make (map [WidgetID ]* textinput.Field )
306309 }
307310 c .textInputTextFields [id ] = & textinput.Field {}
308311 }
309312 return c .textInputTextFields [id ]
310313}
311314
312- func (c * container ) toggled (id widgetID ) bool {
315+ func (c * container ) toggled (id WidgetID ) bool {
313316 _ , ok := c .toggledIDs [id ]
314317 return ok
315318}
316319
317- func (c * container ) toggle (id widgetID ) {
320+ func (c * container ) toggle (id WidgetID ) {
318321 if _ , toggled := c .toggledIDs [id ]; toggled {
319322 delete (c .toggledIDs , id )
320323 return
321324 }
322325 if c .toggledIDs == nil {
323- c .toggledIDs = map [widgetID ]struct {}{}
326+ c .toggledIDs = map [WidgetID ]struct {}{}
324327 }
325328 c .toggledIDs [id ] = struct {}{}
326329}
0 commit comments