flamendless / Slab

An immediate mode GUI for the Love2D framework.
MIT License
286 stars 25 forks source link

[v1.0.0] - Listbox error #135

Closed chicogamedev closed 2 years ago

chicogamedev commented 2 years ago

I have this piece of code :

for k, v in ipairs(self.projectsList) do
    Slab.BeginListBoxItem("projectItem" .. k, { Selected = self.selectedProjectIndex == k } )
       Slab.Text(v.name)

        if (Slab.IsListBoxItemClicked()) then
            self.selectedProjectIndex = k
        end

            if (Slab.IsListBoxItemClicked(1, true)) then
             self:loadProject(k)
        end
    Slab.EndListBoxItem()
end

I got this error (not with current released version of Slab) :

Error: libs/slab/Internal/UI/ListBox.lua:151: Begin was called for item 'nil' without a call to EndListBoxItem stack traceback:

[C]: in function 'error'
libs/slab/Internal/UI/ListBox.lua:151: in function 'BeginItem'
libs/slab/API.lua:1633: in function 'BeginListBoxItem'

It seems that active.ActiveItem is nil for whatever reason.

flamendless commented 2 years ago

You should be using BeginListBox and EndListBox before calling BeginListBoxItem. See https://github.com/flamendless/Slab/wiki/ListBox#BeginListBox

chicogamedev commented 2 years ago

Yeah sorry since the error was not here with the older version of Slab, these calls are around the given code. Sorry for not showing them.

            Slab.BeginListBox("projectsList", { Clear = self.projectsListUpdate, StretchW = false, StretchH = true, W = 440, AlignX = "Center" })
                self.projectsListUpdate = false
                for k, v in ipairs(self.projectsList) do
                    Slab.BeginListBoxItem("projectItem" .. k, { Selected = self.selectedProjectIndex == k } )
                        Slab.Text(v.name)

                        if (Slab.IsListBoxItemClicked()) then
                            self.selectedProjectIndex = k
                        end

                        if (Slab.IsListBoxItemClicked(1, true)) then
                            self:loadProject(k)
                        end
                    Slab.EndListBoxItem()
                end
            Slab.EndListBox()
flamendless commented 2 years ago

Indeed, there is an error in latest commit. Will fix soon

chicogamedev commented 2 years ago

Thanks !

flamendless commented 2 years ago

Fixed now :)