View Bug Report
SimpleScrollList - Removing items from list causes bug.
Bug #: 42
File: LibSimpleWidgets
Date: 01-25-13 07:47 PM
By: Bullarky
Status: Fixed
I've encountered a bug in the SimpleScrollList and posted the code and directions to reproduce it.

Run the following code. When window pops up, select the last item in the list and hit the delete button. The item will disappear, but when you click on item one in the list you get an error.

Code:
local TestUI = UI.CreateContext("TestUI")
local TestFrame = UI.CreateFrame("SimpleWindow", "TestWindow", TestUI)
local TestList = UI.CreateFrame("SimpleScrollList", "TestList", TestFrame)
local AddButton = UI.CreateFrame("RiftButton", "AddButton", TestFrame)
local DelButton = UI.CreateFrame("RiftButton", "DelButton", TestFrame)

scrollitems = {'test1', 'test2', 'test3', 'test4', 'test5'}

TestFrame:SetVisible(false)
TestFrame:SetCloseButtonVisible(true)
TestFrame:SetTitle("Tester")
TestFrame:SetHeight(600)
TestFrame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 300, 100)
TestFrame:SetVisible(true)

TestList:SetBorder(1, 1, 1, 1, 1)
TestList:SetBackgroundColor(0, 0, 0, 1)
TestList:SetPoint("TOPLEFT", TestFrame:GetContent(), "TOPLEFT", 5, 60)
TestList:SetPoint("BOTTOMRIGHT", TestFrame:GetContent(), "BOTTOMRIGHT", -5, -35)
TestList:SetItems(scrollitems)

AddButton:SetText("Add Item")
AddButton:SetPoint("BOTTOMLEFT", TestFrame, "BOTTOMLEFT", 10, -10)
AddButton.Event.LeftClick = function() AddItem() end

DelButton:SetText("Del Item")
DelButton:SetPoint("BOTTOMRIGHT", TestFrame, "BOTTOMRIGHT", -10, -10)
DelButton.Event.LeftClick = function() RemoveItem() end

function AddItem()
	local randomNo = math.random(1000)
	local newitem = string.format("test%s", randomNo)
	table.insert(scrollitems, newitem)
	TestList:SetItems(scrollitems)
end

function RemoveItem()
	if not TestList:GetSelectedIndex() then return end
	table.remove(scrollitems, TestList:GetSelectedIndex())
	TestList:SetItems(scrollitems)
end
Thanks for taking a look at it when you get a chance.

 
Menu
» Home



Stats
Files: 2
Downloads: 10,737
Favorites: 13

New & Updated


Riftui