keharriso / love-nuklear

Lightweight immediate mode GUI for LÖVE games
MIT License
350 stars 32 forks source link

Direct number passed to property doesn't update #46

Closed MangelMaxime closed 4 years ago

MangelMaxime commented 4 years ago

Hello,

when passing directly a number to ui:property the value can't get updated from the UI component.

However, if I pass it by wrapping it in a table (like in edit2) then it works.

local edit1 = 2
local edit2 = { value = 2 }

function Player:updateUI(ui) 
  if ui:windowBegin('Player infos', 100, 100, 200, 160,
            'border', 'title', 'movable', 'minimizable') then
        ui:layoutRow('dynamic', 30, 2)
        ui:label('Edit #1')
    ui:property("", 0, edit1, 3, 1, 1)
        ui:layoutRow('dynamic', 30, 2)
        ui:label('Edit #2')
    ui:property("", 0, edit2, 3, 1, 1)
    end
    ui:windowEnd()
end

love-nuklear-property-bug

Am I doing something wrong?

keharriso commented 4 years ago

Line 8: You pass edit1 to ui:property, but don't retrieve its return value (the updated property value). Change this:

ui:property("", 0, edit1, 3, 1, 1)

To this:

edit1 = ui:property("", 0, edit1, 3, 1, 1)
MangelMaxime commented 4 years ago

Oh ok, is this behaviour always the same?

I mean if I pass a table it will get updated directly, otherwise I have to store the result ?

Thank you for the quick answer :)

keharriso commented 4 years ago

Yes, this behavior is common among all widgets that take values. If you pass a table to ui:slider for example, the table's value field will be updated. If you pass a number, ui:slider will return the new number. Hope that helps.