Hi
I'm trying to create the classic "Up" & "Down" buttons to reorganize this TextList widget:
Once clicking the "Up" button, the selected/focused list item, if it's not already the first one, it should raise 1 position in the list
I've tryed with this functions but none worked:
How I can achieve this one? Do I really need to destroy and create the widget manually? and how to create it on X position/index of the list?
PS: I'm doing this shit right now which is working, but there must be a better way to do it:
Thanks <3
I'm trying to create the classic "Up" & "Down" buttons to reorganize this TextList widget:
Once clicking the "Up" button, the selected/focused list item, if it's not already the first one, it should raise 1 position in the list
I've tryed with this functions but none worked:
C++:
void raiseChild(UIWidgetPtr child);
void moveChildToIndex(const UIWidgetPtr& child, int index);
void reorderChildren(const std::vector<UIWidgetPtr>& childrens);
How I can achieve this one? Do I really need to destroy and create the widget manually? and how to create it on X position/index of the list?
PS: I'm doing this shit right now which is working, but there must be a better way to do it:
Lua:
-- this table will hold a copy of the widgets
-- we will use this table as a reference and replicate it's data to the UI
waypointWidgetList = {}
-- finds a widget by it's "custom index"
-- required to assign index manually to the children object
-- example: mychildren.index = 1
function findChildByIndex(control, index)
for i, v in pairs(control:getChildren()) do
if v.index == index then
return v
end
end
return nil
end
-- escalate 1 position up a waypoint in the TextList
function moveWaypointUp()
local focusedChild = waypointList:getFocusedChild()
if focusedChild then
local index = focusedChild.index
print("index: " .. index)
if index > 1 then
local newpos = index - 1
local aux = waypointWidgetList[newpos]
waypointWidgetList[newpos] = waypointWidgetList[index]
waypointWidgetList[index] = aux
redrawWaypointList()
childToFocus = findChildByIndex(waypointList, newpos)
if childToFocus then
waypointList:focusChild(childToFocus)
end
end
end
end
-- redraw the entire TextList from memory
function redrawWaypointList()
waypointList:destroyChildren()
for i, waypoint in ipairs(waypointWidgetList) do
local waypointLabel = g_ui.createWidget('WaypointLabel', waypointList)
waypointLabel:setId(i)
waypointLabel.index = i
waypointLabel.description = waypoint.description
waypointLabel:setText(waypoint.description)
waypointLabel:setVisible(true)
end
end
Thanks <3
Last edited: