A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(renderer): fit nine-slice borders inside small boxes
yhh0ce8abb89403
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 64f39beab..79e4fbdc1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,6 +20,8 @@ published separately; it ships inside the editor.### Fixed+- **Small nine-slice visuals keep borders inside their box.** Sprite and UI nine-slice geometry proportionally shrinks opposing borders when their total exceeds the destination size, retaining the texture's original border UVs. Zero-width or zero-height nine-slices emit no geometry; ordinary sizes retain their existing border widths.+- **Fully transparent UI visuals skip geometry uploads.** Default-material solid, image, nine-slice, tiled and filled visuals stop generating vertices and indices when their own or inherited alpha is zero, and resume when visible. Stencil mask geometry and custom-material draws remain available for clipping and shader-defined output.## [0.81.0] - 2026-10-14diff --git a/src/esengine/renderer/plugins/BatchPlugin.cpp b/src/esengine/renderer/plugins/BatchPlugin.cppindex 0ddc084c3..5f05180f5 100644--- a/src/esengine/renderer/plugins/BatchPlugin.cpp+++ b/src/esengine/renderer/plugins/BatchPlugin.cpp@@ -68,12 +68,18 @@ void BatchPlugin::emitNineSlice(f32 R = border.y;f32 T = border.z;f32 B = border.w;+ if (size.x == 0.0f || size.y == 0.0f) return;++ // Fit destination borders proportionally when the box is smaller than+ // their sum. Source UV borders still sample the original texture region.+ const f32 sx = size.x >= 0.0f && L + R > 0.0f ? std::min(1.0f, size.x / (L + R)) : 1.0f;+ const f32 sy = size.y >= 0.0f && T + B > 0.0f ? std::min(1.0f, size.y / (T + B)) : 1.0f;f32 baseX = position.x - size.x * pivotNorm.x;f32 baseY = position.y - size.y * pivotNorm.y;- f32 x[4] = { baseX, baseX + L, baseX + size.x - R, baseX + size.x };- f32 y[4] = { baseY, baseY + B, baseY + size.y - T, baseY + size.y };+ f32 x[4] = { baseX, baseX + L * sx, baseX + size.x - R * sx, baseX + size.x };+ f32 y[4] = { baseY, baseY + B * sy, baseY + size.y - T * sy, baseY + size.y };f32 u[4], v[4];if (texSize.x > 0.0f && texSize.y > 0.0f) {diff --git a/tests/renderer/test_batch_builder.cpp b/tests/renderer/test_batch_builder.cppindex 1d182afb3..0f455839f 100644--- a/tests/renderer/test_batch_builder.cpp+++ b/tests/renderer/test_batch_builder.cpp@@ -43,6 +43,10 @@ struct Harness {~Harness() { pool.shutdown(); }};+struct NineSlicePlugin : UIElementPlugin {+ using BatchPlugin::emitNineSlice;+};+BatchDrawKey quadKey(u32 textureId, i32 layer = 0) {BatchDrawKey key{};key.stage = RenderStage::Transparent;@@ -274,6 +278,48 @@ TEST_CASE("camera mask: hidden text and skeletal submissions upload no geometry"CHECK(frame.stats().triangles == 4);}+TEST_CASE("nine-slice: small boxes contain their borders and preserve source UVs") {+ for (const glm::vec2 size : {glm::vec2{40, 30}, {10, 6}, {10, 30}, {40, 6}, {0, 6}, {10, 0}}) {+ Harness h;+ NineSlicePlugin plugin;+ const glm::vec3 position{13, 17, 0};+ const glm::vec2 pivot{.25f, .75f};+ plugin.emitNineSlice(h.pool, h.list, h.clips, position, size, pivot,+ 0, {100, 100}, {8, 12, 10, 6}, {0, 0}, {1, 1}, {1, 1, 1, 1}, quadKey(1));+ const u32 bytes = h.pool.vertexBytesUsed(LayoutId::Batch);+ if (size.x == 0 || size.y == 0) {+ CHECK(bytes == 0);+ CHECK(h.pool.indicesUsed(LayoutId::Batch) == 0);+ CHECK(h.list.commandCount() == 0);+ continue;+ }+ const auto* vertices = reinterpret_cast<const BatchVertex*>(h.pool.vertexData(LayoutId::Batch));+ const u32 count = bytes / sizeof(BatchVertex);+ REQUIRE(count > 0);+ const glm::vec2 low = glm::vec2(position) - size * pivot;+ const glm::vec2 high = low + size;+ f32 area = 0;+ bool hasLeftUV = false, hasRightUV = false, hasBottomUV = false, hasTopUV = false;+ for (u32 i = 0; i < count; ++i) {+ CHECK(vertices[i].position.x >= low.x - .0001f);+ CHECK(vertices[i].position.x <= high.x + .0001f);+ CHECK(vertices[i].position.y >= low.y - .0001f);+ CHECK(vertices[i].position.y <= high.y + .0001f);+ hasLeftUV |= std::abs(vertices[i].texCoord.x - .08f) < .0001f;+ hasRightUV |= std::abs(vertices[i].texCoord.x - .88f) < .0001f;+ hasBottomUV |= std::abs(vertices[i].texCoord.y - .06f) < .0001f;+ hasTopUV |= std::abs(vertices[i].texCoord.y - .90f) < .0001f;+ if (i % 4 == 0) area += (vertices[i + 1].position.x - vertices[i].position.x)+ * (vertices[i + 3].position.y - vertices[i].position.y);+ }+ CHECK(area == doctest::Approx(size.x * size.y));+ CHECK(hasLeftUV);+ CHECK(hasRightUV);+ CHECK(hasBottomUV);+ CHECK(hasTopUV);+ }+}+TEST_CASE("UI visuals: zero alpha skips geometry and a restored fade draws again") {for (auto mode : {ecs::UIVisualType::SolidColor, ecs::UIVisualType::Image,ecs::UIVisualType::NineSlice, ecs::UIVisualType::Tiled,diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 5e8b57cea..d01ff6f9d 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'fix(renderer): fit nine-slice borders inside small boxes':+ { note: 'Small nine-slice visuals keep borders inside their box.' },'fix(docs): escape playable size limits in MDX':{ internal: 'escapes a less-than sign in both translations so the existing size-limit text compiles as MDX and the release website can deploy' },'feat(playable): report export checks and pending acceptance':