View Single Post
Old 10-22-2019, 11:31 AM   #543
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,420
Default

Quote:
Originally Posted by babag View Post
edit:
found the y position. it's in the 'for' loop at 'button_width, 0'. changing the 0 changes the y position. got a crash when i tried to run two 'for' loops, though, to get a second row.
- What message does the crash give you? Knowing the error it found and the line number can often tell you exactly what the problem was.

- I recommend using the alternate syntax for creating elements, as seen here. v3 of the GUI will only use that format because it's way easier to deal with.

(Don't forget to pass your elements to GUI.CreateElms if you do use that approach)

- Rather than two loops, you could put all of the buttons in a single list and then use some math to manage your rows:
Code:
local button_width = 32
local button_height = 24
local buttons_per_row = 8

for k, v in ipairs(toolbar_buttons) do
  GUI.New(
    "btn_"..k, 
    "Button", 
    1, 
    (k - 1) * button_width, -- x
    math.floor(k / buttons_per_row0) *  button_height, -- y
    button_width, -- w
    button_height, -- h
    v.label, 
    function() reaper.Main_OnCommand(v.command, 0) end
  )
end
Lokasenna is online now   Reply With Quote