jk3064 / chiliui

a lua-based opengl GUI
GNU General Public License v2.0
15 stars 9 forks source link

infinite loop when pressing backspace in an EditBox #45

Closed silentwings closed 8 years ago

silentwings commented 8 years ago

see https://springrts.com/mantis/view.php?id=5072 for details, maybe has already been fixed

gajop commented 8 years ago

Was about to write a response on mantis but beaten to it by you guys :) Anyway, this isn't an engine issue and neither is it a chili one. The problem is in your widget, you shouldn't set text in the editbox by modifying the .text property, but instead invoke the :SetText() method. Change line 793 in bgu_mainMenu.lua widget:

addScrollStack{name='widgetList',x='50%'},Chili.EditBox:New{name='widgetFilter',x=0,y=0,width = '35%',text=' Enter filter -> Hit Return,  or -->',OnMouseDown = {function(obj) obj:SetText('') end}},

PS: You may also want to update your chili eventually

gajop commented 8 years ago

In addition, the new chili/editbox supports the "hint" field which you could use, so instead of

text=' Enter filter -> Hit Return,  or -->'

use

hint=' Enter filter -> Hit Return,  or -->'
silentwings commented 8 years ago

I didn't write this code - but (1) The text field is not modified (ever, as far as I can see), in the line you quote it is only passed to the constructor in a table of arguments. (2) How is anyone supposed to tell which fields are safe to send as arguments to the constructor and which are only safe to set via wrapper functions? As far as I can see http://gajop.github.io/chiliui/modules/controls.editbox.html or the chili code itself makes no distinction,

gajop commented 8 years ago

All fields are safe to be set via constructors, but this isn't the issue here. The original code set the field in the OnMouseUp chili callback:

OnMouseDown = {function(obj) obj.text  = '' end}

Regarding wrapper methods, they should always be used if they exist (e.g. if there's a SetX method, then you should call that instead of setting the .x property directly).

silentwings commented 8 years ago

Oh, you are correct, I didn't scroll far enough right... thanks.

gajop commented 8 years ago

So, can you close this issue? :p

silentwings commented 8 years ago

No, because I don't have any priviledges for this repository.