Skip to content

Commit 311f7ed

Browse files
committed
Text Controls: added antiAliasType and gridFitType to pass to internal TextField (closes #180)
1 parent 6021a07 commit 311f7ed

File tree

10 files changed

+460
-4
lines changed

10 files changed

+460
-4
lines changed

src/feathers/controls/Button.hx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
package feathers.controls;
1010

11-
import feathers.layout.ILayoutObject;
1211
import feathers.core.IFocusObject;
1312
import feathers.core.IHTMLTextControl;
1413
import feathers.core.IMeasureObject;
@@ -18,6 +17,7 @@ import feathers.core.IUIControl;
1817
import feathers.core.IValidating;
1918
import feathers.events.TriggerEvent;
2019
import feathers.layout.HorizontalAlign;
20+
import feathers.layout.ILayoutObject;
2121
import feathers.layout.Measurements;
2222
import feathers.layout.RelativePosition;
2323
import feathers.layout.VerticalAlign;
@@ -29,6 +29,8 @@ import openfl.events.Event;
2929
import openfl.events.FocusEvent;
3030
import openfl.events.KeyboardEvent;
3131
import openfl.events.MouseEvent;
32+
import openfl.text.AntiAliasType;
33+
import openfl.text.GridFitType;
3234
import openfl.text.TextField;
3335
import openfl.ui.Keyboard;
3436
#if (openfl >= "9.2.0")
@@ -324,6 +326,43 @@ class Button extends BasicButton implements ITextControl implements IHTMLTextCon
324326
@:style
325327
public var embedFonts:Bool = false;
326328

329+
/**
330+
Determines the type of anti-aliasing used for embedded fonts.
331+
332+
In the following example, the button uses advanced anti-aliasing:
333+
334+
```haxe
335+
button.embedFonts = true;
336+
button.antiAliasType = ADVANCED;
337+
```
338+
339+
@see `Button.embedFonts`
340+
@see `Button.gridFitType`
341+
342+
@since 1.4.0
343+
**/
344+
@:style
345+
public var antiAliasType:AntiAliasType = NORMAL;
346+
347+
/**
348+
Determines the type of anti-aliasing used for embedded fonts.
349+
350+
In the following example, the button uses sub-pixel grid fitting:
351+
352+
```haxe
353+
button.embedFonts = true;
354+
button.antiAliasType = ADVANCED;
355+
button.gridFitType = SUBPIXEL;
356+
```
357+
358+
@see `Button.antiAliasType`
359+
@see `Button.embedFonts`
360+
361+
@since 1.4.0
362+
**/
363+
@:style
364+
public var gridFitType:GridFitType = PIXEL;
365+
327366
/**
328367
Determines if the text is displayed on a single line, or if it wraps.
329368
@@ -1055,6 +1094,14 @@ class Button extends BasicButton implements ITextControl implements IHTMLTextCon
10551094
this.textField.embedFonts = this.embedFonts;
10561095
this._updatedTextStyles = true;
10571096
}
1097+
if (this.textField.antiAliasType != this.antiAliasType) {
1098+
this.textField.antiAliasType = this.antiAliasType;
1099+
this._updatedTextStyles = true;
1100+
}
1101+
if (this.textField.gridFitType != this.gridFitType) {
1102+
this.textField.gridFitType = this.gridFitType;
1103+
this._updatedTextStyles = true;
1104+
}
10581105
#if (openfl >= "9.2.0" || flash)
10591106
if (this.textField.styleSheet != this.styleSheet) {
10601107
this.textField.styleSheet = this.styleSheet;

src/feathers/controls/FormItem.hx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
package feathers.controls;
1010

11-
import feathers.events.FeathersEvent;
1211
import feathers.core.FeathersControl;
1312
import feathers.core.IFocusManagerAware;
1413
import feathers.core.IFocusObject;
1514
import feathers.core.IMeasureObject;
1615
import feathers.core.ITextControl;
1716
import feathers.core.IUIControl;
1817
import feathers.core.IValidating;
18+
import feathers.events.FeathersEvent;
1919
import feathers.layout.HorizontalAlign;
2020
import feathers.layout.Measurements;
2121
import feathers.layout.RelativePosition;
@@ -27,6 +27,8 @@ import openfl.display.DisplayObject;
2727
import openfl.errors.ArgumentError;
2828
import openfl.events.Event;
2929
import openfl.events.MouseEvent;
30+
import openfl.text.AntiAliasType;
31+
import openfl.text.GridFitType;
3032
import openfl.text.TextField;
3133
#if (openfl >= "9.2.0")
3234
import openfl.text.StyleSheet;
@@ -421,6 +423,43 @@ class FormItem extends FeathersControl implements ITextControl implements IFocus
421423
@:style
422424
public var embedFonts:Bool = false;
423425

426+
/**
427+
Determines the type of anti-aliasing used for embedded fonts.
428+
429+
In the following example, the form item uses advanced anti-aliasing:
430+
431+
```haxe
432+
formItem.embedFonts = true;
433+
formItem.antiAliasType = ADVANCED;
434+
```
435+
436+
@see `FormItem.embedFonts`
437+
@see `FormItem.gridFitType`
438+
439+
@since 1.4.0
440+
**/
441+
@:style
442+
public var antiAliasType:AntiAliasType = NORMAL;
443+
444+
/**
445+
Determines the type of anti-aliasing used for embedded fonts.
446+
447+
In the following example, the form item uses sub-pixel grid fitting:
448+
449+
```haxe
450+
formItem.embedFonts = true;
451+
formItem.antiAliasType = ADVANCED;
452+
formItem.gridFitType = SUBPIXEL;
453+
```
454+
455+
@see `FormItem.antiAliasType`
456+
@see `FormItem.embedFonts`
457+
458+
@since 1.4.0
459+
**/
460+
@:style
461+
public var gridFitType:GridFitType = PIXEL;
462+
424463
/**
425464
The minimum space, in pixels, between the form item's top edge and the
426465
form item's content.
@@ -985,6 +1024,14 @@ class FormItem extends FeathersControl implements ITextControl implements IFocus
9851024
this.textField.embedFonts = this.embedFonts;
9861025
this._updatedTextStyles = true;
9871026
}
1027+
if (this.textField.antiAliasType != this.antiAliasType) {
1028+
this.textField.antiAliasType = this.antiAliasType;
1029+
this._updatedTextStyles = true;
1030+
}
1031+
if (this.textField.gridFitType != this.gridFitType) {
1032+
this.textField.gridFitType = this.gridFitType;
1033+
this._updatedTextStyles = true;
1034+
}
9881035
#if (openfl >= "9.2.0" || flash)
9891036
if (this.textField.styleSheet != this.styleSheet) {
9901037
this.textField.styleSheet = this.styleSheet;

src/feathers/controls/Header.hx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import feathers.text.TextFormat;
2020
import feathers.utils.MeasurementsUtil;
2121
import openfl.display.DisplayObject;
2222
import openfl.events.Event;
23+
import openfl.text.AntiAliasType;
24+
import openfl.text.GridFitType;
2325
import openfl.text.TextField;
2426
#if (openfl >= "9.2.0")
2527
import openfl.text.StyleSheet;
@@ -222,6 +224,43 @@ class Header extends FeathersControl implements ITextControl {
222224
@:style
223225
public var embedFonts:Bool = false;
224226

227+
/**
228+
Determines the type of anti-aliasing used for embedded fonts.
229+
230+
In the following example, the header uses advanced anti-aliasing:
231+
232+
```haxe
233+
header.embedFonts = true;
234+
header.antiAliasType = ADVANCED;
235+
```
236+
237+
@see `Header.embedFonts`
238+
@see `Header.gridFitType`
239+
240+
@since 1.4.0
241+
**/
242+
@:style
243+
public var antiAliasType:AntiAliasType = NORMAL;
244+
245+
/**
246+
Determines the type of anti-aliasing used for embedded fonts.
247+
248+
In the following example, the header uses sub-pixel grid fitting:
249+
250+
```haxe
251+
header.embedFonts = true;
252+
header.antiAliasType = ADVANCED;
253+
header.gridFitType = SUBPIXEL;
254+
```
255+
256+
@see `Header.antiAliasType`
257+
@see `Header.embedFonts`
258+
259+
@since 1.4.0
260+
**/
261+
@:style
262+
public var gridFitType:GridFitType = PIXEL;
263+
225264
/**
226265
The font styles used to render the header's text when the header is
227266
disabled.
@@ -660,6 +699,14 @@ class Header extends FeathersControl implements ITextControl {
660699
this.textField.embedFonts = this.embedFonts;
661700
this._updatedTextStyles = true;
662701
}
702+
if (this.textField.antiAliasType != this.antiAliasType) {
703+
this.textField.antiAliasType = this.antiAliasType;
704+
this._updatedTextStyles = true;
705+
}
706+
if (this.textField.gridFitType != this.gridFitType) {
707+
this.textField.gridFitType = this.gridFitType;
708+
this._updatedTextStyles = true;
709+
}
663710
#if (openfl >= "9.2.0" || flash)
664711
if (this.textField.styleSheet != this.styleSheet) {
665712
this.textField.styleSheet = this.styleSheet;

src/feathers/controls/Label.hx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import openfl.display.DisplayObject;
2525
import openfl.display.InteractiveObject;
2626
import openfl.events.Event;
2727
import openfl.events.FocusEvent;
28+
import openfl.text.AntiAliasType;
29+
import openfl.text.GridFitType;
2830
import openfl.text.TextField;
2931
#if (openfl >= "9.2.0")
3032
import openfl.text.StyleSheet;
@@ -282,6 +284,43 @@ class Label extends FeathersControl implements ITextControl implements IHTMLText
282284
@:style
283285
public var embedFonts:Bool = false;
284286

287+
/**
288+
Determines the type of anti-aliasing used for embedded fonts.
289+
290+
In the following example, the label uses advanced anti-aliasing:
291+
292+
```haxe
293+
label.embedFonts = true;
294+
label.antiAliasType = ADVANCED;
295+
```
296+
297+
@see `Label.embedFonts`
298+
@see `Label.gridFitType`
299+
300+
@since 1.4.0
301+
**/
302+
@:style
303+
public var antiAliasType:AntiAliasType = NORMAL;
304+
305+
/**
306+
Determines the type of anti-aliasing used for embedded fonts.
307+
308+
In the following example, the label uses sub-pixel grid fitting:
309+
310+
```haxe
311+
label.embedFonts = true;
312+
label.antiAliasType = ADVANCED;
313+
label.gridFitType = SUBPIXEL;
314+
```
315+
316+
@see `Label.antiAliasType`
317+
@see `Label.embedFonts`
318+
319+
@since 1.4.0
320+
**/
321+
@:style
322+
public var gridFitType:GridFitType = PIXEL;
323+
285324
private var _selectable:Bool = false;
286325

287326
/**
@@ -714,6 +753,14 @@ class Label extends FeathersControl implements ITextControl implements IHTMLText
714753
this.textField.embedFonts = this.embedFonts;
715754
this._updatedTextStyles = true;
716755
}
756+
if (this.textField.antiAliasType != this.antiAliasType) {
757+
this.textField.antiAliasType = this.antiAliasType;
758+
this._updatedTextStyles = true;
759+
}
760+
if (this.textField.gridFitType != this.gridFitType) {
761+
this.textField.gridFitType = this.gridFitType;
762+
this._updatedTextStyles = true;
763+
}
717764
#if (openfl >= "9.2.0" || flash)
718765
if (this.textField.styleSheet != this.styleSheet) {
719766
this.textField.styleSheet = this.styleSheet;

src/feathers/controls/TextArea.hx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import openfl.display.InteractiveObject;
2525
import openfl.events.Event;
2626
import openfl.events.FocusEvent;
2727
import openfl.events.KeyboardEvent;
28+
import openfl.text.AntiAliasType;
29+
import openfl.text.GridFitType;
2830
import openfl.text.TextField;
2931

3032
/**
@@ -560,6 +562,43 @@ class TextArea extends BaseScrollContainer implements IStateContext<TextInputSta
560562
@:style
561563
public var embedFonts:Bool = false;
562564

565+
/**
566+
Determines the type of anti-aliasing used for embedded fonts.
567+
568+
In the following example, the text area uses advanced anti-aliasing:
569+
570+
```haxe
571+
textArea.embedFonts = true;
572+
textArea.antiAliasType = ADVANCED;
573+
```
574+
575+
@see `TextArea.embedFonts`
576+
@see `TextArea.gridFitType`
577+
578+
@since 1.4.0
579+
**/
580+
@:style
581+
public var antiAliasType:AntiAliasType = NORMAL;
582+
583+
/**
584+
Determines the type of anti-aliasing used for embedded fonts.
585+
586+
In the following example, the text area uses sub-pixel grid fitting:
587+
588+
```haxe
589+
textArea.embedFonts = true;
590+
textArea.antiAliasType = ADVANCED;
591+
textArea.gridFitType = SUBPIXEL;
592+
```
593+
594+
@see `TextArea.antiAliasType`
595+
@see `TextArea.embedFonts`
596+
597+
@since 1.4.0
598+
**/
599+
@:style
600+
public var gridFitType:GridFitType = PIXEL;
601+
563602
/**
564603
Determines if the text will wrap when reaching the right edge, or if
565604
horizontal scrolling will be required.
@@ -981,6 +1020,8 @@ class TextArea extends BaseScrollContainer implements IStateContext<TextInputSta
9811020
if (stylesInvalid) {
9821021
this.refreshTextStyles();
9831022
this.textFieldViewPort.embedFonts = this.embedFonts;
1023+
this.textFieldViewPort.antiAliasType = this.antiAliasType;
1024+
this.textFieldViewPort.gridFitType = this.gridFitType;
9841025
this.textFieldViewPort.wordWrap = this.wordWrap;
9851026
this.textFieldViewPort.paddingTop = this.textPaddingTop;
9861027
this.textFieldViewPort.paddingRight = this.textPaddingRight;
@@ -1116,6 +1157,14 @@ class TextArea extends BaseScrollContainer implements IStateContext<TextInputSta
11161157
this.promptTextField.embedFonts = this.embedFonts;
11171158
this._updatedPromptStyles = true;
11181159
}
1160+
if (this.promptTextField.antiAliasType != this.antiAliasType) {
1161+
this.promptTextField.antiAliasType = this.antiAliasType;
1162+
this._updatedPromptStyles = true;
1163+
}
1164+
if (this.promptTextField.gridFitType != this.gridFitType) {
1165+
this.promptTextField.gridFitType = this.gridFitType;
1166+
this._updatedPromptStyles = true;
1167+
}
11191168
var textFormat = this.getCurrentPromptTextFormat();
11201169
var simpleTextFormat = textFormat != null ? textFormat.toSimpleTextFormat() : null;
11211170
if (simpleTextFormat == this._previousSimplePromptTextFormat) {

0 commit comments

Comments
 (0)