Browse Source

fix width calculation bug, remove debug, fix y UI calculation, fix height adjust when there's heightless inline components

master
Odilitime 5 years ago
parent
commit
f511dfd5f9
  1. 65
      src/graphics/components/Component.cpp

65
src/graphics/components/Component.cpp

@ -69,7 +69,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window * @@ -69,7 +69,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window *
if (properties.find("width") != properties.end()) {
boxSetup.width.requested = true;
if (properties["width"][properties["width"].size() - 1] == '%') {
std::cout << "Component::setUpUI - found width %" << std::endl;
//std::cout << "Component::setUpUI - found width %" << std::endl;
boxSetup.width.pct = std::stoi(properties["width"]);
} else {
boxSetup.width.px = std::stoi(properties["width"]);
@ -78,7 +78,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window * @@ -78,7 +78,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window *
if (properties.find("height") != properties.end()) {
boxSetup.height.requested = true;
if (properties["height"][properties["height"].size() - 1] == '%') {
std::cout << "Component::setUpUI - found height %" << std::endl;
//std::cout << "Component::setUpUI - found height %" << std::endl;
boxSetup.height.pct = std::stoi(properties["height"]);
} else {
boxSetup.height.px = std::stoi(properties["height"]);
@ -87,7 +87,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window * @@ -87,7 +87,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window *
if (properties.find("top") != properties.end()) {
boxSetup.top.requested = true;
if (properties["top"][properties["top"].size() - 1] == '%') {
std::cout << "Component::setUpUI - found top %" << std::endl;
//std::cout << "Component::setUpUI - found top %" << std::endl;
boxSetup.top.pct = std::stoi(properties["top"]);
} else {
boxSetup.top.px = std::stoi(properties["top"]);
@ -96,7 +96,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window * @@ -96,7 +96,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window *
if (properties.find("bottom") != properties.end()) {
boxSetup.bottom.requested = true;
if (properties["bottom"][properties["bottom"].size() - 1] == '%') {
std::cout << "Component::setUpUI - found bottom %" << std::endl;
//std::cout << "Component::setUpUI - found bottom %" << std::endl;
boxSetup.bottom.pct = std::stoi(properties["bottom"]);
} else {
boxSetup.bottom.px = std::stoi(properties["bottom"]);
@ -105,7 +105,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window * @@ -105,7 +105,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window *
if (properties.find("left") != properties.end()) {
boxSetup.left.requested = true;
if (properties["left"][properties["left"].size() - 1] == '%') {
std::cout << "Component::setUpUI - found left %" << std::endl;
//std::cout << "Component::setUpUI - found left %" << std::endl;
boxSetup.left.pct = std::stoi(properties["left"]);
} else {
boxSetup.left.px = std::stoi(properties["left"]);
@ -114,7 +114,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window * @@ -114,7 +114,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window *
if (properties.find("right") != properties.end()) {
boxSetup.right.requested = true;
if (properties["right"][properties["right"].size() - 1] == '%') {
std::cout << "Component::setUpUI - found right %" << std::endl;
//std::cout << "Component::setUpUI - found right %" << std::endl;
boxSetup.right.pct = std::stoi(properties["right"]);
} else {
boxSetup.right.px = std::stoi(properties["right"]);
@ -123,11 +123,13 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window * @@ -123,11 +123,13 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window *
std::unique_ptr<std::pair<UImetricV2, UImetricV2>> xUI = getUIMetric(boxSetup.left, boxSetup.right, boxSetup.width);
std::unique_ptr<std::pair<UImetricV2, UImetricV2>> yUI = getUIMetric(boxSetup.top, boxSetup.bottom, boxSetup.height);
int cX = 0, cY = 0, cW = boxSetup.width.px, cH = boxSetup.height.px;
int xPx = 0, yPx = 0;
double xPct = 0, yPct = 0;
double wPct = 100, hPct = 100;
int wPx = 0, hPx = 0;
int winWidth = pwin->windowWidth;
int winHeight = pwin->windowHeight;
//std::cout << "Component::setUpUI - laying out a " << typeOfComponent(this) << std::endl;
if (xUI) {
//std::cout << "box XUI at " << xUI->first.pct << "% +" << xUI->first.px << std::endl;
//std::cout << "box XUI for " << xUI->second.pct << "% +" << xUI->second.px << std::endl;
@ -138,6 +140,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window * @@ -138,6 +140,7 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window *
// well we still need winHeight tho, because of the coords
cX = (xUI->first.pct * 0.01 * winWidth) + xUI->first.px;
xPct = xUI->first.pct;
xPx = xUI->first.px;
cW = (xUI->second.pct * 0.01 * winWidth) + xUI->second.px;
wPct = xUI->second.pct;
wPx = xUI->second.px;
@ -145,18 +148,23 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window * @@ -145,18 +148,23 @@ void Component::setUpUI(std::map<std::string, std::string> &properties, Window *
//std::cout << "Component::setUpUI W at " << wPct << "% for " << wPx << std::endl;
}
if (yUI) {
cY = (yUI->first.pct * 0.01 * winHeight) + yUI->first.px;
yPct = yUI->first.pct;
//std::cout << "Component::setUpUI pct" << yUI->first.pct << "/100 - " << yUI->first.px << std::endl;
cY = (yUI->first.pct * 0.01 * winHeight) - yUI->first.px;
// bottom=0 is 0, 0, so we do 100- here
yPct = 100 - yUI->first.pct;
yPx = yUI->first.px;
cH = (yUI->second.pct * 0.01 * winHeight) + yUI->second.px;
hPct = yUI->second.pct;
hPx = yUI->second.px;
//std::cout << "Component::setUpUI Y at " << cY << " for " << cH << std::endl;
//std::cout << "Component::setUpUI Y would be " << (-cH - cY) << " and new is " << yPx << std::endl;
//std::cout << "Component::setUpUI H at " << hPct << "% for " << hPx << std::endl;
}
// set up proper component information for resizing
this->uiControl.x = { 0, cX }; //
this->uiControl.y = { 100, -cH - cY }; //
this->uiControl.x = { xPct, xPx }; //
this->uiControl.y = { yPct, -cH - yPx }; //
this->uiControl.w = { wPct, wPx }; //
this->uiControl.h = { hPct, hPx }; //
@ -298,7 +306,33 @@ void Component::layout() { @@ -298,7 +306,33 @@ void Component::layout() {
}
} else {
// we're block
y = previous->y - previous->height;
y = previous->y - previous->height; // advance down one height
if (!previous->height) {
// ok if last is a nothing burger (0x0 size)
// then we need the parent height
// or we could spool to get the height for the last inline that's been set
// this isn't right
//y -= this->parent->height;
// this is bad because we assume there's only going to be one
std::shared_ptr<Component> pos = this->previous;
bool found = false;
while(pos->previous) {
pos = pos->previous;
if (!pos->isInline) {
std::cout << "found block element at " << pos->y << std::endl;
break;
}
if (pos->height) {
std::cout << "no size, grabbing height " << (int)pos->height << std::endl;
y -= pos->height;
found = true;
break;
}
}
if (!found) {
std::cout << "couldnt adjust height properly" << std::endl;
}
}
//std::cout << "Component::layout - inLine block" << std::endl;
}
} else {
@ -404,6 +438,7 @@ void Component::updateParentSize() { @@ -404,6 +438,7 @@ void Component::updateParentSize() {
// find max width of all siblings
unsigned int maxWidth = width; // float?
unsigned int heightAccum = 0;
unsigned int widthAccum = 0;
unsigned int totalHeight = 0;
// integrity check
@ -415,10 +450,12 @@ void Component::updateParentSize() { @@ -415,10 +450,12 @@ void Component::updateParentSize() {
// look at siblings
bool wasInline = false;
//std::cout << "Component::updateParentSize - assessing " << parent->children.size() << " children" << std::endl;
for (std::shared_ptr<Component> child : parent->children) {
maxWidth = std::max(maxWidth, static_cast<unsigned int>(child->width));
if (child->isInline) {
heightAccum = std::max(heightAccum, static_cast<unsigned int>(child->height));
widthAccum += child->width;
/*
if (wasInline) {
// in in
@ -434,15 +471,19 @@ void Component::updateParentSize() { @@ -434,15 +471,19 @@ void Component::updateParentSize() {
// flush height of previous line + our height
totalHeight += heightAccum + child->height;
heightAccum = 0; // reset
maxWidth = std::max(maxWidth, static_cast<unsigned int>(widthAccum));
widthAccum = 0;
} else {
// bl bl
totalHeight += child->height;
// than a max of all widths of the two is fine
}
}
wasInline = child->isInline;
}
// flush any remaining heightAccum
// flush any remaining width/heightAccum
totalHeight += heightAccum;
maxWidth = std::max(maxWidth, static_cast<unsigned int>(widthAccum));
//std::cout << "new size " << maxWidth << "x" << totalHeight << std::endl;
// did our size actually change

Loading…
Cancel
Save