diff --git a/src/LayerComposition.cpp b/src/LayerComposition.cpp index 349934b..f32e5c2 100644 --- a/src/LayerComposition.cpp +++ b/src/LayerComposition.cpp @@ -122,7 +122,7 @@ LayerID LayerComposition::addLayer(const ComboIdentifier & identifier, layer->setProps(props); layer->setup(); if(layerID == ""){ - layerID = layer->getId(); + layerID = getNextFreeLayerID(); }else{ layer->setId(layerID); } @@ -144,7 +144,7 @@ LayerID LayerComposition::addLayer(const ComboIdentifier & identifier, layer->setProps(props); layer->setup(); if(layerID == ""){ - layerID = layer->getId(); + layerID = getNextFreeLayerID(); }else{ layer->setId(layerID); } @@ -254,5 +254,16 @@ void LayerComposition::setMsdfUniform1fv(const vector & names, } } } +const LayerID LayerComposition::getNextFreeLayerID() const { + for(int i = 0; i < layers.size(); i++){ + LayerID possible_id = "layer-" + std::to_string(i); + if(std::find(layerOrder.begin(), + layerOrder.end(), + possible_id) == layerOrder.end()){ + return possible_id; + } + } + return "layer-" + std::to_string(layers.size()); +} } diff --git a/src/LayerComposition.h b/src/LayerComposition.h index ac76ec9..119d7ad 100644 --- a/src/LayerComposition.h +++ b/src/LayerComposition.h @@ -38,6 +38,7 @@ class LayerComposition { void setLayerOrder(const vector & layerOrder); void setMsdfUniform1fv(const vector & names, const vector & values); + const LayerID getNextFreeLayerID() const; private: VFlipState vFlipState = V_FLIP_UNKNOWN; unordered_map > layers;