Class: SC.AutoResize
Use this mixin to make your view automatically resize based upon its value, title, or other string property. Only works for views that support automatic resizing.
Supporting Automatic Resizing
To support automatic resizing, your view must provide these properties:
supportsAutoResize
. Must be set toYES
.autoResizeLayer
A DOM element to use as a template for resizing the view. Font sizes and other styles will be copied to the measuring element SproutCore uses to measure the text.autoResizeText
. The text to measure. A button view might make a proxy to itsdisplayTitle
, for instance.
Your view may also supply:
autoResizePadding
. An amount to add to the measured size. This may be either a single number to be added to both width and height, or a hash containing separatewidth
andheight
properties.
NOTE: these properties are not defined in the mixin itself because the supporting view,
rather than the user of SC.AutoResize
, will be providing the properties, and mixing
SC.AutoResize
into the view should not override these properties.
Defined in: auto_resize.js
Field Summary
- SC.AutoResize.autoFitDiscreteFontSizes
- SC.AutoResize.batchResizeId
- SC.AutoResize.calculatedFontSize
- SC.AutoResize.maxFontSize
- SC.AutoResize.maxHeight
- SC.AutoResize.maxWidth
- SC.AutoResize.measuredSize
- SC.AutoResize.minFontSize
- SC.AutoResize.shouldAutoFitText
- SC.AutoResize.shouldAutoResize
- SC.AutoResize.shouldCacheSizes
- SC.AutoResize.shouldMeasureSize
- SC.AutoResize.shouldResizeHeight
- SC.AutoResize.shouldResizeWidth
Class Methods
- applyAttributesToContext(orig, context)
- fitTextToFrame()
- fontPropertyDidChange()
- measuredSizeDidChange()
- measureSize(batch)
- prepareLayerForStringMeasurement(layer)
- scheduleMeasurement()
- viewDidResize(orig)
Field Detail
SC.AutoResize.autoFitDiscreteFontSizes BooleanIf NO
, the calculated font size may be any size between minFontSize
and
maxFontSize
. If YES, it will only be either minFontSize
or maxFontSize
.
- Default value:
- NO
The maximum font size to use when automatically fitting text. If shouldAutoFitText
is set,
this must be supplied.
Font size is in pixels.
The measured size of the view's content (the value of the autoResizeField
).
This property is observable, and, if used in conjunction with setting
shouldAutoResize
to NO
, allows you to customize the 'sizing' part, using
SC.AutoResize
purely for its measuring code.
The minimum font size to use when automatically fitting text. If shouldAutoFitText
is set,
this must be supplied.
Font size is in pixels.
If YES
, the view's text will be resized to fit the view. This is applied after any
resizing, so will only take affect if shouldAutoResize
is off, or a maximum width/height
is set.
You also must set a minimum and maximum font size. Any auto resizing will happen at the maximum size, and then the text will be resized as necessary.
If YES
, automatically resizes the view (default). If NO, only measures,
setting 'measuredSize' to the measured value (you can bind to measuredSize
and update size manually).
- Default value:
- YES
Caches sizes for measured strings. This cache does not have a max size, so
should only be used when a view has a limited number of possible values.
Multiple views that have the same batchResizeId
will share the same cache.
- Default value:
- NO
- Default value:
- YES
Determines if the view's height should be resized
on calculation. Default is NO
to retain backwards
compatibility.
- Default value:
- NO
Determines if the view's width should be resized on calculation.
- Default value:
- YES
Class Method Detail
- Parameters:
- orig
- context
- Parameters:
- batch
- For internal use during batch resizing.
If we are fitting text, the layer must be measured with its font size set to our maximum font size.
- Parameters:
- layer
- Parameters:
- orig