Add image atlas and nine-slice support
This commit is contained in:
@@ -8,6 +8,14 @@ class RuntimeNode {
|
||||
required this.type,
|
||||
this.parent,
|
||||
this.asset,
|
||||
this.sourceX,
|
||||
this.sourceY,
|
||||
this.sourceWidth,
|
||||
this.sourceHeight,
|
||||
this.sliceLeft,
|
||||
this.sliceTop,
|
||||
this.sliceRight,
|
||||
this.sliceBottom,
|
||||
this.pressedAsset,
|
||||
this.disabledAsset,
|
||||
this.animation,
|
||||
@@ -70,6 +78,14 @@ class RuntimeNode {
|
||||
final String type;
|
||||
final String? parent;
|
||||
final String? asset;
|
||||
final double? sourceX;
|
||||
final double? sourceY;
|
||||
final double? sourceWidth;
|
||||
final double? sourceHeight;
|
||||
final double? sliceLeft;
|
||||
final double? sliceTop;
|
||||
final double? sliceRight;
|
||||
final double? sliceBottom;
|
||||
final String? pressedAsset;
|
||||
final String? disabledAsset;
|
||||
final String? animation;
|
||||
@@ -213,6 +229,26 @@ class RuntimeNode {
|
||||
type: nextType,
|
||||
parent: _parentProp(props, currentParent: parent, nodeId: id),
|
||||
asset: _stringProp(props, RuntimeProtocolField.asset) ?? asset,
|
||||
sourceX: _nonNegativeDoubleProp(props, RuntimeProtocolField.sourceX) ?? sourceX,
|
||||
sourceY: _nonNegativeDoubleProp(props, RuntimeProtocolField.sourceY) ?? sourceY,
|
||||
sourceWidth:
|
||||
_positiveDoubleProp(props, RuntimeProtocolField.sourceWidth) ??
|
||||
sourceWidth,
|
||||
sourceHeight:
|
||||
_positiveDoubleProp(props, RuntimeProtocolField.sourceHeight) ??
|
||||
sourceHeight,
|
||||
sliceLeft:
|
||||
_nonNegativeDoubleProp(props, RuntimeProtocolField.sliceLeft) ??
|
||||
sliceLeft,
|
||||
sliceTop:
|
||||
_nonNegativeDoubleProp(props, RuntimeProtocolField.sliceTop) ??
|
||||
sliceTop,
|
||||
sliceRight:
|
||||
_nonNegativeDoubleProp(props, RuntimeProtocolField.sliceRight) ??
|
||||
sliceRight,
|
||||
sliceBottom:
|
||||
_nonNegativeDoubleProp(props, RuntimeProtocolField.sliceBottom) ??
|
||||
sliceBottom,
|
||||
pressedAsset:
|
||||
_stringProp(props, RuntimeProtocolField.pressedAsset) ?? pressedAsset,
|
||||
disabledAsset:
|
||||
@@ -345,6 +381,20 @@ class RuntimeNode {
|
||||
nodeId: _requiredString(map, RuntimeProtocolField.id),
|
||||
),
|
||||
asset: _stringProp(map, RuntimeProtocolField.asset),
|
||||
sourceX: _nonNegativeDoubleProp(map, RuntimeProtocolField.sourceX),
|
||||
sourceY: _nonNegativeDoubleProp(map, RuntimeProtocolField.sourceY),
|
||||
sourceWidth: _positiveDoubleProp(map, RuntimeProtocolField.sourceWidth),
|
||||
sourceHeight: _positiveDoubleProp(
|
||||
map,
|
||||
RuntimeProtocolField.sourceHeight,
|
||||
),
|
||||
sliceLeft: _nonNegativeDoubleProp(map, RuntimeProtocolField.sliceLeft),
|
||||
sliceTop: _nonNegativeDoubleProp(map, RuntimeProtocolField.sliceTop),
|
||||
sliceRight: _nonNegativeDoubleProp(map, RuntimeProtocolField.sliceRight),
|
||||
sliceBottom: _nonNegativeDoubleProp(
|
||||
map,
|
||||
RuntimeProtocolField.sliceBottom,
|
||||
),
|
||||
pressedAsset: _stringProp(map, RuntimeProtocolField.pressedAsset),
|
||||
disabledAsset: _stringProp(map, RuntimeProtocolField.disabledAsset),
|
||||
animation: _stringProp(map, RuntimeProtocolField.animation),
|
||||
@@ -530,6 +580,17 @@ class RuntimeNode {
|
||||
return value;
|
||||
}
|
||||
|
||||
static double? _positiveDoubleProp(Map<String, Object?> map, String key) {
|
||||
final value = _doubleProp(map, key);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (value <= 0) {
|
||||
throw FormatException('RuntimeNode.$key must be > 0');
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static double? _scrollProp(
|
||||
Map<String, Object?> map,
|
||||
String key, {
|
||||
|
||||
Reference in New Issue
Block a user