Add image atlas and nine-slice support

This commit is contained in:
gem
2026-06-09 12:30:44 +08:00
parent 409942b4af
commit e2a584d4dc
12 changed files with 453 additions and 24 deletions

View File

@@ -10,6 +10,14 @@ void main() {
'type': 'button',
'parent': 'top_bar',
'asset': 'dice_normal',
'sourceX': 4,
'sourceY': 5,
'sourceWidth': 64,
'sourceHeight': 32,
'sliceLeft': 6,
'sliceTop': 7,
'sliceRight': 8,
'sliceBottom': 9,
'pressedAsset': 'dice_pressed',
'disabledAsset': 'dice_disabled',
'animation': 'idle',
@@ -72,6 +80,14 @@ void main() {
expect(node.type, 'button');
expect(node.parent, 'top_bar');
expect(node.asset, 'dice_normal');
expect(node.sourceX, 4);
expect(node.sourceY, 5);
expect(node.sourceWidth, 64);
expect(node.sourceHeight, 32);
expect(node.sliceLeft, 6);
expect(node.sliceTop, 7);
expect(node.sliceRight, 8);
expect(node.sliceBottom, 9);
expect(node.pressedAsset, 'dice_pressed');
expect(node.disabledAsset, 'dice_disabled');
expect(node.animation, 'idle');
@@ -147,6 +163,14 @@ void main() {
expect(node.textShadowOffsetX, isNull);
expect(node.textShadowOffsetY, isNull);
expect(node.textShadowBlur, isNull);
expect(node.sourceX, isNull);
expect(node.sourceY, isNull);
expect(node.sourceWidth, isNull);
expect(node.sourceHeight, isNull);
expect(node.sliceLeft, isNull);
expect(node.sliceTop, isNull);
expect(node.sliceRight, isNull);
expect(node.sliceBottom, isNull);
expect(node.scrollbarVisible, isTrue);
expect(node.paddingLeft, 0);
expect(node.paddingTop, 0);
@@ -182,6 +206,14 @@ void main() {
'paddingBottom': 11,
'contentWidth': 120,
'contentHeight': 100,
'sourceX': 3,
'sourceY': 4,
'sourceWidth': 40,
'sourceHeight': 41,
'sliceLeft': 5,
'sliceTop': 6,
'sliceRight': 7,
'sliceBottom': 8,
'pressedAsset': 'button_pressed',
'disabledAsset': 'button_disabled',
'scrollX': 90,
@@ -213,6 +245,14 @@ void main() {
expect(updated.paddingBottom, 11);
expect(updated.contentWidth, 120);
expect(updated.contentHeight, 100);
expect(updated.sourceX, 3);
expect(updated.sourceY, 4);
expect(updated.sourceWidth, 40);
expect(updated.sourceHeight, 41);
expect(updated.sliceLeft, 5);
expect(updated.sliceTop, 6);
expect(updated.sliceRight, 7);
expect(updated.sliceBottom, 8);
expect(updated.pressedAsset, 'button_pressed');
expect(updated.disabledAsset, 'button_disabled');
expect(updated.scrollX, 68);
@@ -255,6 +295,22 @@ void main() {
() => RuntimeNode.fromMap({'id': 'a', 'type': 'progress', 'value': 2}),
throwsFormatException,
);
expect(
() => RuntimeNode.fromMap({
'id': 'a',
'type': 'image',
'sourceWidth': 0,
}),
throwsFormatException,
);
expect(
() => RuntimeNode.fromMap({
'id': 'a',
'type': 'image',
'sliceLeft': -1,
}),
throwsFormatException,
);
expect(
() => RuntimeNode.fromMap({
'id': 'a',