99 "os"
1010 "strconv"
1111 "unicode/utf8"
12- "unsafe"
1312
1413 "github.com/hajimehoshi/ebiten/v2"
1514 "github.com/hajimehoshi/ebiten/v2/inpututil"
@@ -24,15 +23,16 @@ const (
2423//
2524// TextField returns true when this TextField is unfocused or the user pressed Enter, otherwise false.
2625//
27- // The identifier for a TextField is the pointer value of its buf.
28- // TextField objects with different pointers are considered distinct.
29- // Therefore, for example, you should not provide a pointer to a local variable;
30- // instead, you should provide a pointer to a member variable of a struct or a pointer to a global variable.
26+ // A TextField control is uniquely determined by its call location.
27+ // Function calls made in different locations will create different controls.
28+ // If you want to generate different controls with the same function call in a loop (such as a for loop), use [IDScope].
3129func (c * Context ) TextField (buf * string ) bool {
30+ pc := caller ()
31+ id := c .idFromCaller (pc )
3232 var res bool
3333 c .wrapError (func () error {
3434 var err error
35- res , err = c .textField (buf , 0 )
35+ res , err = c .textField (buf , id , 0 )
3636 if err != nil {
3737 return err
3838 }
@@ -119,8 +119,7 @@ func (c *Context) SetTextFieldValue(value string) {
119119 })
120120}
121121
122- func (c * Context ) textField (buf * string , opt option ) (bool , error ) {
123- id := c .idFromPointer (unsafe .Pointer (buf ))
122+ func (c * Context ) textField (buf * string , id controlID , opt option ) (bool , error ) {
124123 c .lastTextFieldID = id
125124 res , err := c .textFieldRaw (buf , id , opt )
126125 if err != nil {
@@ -135,15 +134,16 @@ func (c *Context) textField(buf *string, opt option) (bool, error) {
135134//
136135// NumberField returns true when the value has been changed, otherwise false.
137136//
138- // The identifier for a NumberField is the pointer value of its value.
139- // NumberField objects with different pointers are considered distinct.
140- // Therefore, for example, you should not provide a pointer to a local variable;
141- // instead, you should provide a pointer to a member variable of a struct or a pointer to a global variable.
137+ // A NumberField control is uniquely determined by its call location.
138+ // Function calls made in different locations will create different controls.
139+ // If you want to generate different controls with the same function call in a loop (such as a for loop), use [IDScope].
142140func (c * Context ) NumberField (value * int , step int ) bool {
141+ pc := caller ()
142+ id := c .idFromCaller (pc )
143143 var res bool
144144 c .wrapError (func () error {
145145 var err error
146- res , err = c .numberField (value , step , optionAlignCenter )
146+ res , err = c .numberField (value , step , id , optionAlignCenter )
147147 if err != nil {
148148 return err
149149 }
@@ -159,15 +159,16 @@ func (c *Context) NumberField(value *int, step int) bool {
159159//
160160// NumberFieldF returns true when the value has been changed, otherwise false.
161161//
162- // The identifier for a NumberFieldF is the pointer value of its value.
163- // NumberFieldF objects with different pointers are considered distinct.
164- // Therefore, for example, you should not provide a pointer to a local variable;
165- // instead, you should provide a pointer to a member variable of a struct or a pointer to a global variable.
162+ // A NumberFieldF control is uniquely determined by its call location.
163+ // Function calls made in different locations will create different controls.
164+ // If you want to generate different controls with the same function call in a loop (such as a for loop), use [IDScope].
166165func (c * Context ) NumberFieldF (value * float64 , step float64 , digits int ) bool {
166+ pc := caller ()
167+ id := c .idFromCaller (pc )
167168 var res bool
168169 c .wrapError (func () error {
169170 var err error
170- res , err = c .numberFieldF (value , step , digits , optionAlignCenter )
171+ res , err = c .numberFieldF (value , step , digits , id , optionAlignCenter )
171172 if err != nil {
172173 return err
173174 }
@@ -176,8 +177,7 @@ func (c *Context) NumberFieldF(value *float64, step float64, digits int) bool {
176177 return res
177178}
178179
179- func (c * Context ) numberField (value * int , step int , opt option ) (bool , error ) {
180- id := c .idFromPointer (unsafe .Pointer (value ))
180+ func (c * Context ) numberField (value * int , step int , id controlID , opt option ) (bool , error ) {
181181 last := * value
182182
183183 res , err := c .numberTextField (value , id )
@@ -210,8 +210,7 @@ func (c *Context) numberField(value *int, step int, opt option) (bool, error) {
210210 return res , nil
211211}
212212
213- func (c * Context ) numberFieldF (value * float64 , step float64 , digits int , opt option ) (bool , error ) {
214- id := c .idFromPointer (unsafe .Pointer (value ))
213+ func (c * Context ) numberFieldF (value * float64 , step float64 , digits int , id controlID , opt option ) (bool , error ) {
215214 last := * value
216215
217216 res , err := c .numberTextFieldF (value , id )
0 commit comments