77 "fmt"
88 "image"
99 "math"
10- "strings"
1110 "unsafe"
1211
1312 "github.com/hajimehoshi/ebiten/v2"
@@ -18,8 +17,6 @@ type controlID string
1817
1918const emptyControlID controlID = ""
2019
21- const idSeparator = "\x00 "
22-
2320type option int
2421
2522const (
@@ -107,11 +104,11 @@ func (c *Context) updateControl(id controlID, bounds image.Rectangle, opt option
107104 return
108105}
109106
110- func (c * Context ) Control (idStr string , f func (bounds image.Rectangle ) bool ) bool {
107+ func (c * Context ) Control (f func (bounds image.Rectangle ) bool ) bool {
111108 pc := caller ()
112109 var res bool
113110 c .wrapError (func () error {
114- id := c .idFromCaller (pc , idStr )
111+ id := c .idFromCaller (pc )
115112 var err error
116113 res , err = c .control (id , 0 , func (bounds image.Rectangle , wasFocused bool ) (bool , error ) {
117114 return f (bounds ), nil
@@ -179,8 +176,7 @@ func (c *Context) Text(text string) {
179176}
180177
181178func (c * Context ) button (label string , opt option , callerPC uintptr ) (controlID , bool , error ) {
182- label , idStr , _ := strings .Cut (label , idSeparator )
183- id := c .idFromCaller (callerPC , idStr )
179+ id := c .idFromCaller (callerPC )
184180 res , err := c .control (id , opt , func (bounds image.Rectangle , wasFocused bool ) (bool , error ) {
185181 var res bool
186182 // handle click
@@ -330,8 +326,7 @@ func (c *Context) sliderF(value *float64, low, high, step float64, digits int, o
330326}
331327
332328func (c * Context ) header (label string , isTreeNode bool , opt option , callerPC uintptr , f func () error ) error {
333- label , idStr , _ := strings .Cut (label , idSeparator )
334- id := c .idFromCaller (callerPC , idStr )
329+ id := c .idFromCaller (callerPC )
335330 c .SetGridLayout (nil , nil )
336331
337332 var expanded bool
@@ -404,7 +399,7 @@ func (c *Context) treeNode(label string, opt option, callerPC uintptr, f func())
404399}
405400
406401// x = x, y = y, w = w, h = h
407- func (c * Context ) scrollbarVertical (cnt * container , b image.Rectangle , cs image.Point , containerID controlID ) {
402+ func (c * Context ) scrollbarVertical (cnt * container , b image.Rectangle , cs image.Point ) {
408403 maxscroll := cs .Y - b .Dy ()
409404 if maxscroll > 0 && b .Dy () > 0 {
410405 // get sizing / positioning
@@ -413,7 +408,7 @@ func (c *Context) scrollbarVertical(cnt *container, b image.Rectangle, cs image.
413408 base .Max .X = base .Min .X + c .style ().scrollbarSize
414409
415410 // handle input
416- id := c .idFromString ("scrollbar-y" , containerID )
411+ id := c .idFromString ("scrollbar-y" )
417412 c .updateControl (id , base , 0 )
418413 if c .focus == id && ebiten .IsMouseButtonPressed (ebiten .MouseButtonLeft ) {
419414 cnt .layout .ScrollOffset .Y += c .mouseDelta ().Y * cs .Y / base .Dy ()
@@ -439,7 +434,7 @@ func (c *Context) scrollbarVertical(cnt *container, b image.Rectangle, cs image.
439434}
440435
441436// x = y, y = x, w = h, h = w
442- func (c * Context ) scrollbarHorizontal (cnt * container , b image.Rectangle , cs image.Point , containerID controlID ) {
437+ func (c * Context ) scrollbarHorizontal (cnt * container , b image.Rectangle , cs image.Point ) {
443438 maxscroll := cs .X - b .Dx ()
444439 if maxscroll > 0 && b .Dx () > 0 {
445440 // get sizing / positioning
@@ -448,7 +443,7 @@ func (c *Context) scrollbarHorizontal(cnt *container, b image.Rectangle, cs imag
448443 base .Max .Y = base .Min .Y + c .style ().scrollbarSize
449444
450445 // handle input
451- id := c .idFromString ("scrollbar-x" , containerID )
446+ id := c .idFromString ("scrollbar-x" )
452447 c .updateControl (id , base , 0 )
453448 if c .focus == id && ebiten .IsMouseButtonPressed (ebiten .MouseButtonLeft ) {
454449 cnt .layout .ScrollOffset .X += c .mouseDelta ().X * cs .X / base .Dx ()
@@ -474,15 +469,15 @@ func (c *Context) scrollbarHorizontal(cnt *container, b image.Rectangle, cs imag
474469}
475470
476471// if `swap` is true, X = Y, Y = X, W = H, H = W
477- func (c * Context ) scrollbar (cnt * container , b image.Rectangle , cs image.Point , swap bool , containerID controlID ) {
472+ func (c * Context ) scrollbar (cnt * container , b image.Rectangle , cs image.Point , swap bool ) {
478473 if swap {
479- c .scrollbarHorizontal (cnt , b , cs , containerID )
474+ c .scrollbarHorizontal (cnt , b , cs )
480475 } else {
481- c .scrollbarVertical (cnt , b , cs , containerID )
476+ c .scrollbarVertical (cnt , b , cs )
482477 }
483478}
484479
485- func (c * Context ) scrollbars (cnt * container , body image.Rectangle , containerID controlID ) image.Rectangle {
480+ func (c * Context ) scrollbars (cnt * container , body image.Rectangle ) image.Rectangle {
486481 sz := c .style ().scrollbarSize
487482 cs := cnt .layout .ContentSize
488483 cs .X += c .style ().padding * 2
@@ -497,15 +492,15 @@ func (c *Context) scrollbars(cnt *container, body image.Rectangle, containerID c
497492 }
498493 // to create a horizontal or vertical scrollbar almost-identical code is
499494 // used; only the references to `x|y` `w|h` need to be switched
500- c .scrollbar (cnt , body , cs , false , containerID )
501- c .scrollbar (cnt , body , cs , true , containerID )
495+ c .scrollbar (cnt , body , cs , false )
496+ c .scrollbar (cnt , body , cs , true )
502497 c .popClipRect ()
503498 return body
504499}
505500
506- func (c * Context ) pushContainerBodyLayout (cnt * container , body image.Rectangle , opt option , containerID controlID ) error {
501+ func (c * Context ) pushContainerBodyLayout (cnt * container , body image.Rectangle , opt option ) error {
507502 if (^ opt & optionNoScroll ) != 0 {
508- body = c .scrollbars (cnt , body , containerID )
503+ body = c .scrollbars (cnt , body )
509504 }
510505 if err := c .pushLayout (body .Inset (c .style ().padding ), cnt .layout .ScrollOffset , opt & optionAutoSize != 0 ); err != nil {
511506 return err
0 commit comments