@@ -2336,6 +2336,7 @@ UILayerInstanceElement.prototype.measure_item = function(node, max_width, max_he
23362336 width : ( ( ( instance . bbox . right - instance . bbox . left ) / instance . image_xscale ) * this . instanceScaleX ) ,
23372337 height : ( ( ( instance . bbox . bottom - instance . bbox . top ) / instance . image_yscale ) * this . instanceScaleY ) ,
23382338 } ;
2339+ ret = stretch_item_size ( node , max_width , max_height , this , ret ) ;
23392340 return ret ;
23402341 }
23412342 else {
@@ -2578,6 +2579,7 @@ UILayerSequenceElement.prototype.measure_item = function(node, max_width, max_he
25782579 {
25792580 /* Sequence width/height (at t=0) is calculated by the IDE for us. */
25802581 var ret = { width : sequence . m_width , height : sequence . m_height } ;
2582+ ret = stretch_item_size ( node , max_width , max_height , this , ret ) ;
25812583 return ret ;
25822584 }
25832585
@@ -2895,6 +2897,8 @@ UILayerSpriteElement.prototype.measure_item = function(node, max_width, max_heig
28952897 }
28962898
28972899 ret = { width : sprite_width , height : sprite_height } ;
2900+ ret = stretch_item_size ( node , max_width , max_height , this , ret ) ;
2901+
28982902 return ret ;
28992903 }
29002904 else {
@@ -3149,6 +3153,47 @@ UILayerTextElement.prototype.position = function(container, clipping_rect, set_c
31493153 }
31503154} ;
31513155
3156+ function stretch_item_size ( node , max_width , max_height , element , _size )
3157+ {
3158+ var size = { width : _size . width , height : _size . height } ;
3159+ /* When stretch and keep aspect is enabled, we allow the text to grow to fit a fixed-size
3160+ * container in one dimension and then grow the other (auto sized) dimension to fit via the
3161+ * measure function...
3162+ *
3163+ * This logic is copied from RoomItemHelper.MeasureItemSize() in the IDE.
3164+ */
3165+
3166+ if ( element . keepAspect && ( element . stretchWidth || element . stretchHeight ) ) {
3167+ var node_width = node . getWidth ( ) ;
3168+ var node_height = node . getHeight ( ) ;
3169+
3170+ var autoW = node_width . unit == YGUnitAuto ;
3171+ var autoH = node_height . unit == YGUnitAuto ;
3172+ var parentW = ( autoW ) ? Math . min ( size . width , max_width ) : max_width ; //parent width = item width, when auto sized
3173+ var parentH = ( autoH ) ? Math . min ( size . height , max_height ) : max_height ;
3174+ var contentAspect = size . width / size . height ;
3175+ var adjustHeight = true ;
3176+ if ( autoW && autoH ) {
3177+ var parentAspect = parentW / parentH ; //parent size = item size in both dimensions
3178+ adjustHeight = ( contentAspect > parentAspect ) ;
3179+ }
3180+ else if ( autoW ) {
3181+ size . width = Math . abs ( max_height * contentAspect ) ; //we cannot adjust fixed height
3182+ }
3183+ else if ( autoH ) {
3184+ size . height = Math . abs ( max_width / contentAspect ) ; //we cannot adjust fixed width
3185+ }
3186+
3187+ if ( adjustHeight )
3188+ size . height = Math . abs ( parentW / contentAspect ) ;
3189+ else
3190+ size . width = Math . abs ( parentH * contentAspect ) ;
3191+ }
3192+
3193+ return size ;
3194+
3195+ }
3196+
31523197UILayerTextElement . prototype . measure_item = function ( node , max_width , max_height )
31533198{
31543199 var ret ;
@@ -3177,37 +3222,10 @@ UILayerTextElement.prototype.measure_item = function(node, max_width, max_height
31773222 * This logic is copied from RoomItemHelper.MeasureItemSize() in the IDE.
31783223 */
31793224
3180- if ( ( ! element . m_wrap ) && this . keepAspect && ( this . stretchWidth || this . stretchHeight ) )
3225+ if ( ( ! element . m_wrap ) )
31813226 {
3182- var node_width = node . getWidth ( ) ;
3183- var node_height = node . getHeight ( ) ;
3184-
3185- var autoW = node_width . unit == YGUnitAuto ;
3186- var autoH = node_height . unit == YGUnitAuto ;
3187- var parentW = ( autoW ) ? size . width : max_width ; //parent width = item width, when auto sized
3188- var parentH = ( autoH ) ? size . height : max_height ;
3189- var contentAspect = size . width / size . height ;
3190- var adjustHeight = true ;
3191- if ( autoW && autoH )
3192- {
3193- var parentAspect = parentW / parentH ; //parent size = item size in both dimensions
3194- adjustHeight = ( contentAspect > parentAspect ) ;
3195- }
3196- else if ( autoW )
3197- {
3198- size . width = Math . abs ( max_height * contentAspect ) ; //we cannot adjust fixed height
3199- }
3200- else if ( autoH )
3201- {
3202- size . height = Math . abs ( max_width / contentAspect ) ; //we cannot adjust fixed width
3203- }
3204-
3205- if ( adjustHeight )
3206- size . height = Math . abs ( parentW / contentAspect ) ;
3207- else
3208- size . width = Math . abs ( parentH * contentAspect ) ;
3227+ size = stretch_item_size ( node , max_width , max_height , this , size ) ;
32093228 }
3210-
32113229 return size ;
32123230} ;
32133231
0 commit comments