britzl / gooey

Defold GUI system
MIT License
150 stars 22 forks source link

.nodes failing on list items in dynamic_list #69

Closed geidnert closed 2 years ago

geidnert commented 2 years ago

Have a new interesting error, i use a gooey dynamic_list with x number of item rows in it, i want to find out on what element inside one list item i have clicked on, for example a delete button, so i use

if gui.pick_node(list.items[list.selected_item].nodes[hash(“giftitem/delete_btn”)], action.x, action.y)

inside the gooey dynamic_list function, and it works fine for item 1 to 9, but number 10 and above fails, and it looks like it is the .nodes that doesnt work when i debug printed out them like you se in the picture here

i made an example based on the gooey example project, and maybe the errors are coming as soon as i scroll the list and try to click on an scene object in one list item. So in the project i include it looks like it start failing on item nr 6

gooey-list_error.zip

britzl commented 2 years ago

The problem here is that it's a dynamic list, which means that it doesn't have one list item per element in the list. Instead it has just enough list item nodes to cover the visible area of the list and these items are reused.

The list.selected_item gives you an index into the list data, not an index into list.items.

The solution is to change list.selected_item to return the actual item structure (ie table containing index, root, nodes etc).

This is a breaking change and the version change will reflect this.

geidnert commented 2 years ago

Ok, is this something that you think would make sense to change or am i using it all wrong? will you make a new major version of the camera extension if you think so?

britzl commented 2 years ago

I've made the change already. Please try the new version.

With the new version list.selected_item is now the full item table with values root, nodes, index etc