@@ -147,46 +147,52 @@ func (c *Context) doWindow(title string, bounds image.Rectangle, opt option, id
147147 if (^ opt & optionNoTitle ) != 0 {
148148 id := c .idFromString ("title" )
149149 r := image .Rect (tr .Min .X + tr .Dy ()- c .style ().padding , tr .Min .Y , tr .Max .X , tr .Max .Y )
150- c . handleInputForWidget (id , r , opt )
151- c . drawWidgetText ( title , r , colorTitleText , opt )
152- if id == c . focus && c . pointing . pressed () {
153- b := cnt . layout . Bounds . Add ( c . pointingDelta ())
154- if c . screenWidth > 0 {
155- maxX := b . Max . X
156- if maxX >= c .screenWidth / c .Scale () {
157- b = b . Add ( image . Pt ( c . screenWidth / c . Scale () - maxX , 0 ))
150+ _ = c . widgetWithBounds (id , opt , r , func ( bounds image. Rectangle , wasFocused bool ) EventHandler {
151+ if id == c . focus && c . pointing . pressed () {
152+ b := cnt . layout . Bounds . Add ( c . pointingDelta ())
153+ if c . screenWidth > 0 {
154+ maxX := b . Max . X
155+ if maxX >= c . screenWidth / c . Scale () {
156+ b = b . Add ( image . Pt ( c .screenWidth / c .Scale ()- maxX , 0 ))
157+ }
158158 }
159- }
160- if b .Min .X < 0 {
161- b = b .Add (image .Pt (- b .Min .X , 0 ))
162- }
163- if c .screenHeight > 0 {
164- maxY := b .Min .Y + tr .Dy ()
165- if maxY >= c .screenHeight / c .Scale ()- c .style ().padding {
166- b = b .Add (image .Pt (0 , c .screenHeight / c .Scale ()- maxY ))
159+ if b .Min .X < 0 {
160+ b = b .Add (image .Pt (- b .Min .X , 0 ))
167161 }
162+ if c .screenHeight > 0 {
163+ maxY := b .Min .Y + tr .Dy ()
164+ if maxY >= c .screenHeight / c .Scale ()- c .style ().padding {
165+ b = b .Add (image .Pt (0 , c .screenHeight / c .Scale ()- maxY ))
166+ }
167+ }
168+ if b .Min .Y < 0 {
169+ b = b .Add (image .Pt (0 , - b .Min .Y ))
170+ }
171+ cnt .layout .Bounds = b
168172 }
169- if b .Min .Y < 0 {
170- b = b .Add (image .Pt (0 , - b .Min .Y ))
171- }
172- cnt .layout .Bounds = b
173- }
174- body .Min .Y += tr .Dy ()
173+ body .Min .Y += tr .Dy ()
174+ return nil
175+ }, func (bounds image.Rectangle ) {
176+ c .drawWidgetText (title , r , colorTitleText , opt )
177+ })
175178 }
176179
177180 // do `collapse` button
178181 if (^ opt & optionNoClose ) != 0 {
179182 id := c .idFromString ("collapse" )
180183 r := image .Rect (tr .Min .X , tr .Min .Y , tr .Min .X + tr .Dy (), tr .Max .Y )
181- icon := iconExpanded
182- if collapsed {
183- icon = iconCollapsed
184- }
185- c .drawIcon (icon , r , c .style ().colors [colorTitleText ])
186- c .handleInputForWidget (id , r , opt )
187- if c .pointing .justPressed () && id == c .focus {
188- cnt .collapsed = ! cnt .collapsed
189- }
184+ _ = c .widgetWithBounds (id , opt , r , func (bounds image.Rectangle , wasFocused bool ) EventHandler {
185+ if c .pointing .justPressed () && id == c .focus {
186+ cnt .collapsed = ! cnt .collapsed
187+ }
188+ return nil
189+ }, func (bounds image.Rectangle ) {
190+ icon := iconExpanded
191+ if collapsed {
192+ icon = iconCollapsed
193+ }
194+ c .drawIcon (icon , r , c .style ().colors [colorTitleText ])
195+ })
190196 }
191197 }
192198
@@ -208,11 +214,13 @@ func (c *Context) doWindow(title string, bounds image.Rectangle, opt option, id
208214 sz := c .style ().titleHeight
209215 id := c .idFromString ("resize" )
210216 r := image .Rect (bounds .Max .X - sz , bounds .Max .Y - sz , bounds .Max .X , bounds .Max .Y )
211- c .handleInputForWidget (id , r , opt )
212- if id == c .focus && c .pointing .pressed () {
213- cnt .layout .Bounds .Max .X = min (cnt .layout .Bounds .Min .X + max (96 , cnt .layout .Bounds .Dx ()+ c .pointingDelta ().X ), c .screenWidth / c .Scale ())
214- cnt .layout .Bounds .Max .Y = min (cnt .layout .Bounds .Min .Y + max (64 , cnt .layout .Bounds .Dy ()+ c .pointingDelta ().Y ), c .screenHeight / c .Scale ())
215- }
217+ _ = c .widgetWithBounds (id , 0 , r , func (bounds image.Rectangle , wasFocused bool ) EventHandler {
218+ if id == c .focus && c .pointing .pressed () {
219+ cnt .layout .Bounds .Max .X = min (cnt .layout .Bounds .Min .X + max (96 , cnt .layout .Bounds .Dx ()+ c .pointingDelta ().X ), c .screenWidth / c .Scale ())
220+ cnt .layout .Bounds .Max .Y = min (cnt .layout .Bounds .Min .Y + max (64 , cnt .layout .Bounds .Dy ()+ c .pointingDelta ().Y ), c .screenHeight / c .Scale ())
221+ }
222+ return nil
223+ }, nil )
216224 }
217225
218226 // resize to content size
0 commit comments