add getNextFreeLayerID()

This commit is contained in:
jrkb 2023-08-17 14:55:53 +02:00
parent c1d6d052be
commit 927a12e51e
2 changed files with 14 additions and 2 deletions

View file

@ -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 <string> & 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());
}
}

View file

@ -38,6 +38,7 @@ class LayerComposition {
void setLayerOrder(const vector <LayerID> & layerOrder);
void setMsdfUniform1fv(const vector <string> & names,
const vector <float> & values);
const LayerID getNextFreeLayerID() const;
private:
VFlipState vFlipState = V_FLIP_UNKNOWN;
unordered_map <LayerID, shared_ptr <Layer> > layers;