Fix background shorthand for -position and -clip

develop
Nimetu 3 years ago
parent 234465387b
commit b2ec03d1a1

@ -1075,7 +1075,6 @@ namespace NLGUI
// first loop -> true // first loop -> true
// second loop -> false && break // second loop -> false && break
loop = !loop; loop = !loop;
if (next < parts.size()) if (next < parts.size())
{ {
val = toLowerAscii(parts[next]); val = toLowerAscii(parts[next]);
@ -1086,30 +1085,57 @@ namespace NLGUI
// consume 'center' // consume 'center'
next++; next++;
} }
else if (val == "left" || val == "right") else if ((bgPositionX.empty() || bgPositionX == "center") && (val == "left" || val == "right"))
{ {
bgPositionX = val; bgPositionX = val;
// consume 'left|right' // consume 'left|right'
next++; next++;
if (next < parts.size() && getCssLength(fval, unit, parts[next])) if (next < parts.size() && getCssLength(fval, unit, parts[next]))
{ {
bgPositionX += " " + toString("%.0f%s", fval, unit.c_str()); bgPositionX += " " + parts[next];
// consume css length // consume css length
next++; next++;
} }
} }
else if (val == "top" || val == "bottom") else if ((bgPositionY.empty() || bgPositionY == "center") && (val == "top" || val == "bottom"))
{ {
bgPositionY = val; bgPositionY = val;
// consume top|bottom // consume top|bottom
next++; next++;
if (next < parts.size() && getCssLength(fval, unit, parts[next])) if (next < parts.size() && getCssLength(fval, unit, parts[next]))
{ {
bgPositionY += " " + toString("%.0f%s", fval, unit.c_str()); bgPositionY += " " + parts[next];
// consume css length // consume css length
next++; 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); } while (loop);
@ -1152,7 +1178,7 @@ namespace NLGUI
if (val == "auto") if (val == "auto")
h = v = "auto"; h = v = "auto";
else else
h = v = toString("%.0f%s", fval, unit.c_str()); h = v = val;
next++; next++;
if (next < parts.size()) if (next < parts.size())
@ -1161,7 +1187,7 @@ namespace NLGUI
if (val == "auto") if (val == "auto")
v = "auto"; v = "auto";
else if (getCssLength(fval, unit, val)) else if (getCssLength(fval, unit, val))
v = toString("%.0f%s", fval, unit.c_str()); v = val;
else else
next--; // not size token next--; // not size token
} }
@ -1244,7 +1270,10 @@ namespace NLGUI
// first time background-origin is set, also set background-clip // first time background-origin is set, also set background-clip
if (!bgClipFound) if (!bgClipFound)
{
bgClipValue = val; bgClipValue = val;
bgClipFound = true;
}
} }
} }
else if (props[i] == "background-clip") else if (props[i] == "background-clip")
@ -1294,6 +1323,7 @@ namespace NLGUI
{ {
if (props[i] == "background-position") if (props[i] == "background-position")
{ {
style["background-position"] = bgPositionX + " " + bgPositionY;
style["background-position-x"] = bgPositionX; style["background-position-x"] = bgPositionX;
style["background-position-y"] = bgPositionY; style["background-position-y"] = bgPositionY;
} }

Loading…
Cancel
Save