From 927a12e51e510485aa60a2fb4a4af2f544a137ab Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Thu, 17 Aug 2023 14:55:53 +0200 Subject: [PATCH] add getNextFreeLayerID() --- src/LayerComposition.cpp | 15 +++++++++++++-- src/LayerComposition.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) 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;