forked from Jibo-Revival-Group/JiboOs
181 lines
6.4 KiB
JavaScript
181 lines
6.4 KiB
JavaScript
|
|
/**
|
||
|
|
* @interface jibo.face.views.Label~LabelOptions
|
||
|
|
* @extends jibo.face.views.Element~ElementOptions
|
||
|
|
* @description Interface describing data provided in the config for label initialization.
|
||
|
|
* @prop {PIXI.TextStyle} [style] - Structure that describes text style.
|
||
|
|
* @prop {String} [text] - Text value shown in the label.
|
||
|
|
* @prop {jibo.face.views.Element~PointData} [targetAnchor] - Anchor point for the label.
|
||
|
|
* @prop {jibo.face.views.Element~DimensionData} [bounds] - Bounds for text. When specified font will be decreased to fit.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Wraps text label in Pixi.
|
||
|
|
*
|
||
|
|
* @class Label
|
||
|
|
* @extends jibo.face.views.Element
|
||
|
|
* @memberof jibo.face.views
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Default value for the text style if one's missing.
|
||
|
|
* @name jibo.face.views.Label.DEFAULT_STYLE
|
||
|
|
* @type {PIXI.TextStyle}
|
||
|
|
* @readOnly
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The default class identifier.
|
||
|
|
* Generally used to register the class.
|
||
|
|
* @name jibo.face.views.Label.DEFAULT_TYPE
|
||
|
|
* @type {String}
|
||
|
|
* @readOnly
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Object describing the font specification used by `PIXI.Text`.
|
||
|
|
* ```
|
||
|
|
* fontSize: 100,
|
||
|
|
* fontFamily: 'Proxima Nova Soft',
|
||
|
|
* fill: '#FFFFFF',
|
||
|
|
* fontStyle: 'bold'
|
||
|
|
* wordWrap: true,
|
||
|
|
* wordWrapWidth: 100,
|
||
|
|
* align: 'center'
|
||
|
|
* ```
|
||
|
|
* @name jibo.face.views.Label#style
|
||
|
|
* @type {PIXI.TextStyle}
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Reference to the PIXI.Text object.
|
||
|
|
* @name jibo.face.views.Label#textDisplay
|
||
|
|
* @type {PIXI.Text}
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Bounds of the label component
|
||
|
|
* @name jibo.face.views.Label#_bounds
|
||
|
|
* @type {jibo.face.views.Element~DimensionData}
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Dimensional boundaries of the label that text display cannot exceed.
|
||
|
|
* If defined, {@link jibo.face.views.Label#style}`.fontSize` will be scaled to fit.
|
||
|
|
* Does not increase `fontSize` if text will fit provided boundaries.
|
||
|
|
* @example
|
||
|
|
* x: 300, // width
|
||
|
|
* y: 100 // height
|
||
|
|
* @name jibo.face.views.Label#bounds
|
||
|
|
* @type {jibo.face.views.Element~DimensionData}
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Anchor values for display, values range from 0 to 1
|
||
|
|
* and represent a percentage of the total width or height.
|
||
|
|
* If defined anchor values will be applied to display on its creation.
|
||
|
|
* @name jibo.face.views.Label#_targetAnchor
|
||
|
|
* @type {PIXI.Point}
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Text message to display.
|
||
|
|
* @name jibo.face.views.Label#_text
|
||
|
|
* @type {String}
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Keeps reference to original font size specified by style.
|
||
|
|
* A reference is necessary as the font size can be adjusted to fit the bounds.
|
||
|
|
* @name jibo.face.views.Label#_originalFontSize
|
||
|
|
* @type {String}
|
||
|
|
* @private
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Text to display.
|
||
|
|
* If display exists updating the text value will also update the display.
|
||
|
|
* @name jibo.face.views.Label#text
|
||
|
|
* @type {String}
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Helper method to create font style Objects for use with `PIXI.Text`.
|
||
|
|
* @method jibo.face.views.Label.createFontStyle
|
||
|
|
* @param {Number|String} size The size of the font.
|
||
|
|
* @param {String} family The font family/name.
|
||
|
|
* @param {String} color The font color.
|
||
|
|
* @param {String} [style] The font style (e.g. bold, italic)
|
||
|
|
* @param {String} [align] The font alignment (e.g. left, center, right)
|
||
|
|
* @returns {PIXI.TextStyle} [style] Object in format required by Pixi to define text style.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create Label from config Object.
|
||
|
|
* @method jibo.face.views.Label.createFromConfig
|
||
|
|
* @param configData {any} Configuration object to create label for.
|
||
|
|
* @returns {jibo.face.views.Label} Label created.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the width and height of `PIXI.Text` based on current text and style.
|
||
|
|
* If text has not been defined method will use given `sampleText`, if that is not given uses an internal default.
|
||
|
|
* @method jibo.face.views.Label#getTextDimensions
|
||
|
|
* @param {String} [sampleText] Used only if {@link jibo.face.views.Label#text} is undefined.
|
||
|
|
* @returns {jibo.face.views.Element~DimensionData} Dimensions of text.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Predefine the anchor point for your text. These anchors are applied when `applyTransition` is called.
|
||
|
|
* This is useful for defining anchor of the label before the display is created.
|
||
|
|
* @method jibo.face.views.Label#setTargetAnchor
|
||
|
|
* @param {int} [x = 0] - Value between 0 and 1, percentage of width where the anchor should be placed.
|
||
|
|
* @param {int} [y = 0] - Value between 0 and 1, percentage of height where the anchor should be placed.
|
||
|
|
* @param {Boolean} [applyNow = false] If `true` will apply anchor position to Text within method,
|
||
|
|
* as long as Text has been defined.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Apply target position and anchors if they were defined and if display and text have been created.
|
||
|
|
* @method jibo.face.views.Label#applyPosition
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* FOR OVERRIDE ONLY. DO NOT CALL.
|
||
|
|
*
|
||
|
|
* Open transition, defaults to fading alpha in from zero.
|
||
|
|
* @method jibo.face.views.Label#open
|
||
|
|
* @param {Function} [callback] Function to be called once open is complete.
|
||
|
|
* @param {String} transitionType String used to determine way Component opens,
|
||
|
|
* refer to ViewManager for constants used
|
||
|
|
* @param {number} [duration = ViewManager.TRANS_TIME] Duration of the transition.
|
||
|
|
* @param {String} [tweenType = sineOut] Type of tween used.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* FOR OVERRIDE ONLY. DO NOT CALL.
|
||
|
|
*
|
||
|
|
* Open transition, defaults to fading alpha out to zero.
|
||
|
|
* @method jibo.face.views.Label#close
|
||
|
|
* @param {Function} [callback] Function to be called once open is complete.
|
||
|
|
* @param {String} [transitionType] String used to determine way Component closes,
|
||
|
|
* refer to ViewManager for constants used.
|
||
|
|
* @param {number} [duration = ViewManager.TRANS_TIME] Duration of the transition.
|
||
|
|
* @param {String} [tweenType = sineIn] Type of tween used.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Adjust text font size to fit within bounds.
|
||
|
|
* Applies autofit if bounds were specified and display and text are defined.
|
||
|
|
* @method jibo.face.views.Label#applyTextBounds
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Extract font size from a text style and return as a number.
|
||
|
|
* @method jibo.face.views.Label#getFontSize
|
||
|
|
* @return {number} - Font size as a number
|
||
|
|
* @private
|
||
|
|
*/
|