-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathTextCallout.hx
More file actions
356 lines (272 loc) · 8.08 KB
/
TextCallout.hx
File metadata and controls
356 lines (272 loc) · 8.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
/*
Feathers UI
Copyright 2026 Bowler Hat LLC. All Rights Reserved.
This program is free software. You can redistribute and/or modify it in
accordance with the terms of the accompanying license agreement.
*/
package feathers.controls;
import feathers.core.IHTMLTextControl;
import feathers.core.ITextControl;
import feathers.layout.RelativePositions;
import feathers.text.TextFormat;
import openfl.display.DisplayObject;
#if (openfl >= "9.2.0")
import openfl.text.StyleSheet;
#elseif flash
import flash.text.StyleSheet;
#end
/**
A special type of `Callout` designed to display text only.
In the following example, a text callout is shown when a `Button` is
triggered:
```haxe
function button_triggerHandler(event:TriggerEvent):Void
{
var button = cast(event.currentTarget, Button);
TextCallout.show("Hello World", button);
}
button.addEventListener(TriggerEvent.TRIGGER, button_triggerHandler);
```
@see [Tutorial: How to use the TextCallout component](https://feathersui.com/learn/haxe-openfl/text-callout/)
@see `TextCallout.show()`
@since 1.0.0
**/
@defaultXmlProperty("text")
@:styleContext
class TextCallout extends Callout implements ITextControl implements IHTMLTextControl {
/**
A variant used to style the callout in a style that indicates that
something related to the origin is considered dangerous or in error.
Variants allow themes to provide an assortment of different appearances
for the same type of UI component.
The following example uses this variant:
```haxe
callout.variant = TextCallout.VARIANT_DANGER;
```
@see `feathers.style.IVariantStyleObject.variant`
@see [Feathers UI User Manual: Themes](https://feathersui.com/learn/haxe-openfl/themes/)
@since 1.0.0
**/
public static final VARIANT_DANGER = "danger";
/**
Creates a text callout, and then positions and sizes it automatically
based based on an origin component and an optional set of positions.
In the following example, a text callout is shown when a `Button` is
triggered:
```haxe
function button_triggerHandler(event:TriggerEvent):Void
{
var button = cast(event.currentTarget, Button);
TextCallout.show("Hello World", button);
}
button.addEventListener(TriggerEvent.TRIGGER, button_triggerHandler);
```
@since 1.0.0
**/
public static function show(text:String, origin:DisplayObject, ?supportedPositions:RelativePositions, modal:Bool = true):TextCallout {
var callout = new TextCallout(text);
return cast(Callout.showCallout(callout, origin, supportedPositions, modal), TextCallout);
}
/**
Creates a new `TextCallout` object.
In general, a `TextCallout` shouldn't be instantiated directly with the
constructor. Instead, use the static function `TextCallout.show()` to
create a `TextCallout`, as this often requires less pop-up management
code.
@see `TextCallout.show()`
@since 1.0.0
**/
public function new(text:String = "") {
initializeTextCalloutTheme();
super();
this.text = text;
}
private var label:Label;
private var _text:String;
/**
The text displayed by the text callout.
The following example creates a text callout and changes its text:
```haxe
var callout = TextCallout.show("Good morning!", origin);
callout.text = "Good afternoon!";
```
@see `TextCallout.textFormat`
@since 1.0.0
**/
@:inspectable
public var text(get, set):String;
private function get_text():String {
return this._text;
}
private function set_text(value:String):String {
if (this._text == value) {
return this._text;
}
this._text = value;
this.setInvalid(DATA);
return this._text;
}
private var _htmlText:String = null;
/**
Text displayed by the callout that is parsed as a simple form of HTML.
The following example sets the callout's HTML text:
```haxe
callout.htmlText = "<b>Hello</b> <i>World</i>";
```
@default null
@see `TextCallout.text`
@see [`openfl.text.TextField.htmlText`](https://api.openfl.org/openfl/text/TextField.html#htmlText)
@since 1.0.0
**/
public var htmlText(get, set):String;
private function get_htmlText():String {
return this._htmlText;
}
private function set_htmlText(value:String):String {
if (this._htmlText == value) {
return this._htmlText;
}
this._htmlText = value;
this.setInvalid(DATA);
return this._htmlText;
}
/**
@see `feathers.core.ITextControl.baseline`
**/
public var baseline(get, never):Float;
private function get_baseline():Float {
if (this.label == null) {
return 0.0;
}
return this.label.y + this.label.baseline;
}
/**
The font styles used to render the text callout's text.
In the following example, the text callout's formatting is customized:
```haxe
callout.textFormat = new TextFormat("Helvetica", 20, 0xcc0000);
```
@see `TextCallout.text`
@see `TextCallout.disabledTextFormat`
@see `TextCallout.embedFonts`
@since 1.0.0
**/
@:style
public var textFormat:AbstractTextFormat = null;
/**
Configures the `alpha` value of the text callout's text.
In the following example, the text callout's text alpha is customized:
```haxe
callout.textAlpha = 0.5;
```
@see `TextCallout.textFormat`
@since 1.4.0
**/
@:style
@:inspectable(minValue = "0.0", maxValue = "1.0", verbose = "1")
public var textAlpha:Float = 1.0;
#if (openfl >= "9.2.0" || flash)
/**
A custom stylesheet to use with `htmlText`.
If the `styleSheet` style is not `null`, the `textFormat` style will
be ignored.
@see `TextCallout.htmlText`
@since 1.0.0
**/
@:style
public var styleSheet:StyleSheet = null;
#end
/**
Determines if an embedded font is used or not.
In the following example, the callout uses embedded fonts:
```haxe
callout.embedFonts = true;
```
@see `TextCallout.textFormat`
@since 1.0.0
**/
@:style
public var embedFonts:Bool = false;
/**
The font styles used to render the text callout's text when the text
callout is disabled.
In the following example, the text callout's disabled text formatting is
customized:
```haxe
callout.enabled = false;
callout.disabledTextFormat = new TextFormat("Helvetica", 20, 0xee0000);
```
@see `TextCallout.textFormat`
@since 1.0.0
**/
@:style
public var disabledTextFormat:AbstractTextFormat = null;
/**
Determines if the text is displayed on a single line, or if it wraps.
In the following example, the callout's text wraps at 150 pixels:
```haxe
callout.width = 150.0;
callout.wordWrap = true;
```
@default false
@since 1.0.0
**/
@:style
public var wordWrap:Bool = false;
#if (openfl >= "9.2.0" || flash)
/**
Determines if the whitespace in the `htmlText` is condensed or affects
the text layout.
In the following example, the callout's HTML text whitespace is condensed:
```haxe
callout.htmlText = "<p>Hello</p>\n<p>World</p>";
callout.condenseWhite = true;
```
@default false
@see `TextCallout.htmlText`
@since 1.4.0
**/
@:style
public var condenseWhite:Bool = false;
#end
private function initializeTextCalloutTheme():Void {
#if !feathersui_disable_default_theme
feathers.themes.steel.components.SteelTextCalloutStyles.initialize();
#end
}
override private function initialize():Void {
super.initialize();
if (this.label == null) {
this.label = new Label();
this.addChild(this.label);
this.content = this.label;
}
}
override private function update():Void {
var dataInvalid = this.isInvalid(DATA);
var stateInvalid = this.isInvalid(STATE);
var stylesInvalid = this.isInvalid(STYLES);
if (stylesInvalid || stateInvalid) {
this.refreshTextStyles();
}
if (dataInvalid || stylesInvalid || stateInvalid) {
this.refreshText();
}
super.update();
}
private function refreshTextStyles():Void {
this.label.wordWrap = this.wordWrap;
this.label.textFormat = this.textFormat;
this.label.disabledTextFormat = this.disabledTextFormat;
this.label.embedFonts = this.embedFonts;
#if (openfl >= "9.2.0" || flash)
this.label.styleSheet = this.styleSheet;
this.label.condenseWhite = this.condenseWhite;
#end
this.label.textAlpha = this.textAlpha;
}
private function refreshText():Void {
this.label.text = this._text;
this.label.htmlText = this._htmlText;
}
}