/ext-4.1.0_b3/docs/source/Text.html

https://bitbucket.org/srogerf/javascript · HTML · 195 lines · 180 code · 15 blank · 0 comment · 0 complexity · faa98574a3cd03e0ab2ce88e3e9d96ae MD5 · raw file

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-draw-Text-method-constructor'><span id='Ext-draw-Text'>/**
  19. </span></span> * This class encapsulates a drawn text item as rendered by the Ext.draw package within a Component which can be
  20. * then used anywhere in an ExtJS application just like any other Component.
  21. *
  22. * ## Example usage
  23. *
  24. * @example
  25. * Ext.create('Ext.panel.Panel', {
  26. * title: 'Panel with VerticalTextItem',
  27. * width: 300,
  28. * height: 200,
  29. * lbar: {
  30. * layout: {
  31. * align: 'center'
  32. * },
  33. * items: [{
  34. * xtype: 'text',
  35. * text: 'Sample VerticalTextItem',
  36. * degrees: 90
  37. * }]
  38. * },
  39. * renderTo: Ext.getBody()
  40. * });
  41. *
  42. * @constructor
  43. * Creates a new Text Component
  44. * @param {Object} text A config object containing a `text` property, a `degrees` property,
  45. * and, optionally, a `styleSelector` property which specifies a selector which provides CSS rules to
  46. * give font family, size and color to the drawn text.
  47. */
  48. Ext.define('Ext.draw.Text', {
  49. extend: 'Ext.draw.Component',
  50. uses: ['Ext.util.CSS'],
  51. alias: 'widget.text',
  52. <span id='Ext-draw-Text-cfg-text'> /**
  53. </span> * @cfg {String} text
  54. * The text to display (html tags are &lt;b&gt;not&lt;/b&gt; accepted)
  55. */
  56. text: '',
  57. <span id='Ext-draw-Text-cfg-styleSelector'> /**
  58. </span> * @cfg {String} styleSelector
  59. * A CSS selector string which matches a style rule in the document stylesheet from which
  60. * the text's font properties are read.
  61. *
  62. * **Drawn** text is not styled by CSS, but by properties set during its construction, so these styles
  63. * must be programatically read from a stylesheet rule found via a selector at construction time.
  64. */
  65. <span id='Ext-draw-Text-cfg-degrees'> /**
  66. </span> * @cfg {Number} degrees
  67. * The angle by which to initially rotate the text clockwise. Defaults to zero.
  68. */
  69. focusable: false,
  70. viewBox: false,
  71. autoSize: true,
  72. baseCls: Ext.baseCSSPrefix + 'surface ' + Ext.baseCSSPrefix + 'draw-text',
  73. initComponent: function() {
  74. var me = this;
  75. me.textConfig = Ext.apply({
  76. type: 'text',
  77. text: me.text,
  78. rotate: {
  79. degrees: me.degrees || 0
  80. }
  81. }, me.textStyle);
  82. Ext.apply(me.textConfig, me.getStyles(me.styleSelectors || me.styleSelector));
  83. // Surface is created from the *initialConfig*, not the current object state,
  84. // So the generated items must go into the initialConfig
  85. me.initialConfig.items = [me.textConfig];
  86. me.callParent(arguments);
  87. },
  88. <span id='Ext-draw-Text-method-getStyles'> /**
  89. </span> * @private
  90. * Accumulates a style object based upon the styles specified in document stylesheets
  91. * by an array of CSS selectors
  92. */
  93. getStyles: function(selectors) {
  94. selectors = Ext.Array.from(selectors);
  95. var i = 0,
  96. len = selectors.length,
  97. rule,
  98. style,
  99. prop,
  100. result = {};
  101. for (; i &lt; len; i++) {
  102. // Get the style rule which exactly matches the selector.
  103. rule = Ext.util.CSS.getRule(selectors[i]);
  104. if (rule) {
  105. style = rule.style;
  106. if (style) {
  107. Ext.apply(result, {
  108. 'font-family': style.fontFamily,
  109. 'font-weight': style.fontWeight,
  110. 'line-height': style.lineHeight,
  111. 'font-size': style.fontSize,
  112. fill: style.color
  113. });
  114. }
  115. }
  116. }
  117. return result;
  118. },
  119. <span id='Ext-draw-Text-method-setAngle'> /**
  120. </span> * Sets the clockwise rotation angle relative to the horizontal axis.
  121. * @param {Number} degrees The clockwise angle (in degrees) from the horizontal axis
  122. * by which the text should be rotated.
  123. */
  124. setAngle: function(degrees) {
  125. var me = this,
  126. surface,
  127. sprite;
  128. if (me.rendered) {
  129. surface = me.surface;
  130. sprite = surface.items.items[0];
  131. me.degrees = degrees;
  132. sprite.setAttributes({
  133. rotate: {
  134. degrees: degrees
  135. }
  136. }, true);
  137. if (me.autoSize || me.viewBox) {
  138. me.updateLayout();
  139. }
  140. } else {
  141. me.degrees = degrees;
  142. }
  143. },
  144. <span id='Ext-draw-Text-method-setText'> /**
  145. </span> * Updates this item's text.
  146. * @param {String} t The text to display (html **not** accepted).
  147. */
  148. setText: function(text) {
  149. var me = this,
  150. surface,
  151. sprite;
  152. if (me.rendered) {
  153. surface = me.surface;
  154. sprite = surface.items.items[0];
  155. me.text = text || '';
  156. surface.remove(sprite);
  157. me.textConfig.type = 'text';
  158. me.textConfig.text = me.text;
  159. sprite = surface.add(me.textConfig);
  160. sprite.setAttributes({
  161. rotate: {
  162. degrees: me.degrees
  163. }
  164. }, true);
  165. if (me.autoSize || me.viewBox) {
  166. me.updateLayout();
  167. }
  168. } else {
  169. me.on({
  170. render: function() {
  171. me.setText(text);
  172. },
  173. single: true
  174. });
  175. }
  176. }
  177. });
  178. </pre>
  179. </body>
  180. </html>