Skip to content

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.

fix(ui): nine-slice borders reach the native core, and a short box keeps its corners round

yhh1e74970eb100
diff --git a/sdk/src/ecs/bridge/nativeBindings.ts b/sdk/src/ecs/bridge/nativeBindings.ts
index d204f5f7b..adabcfe4b 100644
--- a/sdk/src/ecs/bridge/nativeBindings.ts
+++ b/sdk/src/ecs/bridge/nativeBindings.ts
@@ -90,6 +90,7 @@ export const RESOURCE_BINDINGS = {
releaseTexture: 'es_rm_releaseTexture',
registerTextureWithPath: 'es_rm_registerTextureWithPath',
getTextureDimensions: 'es_getTextureDimensions',
+ setTextureMetadata: 'es_rm_setTextureMetadata',
} as const;
/**
diff --git a/sdk/src/ecs/bridge/nativeResourceManager.ts b/sdk/src/ecs/bridge/nativeResourceManager.ts
index 194132119..a295b9619 100644
--- a/sdk/src/ecs/bridge/nativeResourceManager.ts
+++ b/sdk/src/ecs/bridge/nativeResourceManager.ts
@@ -121,6 +121,13 @@ export function createNativeResourceManager(
hostCallOpt(scope, RESOURCE_BINDINGS.registerTextureWithPath, [handle, path]);
},
+ // A texture's nine-slice border, from its import settings. Without it a
+ // UIVisual that takes its border from the texture draws as one stretched
+ // quad on a device — the corners of a rounded panel come out square.
+ setTextureMetadata: (handle, left, right, top, bottom): void => {
+ hostCallOpt(scope, RESOURCE_BINDINGS.setTextureMetadata, [handle, left, right, top, bottom]);
+ },
+
getTextureDimensions: (handle): { width: number; height: number } | null =>
(hostCallOpt(scope, RESOURCE_BINDINGS.getTextureDimensions, [handle]) as
{ width: number; height: number } | null | undefined) ?? null,
diff --git a/src/esengine/renderer/plugins/BatchPlugin.cpp b/src/esengine/renderer/plugins/BatchPlugin.cpp
index 96e6be99b..c258d6877 100644
--- a/src/esengine/renderer/plugins/BatchPlugin.cpp
+++ b/src/esengine/renderer/plugins/BatchPlugin.cpp
@@ -72,12 +72,18 @@ void BatchPlugin::emitNineSlice(
if (uvScale.x < 0.0f) std::swap(L, R);
if (uvScale.y < 0.0f) std::swap(T, B);
- // Fit destination borders proportionally when the box is smaller than
- // their sum. Source UV borders still sample the original texture region.
+ // Fit destination borders when the box is smaller than their sum, by ONE
+ // factor for both axes — the rule CSS applies to border radii. Fitting each
+ // axis on its own squeezes a short panel's corners into ellipses: a 20px
+ // round corner on a 30px-tall box became 20x15. Source UV borders still
+ // sample the original texture region.
const f32 directionX = std::copysign(1.0f, size.x);
const f32 directionY = std::copysign(1.0f, size.y);
- const f32 sx = directionX * (L + R > 0.0f ? std::min(1.0f, std::abs(size.x) / (L + R)) : 1.0f);
- const f32 sy = directionY * (T + B > 0.0f ? std::min(1.0f, std::abs(size.y) / (T + B)) : 1.0f);
+ const f32 fitX = L + R > 0.0f ? std::abs(size.x) / (L + R) : 1.0f;
+ const f32 fitY = T + B > 0.0f ? std::abs(size.y) / (T + B) : 1.0f;
+ const f32 fit = std::min(1.0f, std::min(fitX, fitY));
+ const f32 sx = directionX * fit;
+ const f32 sy = directionY * fit;
f32 baseX = position.x - size.x * pivotNorm.x;
f32 baseY = position.y - size.y * pivotNorm.y;