Parse name and bounding box attributes in parseAttribute instead of directly in parse
This commit is contained in:
@@ -443,18 +443,10 @@ void cControl::parse(ticpp::Element& who, std::string fname) {
|
|||||||
Iterator<Node> node;
|
Iterator<Node> node;
|
||||||
std::set<std::string> foundAttrs;
|
std::set<std::string> foundAttrs;
|
||||||
std::multiset<std::string> foundNodes;
|
std::multiset<std::string> foundNodes;
|
||||||
int width = 0, height = 0;
|
|
||||||
rectangle frame;
|
|
||||||
for(attr = attr.begin(&who); attr != attr.end(); attr++){
|
for(attr = attr.begin(&who); attr != attr.end(); attr++){
|
||||||
std::string attrName = attr->Name();
|
foundAttrs.insert(attr->Name());
|
||||||
foundAttrs.insert(attrName);
|
if(!parseAttribute(*attr, tagName, fname))
|
||||||
if(attrName == "name") attr->GetValue(&name);
|
throw xBadAttr(tagName, attr->Name(), attr->Row(), attr->Column(), fname);
|
||||||
else if(attrName == "top") attr->GetValue(&frame.top);
|
|
||||||
else if(attrName == "left") attr->GetValue(&frame.left);
|
|
||||||
else if(attrName == "width") attr->GetValue(&width);
|
|
||||||
else if(attrName == "height") attr->GetValue(&height);
|
|
||||||
else if(!parseAttribute(*attr, tagName, fname))
|
|
||||||
throw xBadAttr(tagName, attrName, attr->Row(), attr->Column(), fname);
|
|
||||||
}
|
}
|
||||||
if(auto namer = dynamic_cast<iNameGiver*>(&getParent())) {
|
if(auto namer = dynamic_cast<iNameGiver*>(&getParent())) {
|
||||||
name = namer->generateId(name);
|
name = namer->generateId(name);
|
||||||
@@ -476,7 +468,6 @@ void cControl::parse(ticpp::Element& who, std::string fname) {
|
|||||||
location bestSz = getPreferredSize();
|
location bestSz = getPreferredSize();
|
||||||
frame.width() = width > 0 ? width : bestSz.x;
|
frame.width() = width > 0 ? width : bestSz.x;
|
||||||
frame.height() = height > 0 ? height : bestSz.y;
|
frame.height() = height > 0 ? height : bestSz.y;
|
||||||
setBounds(frame);
|
|
||||||
validatePostParse(who, fname, foundAttrs, foundNodes);
|
validatePostParse(who, fname, foundAttrs, foundNodes);
|
||||||
|
|
||||||
// Wire links to function:
|
// Wire links to function:
|
||||||
@@ -492,6 +483,28 @@ void cControl::parse(ticpp::Element& who, std::string fname) {
|
|||||||
bool cControl::parseAttribute(ticpp::Attribute& attr, std::string tagName, std::string fname) {
|
bool cControl::parseAttribute(ticpp::Attribute& attr, std::string tagName, std::string fname) {
|
||||||
std::string name;
|
std::string name;
|
||||||
attr.GetName(&name);
|
attr.GetName(&name);
|
||||||
|
// Unique identifier
|
||||||
|
if(name == "name") {
|
||||||
|
attr.GetValue(&this->name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Position and size
|
||||||
|
if(name == "top") {
|
||||||
|
attr.GetValue(&frame.top);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(name == "left") {
|
||||||
|
attr.GetValue(&frame.left);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(name == "width") {
|
||||||
|
attr.GetValue(&width);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(name == "height") {
|
||||||
|
attr.GetValue(&height);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// Relative positioning
|
// Relative positioning
|
||||||
if(name == "relative") {
|
if(name == "relative") {
|
||||||
static auto space = " \t";
|
static auto space = " \t";
|
||||||
|
|||||||
@@ -480,6 +480,7 @@ private:
|
|||||||
iComponent* parent;
|
iComponent* parent;
|
||||||
// Transient values only used during parsing
|
// Transient values only used during parsing
|
||||||
ePosition horz = POS_ABS, vert = POS_ABS;
|
ePosition horz = POS_ABS, vert = POS_ABS;
|
||||||
|
int width = 0, height = 0;
|
||||||
std::string anchor;
|
std::string anchor;
|
||||||
bool is_link = false;
|
bool is_link = false;
|
||||||
static std::mt19937 ui_rand;
|
static std::mt19937 ui_rand;
|
||||||
|
|||||||
Reference in New Issue
Block a user