mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-24 22:09:10 -06:00
Change how moveLayer works slightly, so it is easier to use in a GUI implementation
* "newPosition" is now considered to be the item's new position (index) in the list * also update the documentation a little
This commit is contained in:
@@ -376,12 +376,14 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const {
|
||||
"moveLayer",
|
||||
&globebrowsing::luascriptfunctions::moveLayer,
|
||||
"string, string, number, number",
|
||||
"Rearranges the order of a single layer in a scene graph node. The first "
|
||||
"parameter specifies the scene graph node, the second parameter specifies "
|
||||
"Rearranges the order of a single layer on a globe. The first parameter"
|
||||
"is the identifier of the globe, the second parameter specifies "
|
||||
"the name of the layer group, the third parameter is the original position "
|
||||
"of the layer that should be moved and the last parameter is the new "
|
||||
"position. The new position may be -1 to place the layer at the top or any "
|
||||
"large number bigger than the number of layers to place it at the bottom."
|
||||
"position in the list. The first position in the list has index 0, and the "
|
||||
"last position is given by the number of layers minus one. The new position "
|
||||
"may be -1 to place the layer at the top or any number bigger than the "
|
||||
"number of layers to place it at the bottom."
|
||||
},
|
||||
{
|
||||
"goToChunk",
|
||||
|
||||
@@ -169,7 +169,7 @@ int moveLayer(lua_State* L) {
|
||||
}
|
||||
|
||||
globebrowsing::LayerGroup& lg = globe->layerManager().layerGroup(group);
|
||||
lg.moveLayers(oldPosition, newPosition);
|
||||
lg.moveLayer(oldPosition, newPosition);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -212,16 +212,9 @@ void LayerGroup::deleteLayer(const std::string& layerName) {
|
||||
LERROR("Could not find layer " + layerName);
|
||||
}
|
||||
|
||||
void LayerGroup::moveLayers(int oldPosition, int newPosition) {
|
||||
void LayerGroup::moveLayer(int oldPosition, int newPosition) {
|
||||
oldPosition = std::max(0, oldPosition);
|
||||
newPosition = std::min(newPosition, static_cast<int>(_layers.size()));
|
||||
|
||||
// We need to adjust the new position as we first delete the old position, if this
|
||||
// position is before the new position we have reduced the size of the vector by 1 and
|
||||
// need to adapt where we want to put the value in
|
||||
if (oldPosition < newPosition) {
|
||||
newPosition -= 1;
|
||||
}
|
||||
newPosition = std::min(newPosition, static_cast<int>(_layers.size() - 1));
|
||||
|
||||
// There are two synchronous vectors that we have to update here. The _layers vector
|
||||
// is used to determine the order while rendering, the _subowners is the order in
|
||||
|
||||
@@ -52,7 +52,7 @@ struct LayerGroup : public properties::PropertyOwner {
|
||||
|
||||
Layer* addLayer(const ghoul::Dictionary& layerDict);
|
||||
void deleteLayer(const std::string& layerName);
|
||||
void moveLayers(int oldPosition, int newPosition);
|
||||
void moveLayer(int oldPosition, int newPosition);
|
||||
|
||||
/// @returns const vector of all layers
|
||||
std::vector<Layer*> layers() const;
|
||||
|
||||
Reference in New Issue
Block a user