Functions for lists and dropdowns.
This was SVN commit r2508.
This commit is contained in:
parent
7eaf8bc13c
commit
f818449e72
53
binaries/data/mods/official/gui/test/functions_list.js
Normal file
53
binaries/data/mods/official/gui/test/functions_list.js
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
***************************************
|
||||
functions_list.js
|
||||
|
||||
Functions to manipulate objects with
|
||||
a 'list' property. It is important to
|
||||
do this and not manually to ensure that
|
||||
the selection is updated properly.
|
||||
|
||||
***************************************
|
||||
*/
|
||||
|
||||
function removeItem(objectName, pos)
|
||||
{
|
||||
var list = getGUIObjectByName(objectName).list;
|
||||
var selected = getGUIObjectByName(objectName).selected;
|
||||
list.splice(pos, 1);
|
||||
|
||||
getGUIObjectByName(objectName).list = list;
|
||||
|
||||
// It is important that we're setting the new selection *after*
|
||||
// the list is already updated.
|
||||
|
||||
// Update the selected so the same element remains selected
|
||||
if (selected == pos)
|
||||
{
|
||||
getGUIObjectByName(objectName).selected = -1;
|
||||
}
|
||||
else
|
||||
if (selected > pos)
|
||||
{
|
||||
getGUIObjectByName(objectName).selected = selected - 1;
|
||||
}
|
||||
}
|
||||
|
||||
function addItem(objectName, pos, value)
|
||||
{
|
||||
var list = getGUIObjectByName(objectName).list;
|
||||
var selected = getGUIObjectByName(objectName).selected;
|
||||
list.splice(pos, 0, value);
|
||||
|
||||
getGUIObjectByName(objectName).list = list;
|
||||
|
||||
// It is important that we're setting the new selection *after*
|
||||
// the list is already updated.
|
||||
|
||||
// Update the selected so the same element remains selected
|
||||
if (selected >= pos)
|
||||
{
|
||||
getGUIObjectByName(objectName).selected = selected + 1;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user