fix(node): only round a box that has a border
A filled box without one is a plain rectangle: rounding it leaves the surface showing at the corners, which reads as a seam nobody asked for.
This commit is contained in:
@@ -78,13 +78,16 @@ class Painter {
|
||||
const bool hasFill = own && (own->set & S_FILL);
|
||||
if (!hasFill && !hasBorder) return;
|
||||
|
||||
const int32_t radius = tree.inherited(id, S_RADIUS).radius;
|
||||
if (hasFill && radius == 0 && !hasBorder) {
|
||||
// Only a bordered box rounds its corners. Filling a square first would leave corners
|
||||
// outside the border, and rounding an unbordered fill puts a seam where a plain panel
|
||||
// background was expected.
|
||||
if (!hasBorder) {
|
||||
gui.fillRect(n.x, n.y, n.w, n.h, own->fill);
|
||||
return;
|
||||
}
|
||||
const int32_t fill = hasFill ? own->fill : tree.inherited(id, S_BG).bg;
|
||||
gui.roundRect(n.x, n.y, n.w, n.h, radius, surfaceOf(id), &fill, &fill, hasBorder ? &own->border : nullptr);
|
||||
gui.roundRect(n.x, n.y, n.w, n.h, tree.inherited(id, S_RADIUS).radius, surfaceOf(id), &fill, &fill,
|
||||
&own->border);
|
||||
}
|
||||
|
||||
void paintButton(uint16_t id) {
|
||||
|
||||
@@ -145,7 +145,8 @@ int main() {
|
||||
"local root = node.create(nil, {type = 'box', w = 'fill', h = 'fill', pad = 4, gap = 2})\n"
|
||||
"local label = node.create(root, {type = 'text', label = 'Hello'})\n"
|
||||
"local button = node.create(root, {type = 'button', h = 40, interactive = true})\n"
|
||||
"node.setStyle(root, {background = 0xFFFFFF, fill = 0xFFFFFF, color = 0, face = 0xEEEEEE, focusColor = 0xFF0000})\n"
|
||||
"node.setStyle(root, {background = 0xFFFFFF, fill = 0xFFFFFF, color = 0, face = 0xEEEEEE,\n"
|
||||
" border = 0x333333, focusColor = 0xFF0000})\n"
|
||||
"assert(node.layout(root, 0, 0, 320, 240))\n"
|
||||
"local x, y, w, h = node.getRect(label)\n"
|
||||
"assert(x == 4 and y == 4 and w == 312 and h == 16)\n"
|
||||
@@ -161,6 +162,8 @@ int main() {
|
||||
"node.draw(root)\n"
|
||||
"node.dropScratch()");
|
||||
assert(bench.gui.trace.find("drawText(Hello);") != std::string::npos);
|
||||
// The bordered box rounds its corners; the button fills without one.
|
||||
assert(bench.gui.trace.find("roundRect(fill,border);") != std::string::npos);
|
||||
assert(bench.gui.trace.find("roundRect(fill,-);") != std::string::npos);
|
||||
expectError(state, "node.create(nil, {type = 'nope'})");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user