From b2ec03d1a124486530a13b4596e4a07d5f1471b3 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Sat, 3 Jul 2021 23:56:43 +0300 Subject: [PATCH] Fix background shorthand for -position and -clip --- nel/src/gui/css_style.cpp | 44 ++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/nel/src/gui/css_style.cpp b/nel/src/gui/css_style.cpp index c2b4a6ff1..fa80e7b52 100644 --- a/nel/src/gui/css_style.cpp +++ b/nel/src/gui/css_style.cpp @@ -1075,7 +1075,6 @@ namespace NLGUI // first loop -> true // second loop -> false && break loop = !loop; - if (next < parts.size()) { val = toLowerAscii(parts[next]); @@ -1086,30 +1085,57 @@ namespace NLGUI // consume 'center' next++; } - else if (val == "left" || val == "right") + else if ((bgPositionX.empty() || bgPositionX == "center") && (val == "left" || val == "right")) { bgPositionX = val; // consume 'left|right' next++; if (next < parts.size() && getCssLength(fval, unit, parts[next])) { - bgPositionX += " " + toString("%.0f%s", fval, unit.c_str()); + bgPositionX += " " + parts[next]; // consume css length next++; } } - else if (val == "top" || val == "bottom") + else if ((bgPositionY.empty() || bgPositionY == "center") && (val == "top" || val == "bottom")) { bgPositionY = val; // consume top|bottom next++; if (next < parts.size() && getCssLength(fval, unit, parts[next])) { - bgPositionY += " " + toString("%.0f%s", fval, unit.c_str()); + bgPositionY += " " + parts[next]; // consume css length next++; } } + else if (getCssLength(fval, unit, parts[next])) + { + // override X only on first loop + if (next == index) + { + bgPositionX = parts[next]; + } + else if (bgPositionY.empty()) + { + bgPositionY = parts[next]; + } + else + { + // invalid + bgPositionX.clear(); + bgPositionY.clear(); + break; + } + next++; + } + else + { + // invalid value + bgPositionX.clear(); + bgPositionY.clear(); + break; + } } } while (loop); @@ -1152,7 +1178,7 @@ namespace NLGUI if (val == "auto") h = v = "auto"; else - h = v = toString("%.0f%s", fval, unit.c_str()); + h = v = val; next++; if (next < parts.size()) @@ -1161,7 +1187,7 @@ namespace NLGUI if (val == "auto") v = "auto"; else if (getCssLength(fval, unit, val)) - v = toString("%.0f%s", fval, unit.c_str()); + v = val; else next--; // not size token } @@ -1244,7 +1270,10 @@ namespace NLGUI // first time background-origin is set, also set background-clip if (!bgClipFound) + { bgClipValue = val; + bgClipFound = true; + } } } else if (props[i] == "background-clip") @@ -1294,6 +1323,7 @@ namespace NLGUI { if (props[i] == "background-position") { + style["background-position"] = bgPositionX + " " + bgPositionY; style["background-position-x"] = bgPositionX; style["background-position-y"] = bgPositionY; }