From a5af6b5af47b99e70a9d990f4783ca56175b71c5 Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Mon, 3 Aug 2026 18:28:26 -0400 Subject: [PATCH] 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. --- native/src/node/painter.h | 9 ++++++--- native/test/runtime_test.cpp | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/native/src/node/painter.h b/native/src/node/painter.h index f519ef3..f76e757 100644 --- a/native/src/node/painter.h +++ b/native/src/node/painter.h @@ -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) { diff --git a/native/test/runtime_test.cpp b/native/test/runtime_test.cpp index 3246a34..9a70b7e 100644 --- a/native/test/runtime_test.cpp +++ b/native/test/runtime_test.cpp @@ -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'})");