airstruck / luigi

Lovely User Interfaces for Game Inventors
MIT License
113 stars 23 forks source link

Link slider to panel scroll #48

Closed linux-man closed 7 years ago

linux-man commented 7 years ago

I want to create at run time a panel with a variable list of buttons (or labels). I'm aware that I can scroll using the mouse wheel, but I want to do it using a slider. scrollBy function works, but I can't figure how to synchronize scrolling and slider position.

airstruck commented 7 years ago

I haven't looked at it in a while, but all widgets should fire an "onChange" event when their "value" changes; you should be able to listen for that event and call scrollBy or set the scrollY or scrollX properties. Let me know if that helps, if not I'll write up an example.

linux-man commented 7 years ago

Thank you. I wasn't doing :reshape after changing scrollY. It works using the (pseudo) code:

maxScroll = number_of_buttons * buttons_height - panel_height
slider:onChange(function (event)
    panel.scrollY = (1 - event.value) * maxScroll
    panel:reshape()
end)
panel:onWheelMove(function (event)
    slider.value = 1 - panel.scrollY / maxScroll
end)
airstruck commented 7 years ago

Glad you got it working, thanks for posting the example code!