forked from zeozeozeo/microui-go
-
Notifications
You must be signed in to change notification settings - Fork 3
/
controls.go
726 lines (643 loc) · 18.3 KB
/
controls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024 The Ebitengine Authors
package debugui
import (
"fmt"
"image"
"math"
"os"
"strconv"
"unicode/utf8"
"unsafe"
"github.com/hajimehoshi/ebiten/v2/exp/textinput"
)
func (c *Context) inHoverRoot() bool {
for i := len(c.containerStack) - 1; i >= 0; i-- {
if c.containerStack[i] == c.hoverRoot {
return true
}
// only root containers have their `head` field set; stop searching if we've
// reached the current root container
if c.containerStack[i].headIdx >= 0 {
break
}
}
return false
}
func (c *Context) drawControlFrame(id controlID, rect image.Rectangle, colorid int, opt option) {
if (opt & optionNoFrame) != 0 {
return
}
if c.focus == id {
colorid += 2
} else if c.hover == id {
colorid++
}
c.drawFrame(rect, colorid)
}
func (c *Context) drawControlText(str string, rect image.Rectangle, colorid int, opt option) {
var pos image.Point
tw := textWidth(str)
c.pushClipRect(rect)
pos.Y = rect.Min.Y + (rect.Dy()-lineHeight())/2
if (opt & optionAlignCenter) != 0 {
pos.X = rect.Min.X + (rect.Dx()-tw)/2
} else if (opt & optionAlignRight) != 0 {
pos.X = rect.Min.X + rect.Dx() - tw - c.style.padding
} else {
pos.X = rect.Min.X + c.style.padding
}
c.drawText(str, pos, c.style.colors[colorid])
c.popClipRect()
}
func (c *Context) mouseOver(rect image.Rectangle) bool {
return c.mousePos.In(rect) && c.mousePos.In(c.clipRect()) && c.inHoverRoot()
}
func (c *Context) updateControl(id controlID, rect image.Rectangle, opt option) {
if id == 0 {
return
}
mouseover := c.mouseOver(rect)
if c.focus == id {
c.keepFocus = true
}
if (opt & optionNoInteract) != 0 {
return
}
if mouseover && c.mouseDown == 0 {
c.hover = id
}
if c.focus == id {
if c.mousePressed != 0 && !mouseover {
c.setFocus(0)
}
if c.mouseDown == 0 && (^opt&optionHoldFocus) != 0 {
c.setFocus(0)
}
}
if c.hover == id {
if c.mousePressed != 0 {
c.setFocus(id)
} else if !mouseover {
c.hover = 0
}
}
}
func (c *Context) Control(idStr string, f func(r image.Rectangle) Response) Response {
id := c.pushID([]byte(idStr))
defer c.popID()
return c.control(id, 0, f)
}
func (c *Context) control(id controlID, opt option, f func(r image.Rectangle) Response) Response {
r := c.layoutNext()
c.updateControl(id, r, opt)
return f(r)
}
func (c *Context) Text(text string) {
color := c.style.colors[ColorText]
c.LayoutColumn(func() {
var endIdx, p int
c.SetLayoutRow([]int{-1}, lineHeight())
for endIdx < len(text) {
c.control(0, 0, func(r image.Rectangle) Response {
w := 0
endIdx = p
startIdx := endIdx
for endIdx < len(text) && text[endIdx] != '\n' {
word := p
for p < len(text) && text[p] != ' ' && text[p] != '\n' {
p++
}
w += textWidth(text[word:p])
if w > r.Dx() && endIdx != startIdx {
break
}
if p < len(text) {
w += textWidth(string(text[p]))
}
endIdx = p
p++
}
c.drawText(text[startIdx:endIdx], r.Min, color)
p = endIdx + 1
return 0
})
}
})
}
func (c *Context) Label(text string) {
c.control(0, 0, func(r image.Rectangle) Response {
c.drawControlText(text, r, ColorText, 0)
return 0
})
}
func (c *Context) button(label string, idStr string, opt option) Response {
var id controlID
if len(idStr) > 0 {
id = c.pushID([]byte(idStr))
defer c.popID()
} else if len(label) > 0 {
id = c.pushID([]byte(label))
defer c.popID()
}
return c.control(id, opt, func(r image.Rectangle) Response {
var res Response
// handle click
if c.mousePressed == mouseLeft && c.focus == id {
res |= ResponseSubmit
}
// draw
c.drawControlFrame(id, r, ColorButton, opt)
if len(label) > 0 {
c.drawControlText(label, r, ColorText, opt)
}
return res
})
}
func (c *Context) Checkbox(label string, state *bool) Response {
id := c.pushID(ptrToBytes(unsafe.Pointer(state)))
defer c.popID()
return c.control(id, 0, func(r image.Rectangle) Response {
var res Response
box := image.Rect(r.Min.X, r.Min.Y, r.Min.X+r.Dy(), r.Max.Y)
c.updateControl(id, r, 0)
// handle click
if c.mousePressed == mouseLeft && c.focus == id {
res |= ResponseChange
*state = !*state
}
// draw
c.drawControlFrame(id, box, ColorBase, 0)
if *state {
c.drawIcon(iconCheck, box, c.style.colors[ColorText])
}
r = image.Rect(r.Min.X+box.Dx(), r.Min.Y, r.Max.X, r.Max.Y)
c.drawControlText(label, r, ColorText, 0)
return res
})
}
func (c *Context) textField(id controlID) *textinput.Field {
if id == 0 {
return nil
}
if _, ok := c.textFields[id]; !ok {
if c.textFields == nil {
c.textFields = make(map[controlID]*textinput.Field)
}
c.textFields[id] = &textinput.Field{}
}
return c.textFields[id]
}
func (c *Context) textBoxRaw(buf *string, id controlID, opt option) Response {
return c.control(id, opt|optionHoldFocus, func(r image.Rectangle) Response {
var res Response
if c.focus == id {
// handle text input
f := c.textField(id)
f.Focus()
x := r.Min.X + c.style.padding + textWidth(*buf)
y := r.Min.Y + lineHeight()
handled, err := f.HandleInput(x, y)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return 0
}
if *buf != f.TextForRendering() {
*buf = f.TextForRendering()
res |= ResponseChange
}
if !handled {
// handle backspace
if (c.keyPressed&keyBackspace) != 0 && len(*buf) > 0 {
_, size := utf8.DecodeLastRuneInString(*buf)
*buf = (*buf)[:len(*buf)-size]
f.SetTextAndSelection(*buf, len(*buf), len(*buf))
res |= ResponseChange
}
// handle return
if (c.keyPressed & keyReturn) != 0 {
c.setFocus(0)
res |= ResponseSubmit
f.SetTextAndSelection("", 0, 0)
}
}
} else {
f := c.textField(id)
if *buf != f.TextForRendering() {
f.SetTextAndSelection(*buf, len(*buf), len(*buf))
}
}
// draw
c.drawControlFrame(id, r, ColorBase, opt)
if c.focus == id {
color := c.style.colors[ColorText]
textw := textWidth(*buf)
texth := lineHeight()
ofx := r.Dx() - c.style.padding - textw - 1
textx := r.Min.X + min(ofx, c.style.padding)
texty := r.Min.Y + (r.Dy()-texth)/2
c.pushClipRect(r)
c.drawText(*buf, image.Pt(textx, texty), color)
c.drawRect(image.Rect(textx+textw, texty, textx+textw+1, texty+texth), color)
c.popClipRect()
} else {
c.drawControlText(*buf, r, ColorText, opt)
}
return res
})
}
func (c *Context) numberTextBox(value *float64, id controlID) bool {
if c.mousePressed == mouseLeft && (c.keyDown&keyShift) != 0 &&
c.hover == id {
c.numberEdit = id
c.numberEditBuf = fmt.Sprintf(realFmt, *value)
}
if c.numberEdit == id {
res := c.textBoxRaw(&c.numberEditBuf, id, 0)
if (res&ResponseSubmit) != 0 || c.focus != id {
nval, err := strconv.ParseFloat(c.numberEditBuf, 32)
if err != nil {
nval = 0
}
*value = float64(nval)
c.numberEdit = 0
}
return true
}
return false
}
func (c *Context) textBox(buf *string, opt option) Response {
id := c.pushID(ptrToBytes(unsafe.Pointer(buf)))
defer c.popID()
return c.textBoxRaw(buf, id, opt)
}
func formatNumber(v float64, digits int) string {
return fmt.Sprintf("%."+strconv.Itoa(digits)+"f", v)
}
func (c *Context) slider(value *float64, low, high, step float64, digits int, opt option) Response {
last := *value
v := last
id := c.pushID(ptrToBytes(unsafe.Pointer(value)))
defer c.popID()
// handle text input mode
if c.numberTextBox(&v, id) {
return 0
}
// handle normal mode
return c.control(id, opt, func(r image.Rectangle) Response {
var res Response
// handle input
if c.focus == id && (c.mouseDown|c.mousePressed) == mouseLeft {
v = low + float64(c.mousePos.X-r.Min.X)*(high-low)/float64(r.Dx())
if step != 0 {
v = math.Round(v/step) * step
}
}
// clamp and store value, update res
*value = clampF(v, low, high)
v = *value
if last != v {
res |= ResponseChange
}
// draw base
c.drawControlFrame(id, r, ColorBase, opt)
// draw thumb
w := c.style.thumbSize
x := int((v - low) * float64(r.Dx()-w) / (high - low))
thumb := image.Rect(r.Min.X+x, r.Min.Y, r.Min.X+x+w, r.Max.Y)
c.drawControlFrame(id, thumb, ColorButton, opt)
// draw text
text := formatNumber(v, digits)
c.drawControlText(text, r, ColorText, opt)
return res
})
}
func (c *Context) number(value *float64, step float64, digits int, opt option) Response {
id := c.pushID(ptrToBytes(unsafe.Pointer(value)))
defer c.popID()
last := *value
// handle text input mode
if c.numberTextBox(value, id) {
return 0
}
// handle normal mode
return c.control(id, opt, func(r image.Rectangle) Response {
var res Response
// handle input
if c.focus == id && c.mouseDown == mouseLeft {
*value += float64(c.mouseDelta.X) * step
}
// set flag if value changed
if *value != last {
res |= ResponseChange
}
// draw base
c.drawControlFrame(id, r, ColorBase, opt)
// draw text
text := formatNumber(*value, digits)
c.drawControlText(text, r, ColorText, opt)
return res
})
}
func (c *Context) header(label string, idStr string, istreenode bool, opt option) Response {
var id controlID
if len(idStr) > 0 {
id = c.pushID([]byte(idStr))
defer c.popID()
} else if len(label) > 0 {
id = c.pushID([]byte(label))
defer c.popID()
}
idx := c.poolGet(c.treeNodePool[:], id)
c.SetLayoutRow([]int{-1}, 0)
active := idx >= 0
var expanded bool
if (opt & optionExpanded) != 0 {
expanded = !active
} else {
expanded = active
}
return c.control(id, 0, func(r image.Rectangle) Response {
// handle click (TODO (port): check if this is correct)
clicked := c.mousePressed == mouseLeft && c.focus == id
v1, v2 := 0, 0
if active {
v1 = 1
}
if clicked {
v2 = 1
}
active = (v1 ^ v2) == 1
// update pool ref
if idx >= 0 {
if active {
c.poolUpdate(c.treeNodePool[:], idx)
} else {
c.treeNodePool[idx] = poolItem{}
}
} else if active {
c.poolInit(c.treeNodePool[:], id)
}
// draw
if istreenode {
if c.hover == id {
c.drawFrame(r, ColorButtonHover)
}
} else {
c.drawControlFrame(id, r, ColorButton, 0)
}
var icon icon
if expanded {
icon = iconExpanded
} else {
icon = iconCollapsed
}
c.drawIcon(
icon,
image.Rect(r.Min.X, r.Min.Y, r.Min.X+r.Dy(), r.Max.Y),
c.style.colors[ColorText],
)
r.Min.X += r.Dy() - c.style.padding
c.drawControlText(label, r, ColorText, 0)
if expanded {
return ResponseActive
}
return 0
})
}
func (c *Context) treeNode(label string, idStr string, opt option, f func(res Response)) {
res := c.header(label, idStr, true, opt)
if res&ResponseActive == 0 {
return
}
c.layout().indent += c.style.indent
defer func() {
c.layout().indent -= c.style.indent
}()
f(res)
}
// x = x, y = y, w = w, h = h
func (c *Context) scrollbarVertical(cnt *container, b image.Rectangle, cs image.Point) {
maxscroll := cs.Y - b.Dy()
if maxscroll > 0 && b.Dy() > 0 {
// get sizing / positioning
base := b
base.Min.X = b.Max.X
base.Max.X = base.Min.X + c.style.scrollbarSize
// handle input
id := c.idFromBytes([]byte("!scrollbar" + "y"))
c.updateControl(id, base, 0)
if c.focus == id && c.mouseDown == mouseLeft {
cnt.layout.Scroll.Y += c.mouseDelta.Y * cs.Y / base.Dy()
}
// clamp scroll to limits
cnt.layout.Scroll.Y = clamp(cnt.layout.Scroll.Y, 0, maxscroll)
// draw base and thumb
c.drawFrame(base, ColorScrollBase)
thumb := base
thumb.Max.Y = thumb.Min.Y + max(c.style.thumbSize, base.Dy()*b.Dy()/cs.Y)
thumb = thumb.Add(image.Pt(0, cnt.layout.Scroll.Y*(base.Dy()-thumb.Dy())/maxscroll))
c.drawFrame(thumb, ColorScrollThumb)
// set this as the scroll_target (will get scrolled on mousewheel)
// if the mouse is over it
if c.mouseOver(b) {
c.scrollTarget = cnt
}
} else {
cnt.layout.Scroll.Y = 0
}
}
// x = y, y = x, w = h, h = w
func (c *Context) scrollbarHorizontal(cnt *container, b image.Rectangle, cs image.Point) {
maxscroll := cs.X - b.Dx()
if maxscroll > 0 && b.Dx() > 0 {
// get sizing / positioning
base := b
base.Min.Y = b.Max.Y
base.Max.Y = base.Min.Y + c.style.scrollbarSize
// handle input
id := c.idFromBytes([]byte("!scrollbar" + "x"))
c.updateControl(id, base, 0)
if c.focus == id && c.mouseDown == mouseLeft {
cnt.layout.Scroll.X += c.mouseDelta.X * cs.X / base.Dx()
}
// clamp scroll to limits
cnt.layout.Scroll.X = clamp(cnt.layout.Scroll.X, 0, maxscroll)
// draw base and thumb
c.drawFrame(base, ColorScrollBase)
thumb := base
thumb.Max.X = thumb.Min.X + max(c.style.thumbSize, base.Dx()*b.Dx()/cs.X)
thumb = thumb.Add(image.Pt(cnt.layout.Scroll.X*(base.Dx()-thumb.Dx())/maxscroll, 0))
c.drawFrame(thumb, ColorScrollThumb)
// set this as the scroll_target (will get scrolled on mousewheel)
// if the mouse is over it
if c.mouseOver(b) {
c.scrollTarget = cnt
}
} else {
cnt.layout.Scroll.X = 0
}
}
// if `swap` is true, X = Y, Y = X, W = H, H = W
func (c *Context) scrollbar(cnt *container, b image.Rectangle, cs image.Point, swap bool) {
if swap {
c.scrollbarHorizontal(cnt, b, cs)
} else {
c.scrollbarVertical(cnt, b, cs)
}
}
func (c *Context) scrollbars(cnt *container, body image.Rectangle) image.Rectangle {
sz := c.style.scrollbarSize
cs := cnt.layout.ContentSize
cs.X += c.style.padding * 2
cs.Y += c.style.padding * 2
c.pushClipRect(body)
// resize body to make room for scrollbars
if cs.Y > cnt.layout.Body.Dy() {
body.Max.X -= sz
}
if cs.X > cnt.layout.Body.Dx() {
body.Max.Y -= sz
}
// to create a horizontal or vertical scrollbar almost-identical code is
// used; only the references to `x|y` `w|h` need to be switched
c.scrollbar(cnt, body, cs, false)
c.scrollbar(cnt, body, cs, true)
c.popClipRect()
return body
}
func (c *Context) pushContainerBody(cnt *container, body image.Rectangle, opt option) {
if (^opt & optionNoScroll) != 0 {
body = c.scrollbars(cnt, body)
}
c.pushLayout(body.Inset(c.style.padding), cnt.layout.Scroll)
cnt.layout.Body = body
}
func (c *Context) window(title string, idStr string, rect image.Rectangle, opt option, f func(res Response, layout Layout)) {
var id controlID
if len(idStr) > 0 {
id = c.pushID([]byte(idStr))
defer c.popID()
} else if len(title) > 0 {
id = c.pushID([]byte(title))
defer c.popID()
}
cnt := c.container(id, opt)
if cnt == nil || !cnt.open {
return
}
// This is popped at endRootContainer.
// TODO: This is tricky. Refactor this.
if cnt.layout.Rect.Dx() == 0 {
cnt.layout.Rect = rect
}
c.containerStack = append(c.containerStack, cnt)
defer c.popContainer()
// push container to roots list and push head command
c.rootList = append(c.rootList, cnt)
cnt.headIdx = c.pushJump(-1)
defer func() {
// push tail 'goto' jump command and set head 'skip' command. the final steps
// on initing these are done in End
cnt := c.currentContainer()
cnt.tailIdx = c.pushJump(-1)
c.commandList[cnt.headIdx].jump.dstIdx = len(c.commandList) //- 1
}()
// set as hover root if the mouse is overlapping this container and it has a
// higher zindex than the current hover root
if c.mousePos.In(cnt.layout.Rect) && (c.nextHoverRoot == nil || cnt.zIndex > c.nextHoverRoot.zIndex) {
c.nextHoverRoot = cnt
}
// clipping is reset here in case a root-container is made within
// another root-containers's begin/end block; this prevents the inner
// root-container being clipped to the outer
c.clipStack = append(c.clipStack, unclippedRect)
defer c.popClipRect()
body := cnt.layout.Rect
rect = body
// draw frame
if (^opt & optionNoFrame) != 0 {
c.drawFrame(rect, ColorWindowBG)
}
// do title bar
if (^opt & optionNoTitle) != 0 {
tr := rect
tr.Max.Y = tr.Min.Y + c.style.titleHeight
c.drawFrame(tr, ColorTitleBG)
// do title text
if (^opt & optionNoTitle) != 0 {
id := c.idFromBytes([]byte("!title"))
c.updateControl(id, tr, opt)
c.drawControlText(title, tr, ColorTitleText, opt)
if id == c.focus && c.mouseDown == mouseLeft {
cnt.layout.Rect = cnt.layout.Rect.Add(c.mouseDelta)
}
body.Min.Y += tr.Dy()
}
// do `close` button
if (^opt & optionNoClose) != 0 {
id := c.idFromBytes([]byte("!close"))
r := image.Rect(tr.Max.X-tr.Dy(), tr.Min.Y, tr.Max.X, tr.Max.Y)
tr.Max.X -= r.Dx()
c.drawIcon(iconClose, r, c.style.colors[ColorTitleText])
c.updateControl(id, r, opt)
if c.mousePressed == mouseLeft && id == c.focus {
cnt.open = false
}
}
}
c.pushContainerBody(cnt, body, opt)
// do `resize` handle
if (^opt & optionNoResize) != 0 {
sz := c.style.titleHeight
id := c.idFromBytes([]byte("!resize"))
r := image.Rect(rect.Max.X-sz, rect.Max.Y-sz, rect.Max.X, rect.Max.Y)
c.updateControl(id, r, opt)
if id == c.focus && c.mouseDown == mouseLeft {
cnt.layout.Rect.Max.X = cnt.layout.Rect.Min.X + max(96, cnt.layout.Rect.Dx()+c.mouseDelta.X)
cnt.layout.Rect.Max.Y = cnt.layout.Rect.Min.Y + max(64, cnt.layout.Rect.Dy()+c.mouseDelta.Y)
}
}
// resize to content size
if (opt & optionAutoSize) != 0 {
r := c.layout().body
cnt.layout.Rect.Max.X = cnt.layout.Rect.Min.X + cnt.layout.ContentSize.X + (cnt.layout.Rect.Dx() - r.Dx())
cnt.layout.Rect.Max.Y = cnt.layout.Rect.Min.Y + cnt.layout.ContentSize.Y + (cnt.layout.Rect.Dy() - r.Dy())
}
// close if this is a popup window and elsewhere was clicked
if (opt&optionPopup) != 0 && c.mousePressed != 0 && c.hoverRoot != cnt {
cnt.open = false
}
c.pushClipRect(cnt.layout.Body)
defer c.popClipRect()
f(ResponseActive, c.currentContainer().layout)
}
func (c *Context) OpenPopup(name string) {
cnt := c.Container(name)
// set as hover root so popup isn't closed in begin_window_ex()
c.nextHoverRoot = cnt
c.hoverRoot = c.nextHoverRoot
// position at mouse cursor, open and bring-to-front
cnt.layout.Rect = image.Rect(c.mousePos.X, c.mousePos.Y, c.mousePos.X+1, c.mousePos.Y+1)
cnt.open = true
c.bringToFront(cnt)
}
func (c *Context) Popup(name string, f func(res Response, layout Layout)) {
opt := optionPopup | optionAutoSize | optionNoResize | optionNoScroll | optionNoTitle | optionClosed
c.window(name, "", image.Rectangle{}, opt, f)
}
func (c *Context) panel(name string, opt option, f func(layout Layout)) {
id := c.pushID([]byte(name))
defer c.popID()
cnt := c.container(id, opt)
cnt.layout.Rect = c.layoutNext()
if (^opt & optionNoFrame) != 0 {
c.drawFrame(cnt.layout.Rect, ColorPanelBG)
}
c.containerStack = append(c.containerStack, cnt)
c.pushContainerBody(cnt, cnt.layout.Rect, opt)
defer c.popContainer()
c.pushClipRect(cnt.layout.Body)
defer c.popClipRect()
f(c.currentContainer().layout)
}