From 311f7ed8bf798425aa2a588472d52b272e73e40f Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Wed, 22 Jan 2025 15:54:21 -0800 Subject: [PATCH] Text Controls: added antiAliasType and gridFitType to pass to internal TextField (closes #180) --- src/feathers/controls/Button.hx | 49 +++++++++++++++- src/feathers/controls/FormItem.hx | 49 +++++++++++++++- src/feathers/controls/Header.hx | 47 ++++++++++++++++ src/feathers/controls/Label.hx | 47 ++++++++++++++++ src/feathers/controls/TextArea.hx | 49 ++++++++++++++++ src/feathers/controls/TextInput.hx | 55 ++++++++++++++++++ src/feathers/controls/ToggleButton.hx | 49 +++++++++++++++- src/feathers/controls/ToggleSwitch.hx | 56 ++++++++++++++++++- .../controls/dataRenderers/ItemRenderer.hx | 8 +++ .../supportClasses/TextFieldViewPort.hx | 55 ++++++++++++++++++ 10 files changed, 460 insertions(+), 4 deletions(-) diff --git a/src/feathers/controls/Button.hx b/src/feathers/controls/Button.hx index 6ec95a1d..5b9dcb93 100644 --- a/src/feathers/controls/Button.hx +++ b/src/feathers/controls/Button.hx @@ -8,7 +8,6 @@ package feathers.controls; -import feathers.layout.ILayoutObject; import feathers.core.IFocusObject; import feathers.core.IHTMLTextControl; import feathers.core.IMeasureObject; @@ -18,6 +17,7 @@ import feathers.core.IUIControl; import feathers.core.IValidating; import feathers.events.TriggerEvent; import feathers.layout.HorizontalAlign; +import feathers.layout.ILayoutObject; import feathers.layout.Measurements; import feathers.layout.RelativePosition; import feathers.layout.VerticalAlign; @@ -29,6 +29,8 @@ import openfl.events.Event; import openfl.events.FocusEvent; import openfl.events.KeyboardEvent; import openfl.events.MouseEvent; +import openfl.text.AntiAliasType; +import openfl.text.GridFitType; import openfl.text.TextField; import openfl.ui.Keyboard; #if (openfl >= "9.2.0") @@ -324,6 +326,43 @@ class Button extends BasicButton implements ITextControl implements IHTMLTextCon @:style public var embedFonts:Bool = false; + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the button uses advanced anti-aliasing: + + ```haxe + button.embedFonts = true; + button.antiAliasType = ADVANCED; + ``` + + @see `Button.embedFonts` + @see `Button.gridFitType` + + @since 1.4.0 + **/ + @:style + public var antiAliasType:AntiAliasType = NORMAL; + + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the button uses sub-pixel grid fitting: + + ```haxe + button.embedFonts = true; + button.antiAliasType = ADVANCED; + button.gridFitType = SUBPIXEL; + ``` + + @see `Button.antiAliasType` + @see `Button.embedFonts` + + @since 1.4.0 + **/ + @:style + public var gridFitType:GridFitType = PIXEL; + /** Determines if the text is displayed on a single line, or if it wraps. @@ -1055,6 +1094,14 @@ class Button extends BasicButton implements ITextControl implements IHTMLTextCon this.textField.embedFonts = this.embedFonts; this._updatedTextStyles = true; } + if (this.textField.antiAliasType != this.antiAliasType) { + this.textField.antiAliasType = this.antiAliasType; + this._updatedTextStyles = true; + } + if (this.textField.gridFitType != this.gridFitType) { + this.textField.gridFitType = this.gridFitType; + this._updatedTextStyles = true; + } #if (openfl >= "9.2.0" || flash) if (this.textField.styleSheet != this.styleSheet) { this.textField.styleSheet = this.styleSheet; diff --git a/src/feathers/controls/FormItem.hx b/src/feathers/controls/FormItem.hx index 605838cb..09d49d81 100644 --- a/src/feathers/controls/FormItem.hx +++ b/src/feathers/controls/FormItem.hx @@ -8,7 +8,6 @@ package feathers.controls; -import feathers.events.FeathersEvent; import feathers.core.FeathersControl; import feathers.core.IFocusManagerAware; import feathers.core.IFocusObject; @@ -16,6 +15,7 @@ import feathers.core.IMeasureObject; import feathers.core.ITextControl; import feathers.core.IUIControl; import feathers.core.IValidating; +import feathers.events.FeathersEvent; import feathers.layout.HorizontalAlign; import feathers.layout.Measurements; import feathers.layout.RelativePosition; @@ -27,6 +27,8 @@ import openfl.display.DisplayObject; import openfl.errors.ArgumentError; import openfl.events.Event; import openfl.events.MouseEvent; +import openfl.text.AntiAliasType; +import openfl.text.GridFitType; import openfl.text.TextField; #if (openfl >= "9.2.0") import openfl.text.StyleSheet; @@ -421,6 +423,43 @@ class FormItem extends FeathersControl implements ITextControl implements IFocus @:style public var embedFonts:Bool = false; + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the form item uses advanced anti-aliasing: + + ```haxe + formItem.embedFonts = true; + formItem.antiAliasType = ADVANCED; + ``` + + @see `FormItem.embedFonts` + @see `FormItem.gridFitType` + + @since 1.4.0 + **/ + @:style + public var antiAliasType:AntiAliasType = NORMAL; + + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the form item uses sub-pixel grid fitting: + + ```haxe + formItem.embedFonts = true; + formItem.antiAliasType = ADVANCED; + formItem.gridFitType = SUBPIXEL; + ``` + + @see `FormItem.antiAliasType` + @see `FormItem.embedFonts` + + @since 1.4.0 + **/ + @:style + public var gridFitType:GridFitType = PIXEL; + /** The minimum space, in pixels, between the form item's top edge and the form item's content. @@ -985,6 +1024,14 @@ class FormItem extends FeathersControl implements ITextControl implements IFocus this.textField.embedFonts = this.embedFonts; this._updatedTextStyles = true; } + if (this.textField.antiAliasType != this.antiAliasType) { + this.textField.antiAliasType = this.antiAliasType; + this._updatedTextStyles = true; + } + if (this.textField.gridFitType != this.gridFitType) { + this.textField.gridFitType = this.gridFitType; + this._updatedTextStyles = true; + } #if (openfl >= "9.2.0" || flash) if (this.textField.styleSheet != this.styleSheet) { this.textField.styleSheet = this.styleSheet; diff --git a/src/feathers/controls/Header.hx b/src/feathers/controls/Header.hx index 5c8e2f63..3c23b9f4 100644 --- a/src/feathers/controls/Header.hx +++ b/src/feathers/controls/Header.hx @@ -20,6 +20,8 @@ import feathers.text.TextFormat; import feathers.utils.MeasurementsUtil; import openfl.display.DisplayObject; import openfl.events.Event; +import openfl.text.AntiAliasType; +import openfl.text.GridFitType; import openfl.text.TextField; #if (openfl >= "9.2.0") import openfl.text.StyleSheet; @@ -222,6 +224,43 @@ class Header extends FeathersControl implements ITextControl { @:style public var embedFonts:Bool = false; + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the header uses advanced anti-aliasing: + + ```haxe + header.embedFonts = true; + header.antiAliasType = ADVANCED; + ``` + + @see `Header.embedFonts` + @see `Header.gridFitType` + + @since 1.4.0 + **/ + @:style + public var antiAliasType:AntiAliasType = NORMAL; + + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the header uses sub-pixel grid fitting: + + ```haxe + header.embedFonts = true; + header.antiAliasType = ADVANCED; + header.gridFitType = SUBPIXEL; + ``` + + @see `Header.antiAliasType` + @see `Header.embedFonts` + + @since 1.4.0 + **/ + @:style + public var gridFitType:GridFitType = PIXEL; + /** The font styles used to render the header's text when the header is disabled. @@ -660,6 +699,14 @@ class Header extends FeathersControl implements ITextControl { this.textField.embedFonts = this.embedFonts; this._updatedTextStyles = true; } + if (this.textField.antiAliasType != this.antiAliasType) { + this.textField.antiAliasType = this.antiAliasType; + this._updatedTextStyles = true; + } + if (this.textField.gridFitType != this.gridFitType) { + this.textField.gridFitType = this.gridFitType; + this._updatedTextStyles = true; + } #if (openfl >= "9.2.0" || flash) if (this.textField.styleSheet != this.styleSheet) { this.textField.styleSheet = this.styleSheet; diff --git a/src/feathers/controls/Label.hx b/src/feathers/controls/Label.hx index aa1d39a6..5622282a 100644 --- a/src/feathers/controls/Label.hx +++ b/src/feathers/controls/Label.hx @@ -25,6 +25,8 @@ import openfl.display.DisplayObject; import openfl.display.InteractiveObject; import openfl.events.Event; import openfl.events.FocusEvent; +import openfl.text.AntiAliasType; +import openfl.text.GridFitType; import openfl.text.TextField; #if (openfl >= "9.2.0") import openfl.text.StyleSheet; @@ -282,6 +284,43 @@ class Label extends FeathersControl implements ITextControl implements IHTMLText @:style public var embedFonts:Bool = false; + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the label uses advanced anti-aliasing: + + ```haxe + label.embedFonts = true; + label.antiAliasType = ADVANCED; + ``` + + @see `Label.embedFonts` + @see `Label.gridFitType` + + @since 1.4.0 + **/ + @:style + public var antiAliasType:AntiAliasType = NORMAL; + + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the label uses sub-pixel grid fitting: + + ```haxe + label.embedFonts = true; + label.antiAliasType = ADVANCED; + label.gridFitType = SUBPIXEL; + ``` + + @see `Label.antiAliasType` + @see `Label.embedFonts` + + @since 1.4.0 + **/ + @:style + public var gridFitType:GridFitType = PIXEL; + private var _selectable:Bool = false; /** @@ -714,6 +753,14 @@ class Label extends FeathersControl implements ITextControl implements IHTMLText this.textField.embedFonts = this.embedFonts; this._updatedTextStyles = true; } + if (this.textField.antiAliasType != this.antiAliasType) { + this.textField.antiAliasType = this.antiAliasType; + this._updatedTextStyles = true; + } + if (this.textField.gridFitType != this.gridFitType) { + this.textField.gridFitType = this.gridFitType; + this._updatedTextStyles = true; + } #if (openfl >= "9.2.0" || flash) if (this.textField.styleSheet != this.styleSheet) { this.textField.styleSheet = this.styleSheet; diff --git a/src/feathers/controls/TextArea.hx b/src/feathers/controls/TextArea.hx index c94da1e0..1332b4ca 100644 --- a/src/feathers/controls/TextArea.hx +++ b/src/feathers/controls/TextArea.hx @@ -25,6 +25,8 @@ import openfl.display.InteractiveObject; import openfl.events.Event; import openfl.events.FocusEvent; import openfl.events.KeyboardEvent; +import openfl.text.AntiAliasType; +import openfl.text.GridFitType; import openfl.text.TextField; /** @@ -560,6 +562,43 @@ class TextArea extends BaseScrollContainer implements IStateContext @:style public var embedFonts:Bool = false; + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the text input uses advanced anti-aliasing: + + ```haxe + textInput.embedFonts = true; + textInput.antiAliasType = ADVANCED; + ``` + + @see `TextInput.embedFonts` + @see `TextInput.gridFitType` + + @since 1.4.0 + **/ + @:style + public var antiAliasType:AntiAliasType = NORMAL; + + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the text input uses sub-pixel grid fitting: + + ```haxe + textInput.embedFonts = true; + textInput.antiAliasType = ADVANCED; + textInput.gridFitType = SUBPIXEL; + ``` + + @see `TextInput.antiAliasType` + @see `TextInput.embedFonts` + + @since 1.4.0 + **/ + @:style + public var gridFitType:GridFitType = PIXEL; + private var _stateToTextFormat:Map = new Map(); /** @@ -1596,6 +1635,14 @@ class TextInput extends FeathersControl implements IStateContext this.textField.embedFonts = this.embedFonts; this._updatedTextStyles = true; } + if (this.textField.antiAliasType != this.antiAliasType) { + this.textField.antiAliasType = this.antiAliasType; + this._updatedTextStyles = true; + } + if (this.textField.gridFitType != this.gridFitType) { + this.textField.gridFitType = this.gridFitType; + this._updatedTextStyles = true; + } if (this.textField.displayAsPassword != this._displayAsPassword) { this.textField.displayAsPassword = this._displayAsPassword; this._updatedTextStyles = true; @@ -1668,6 +1715,14 @@ class TextInput extends FeathersControl implements IStateContext this.promptTextField.embedFonts = this.embedFonts; this._updatedPromptStyles = true; } + if (this.promptTextField.antiAliasType != this.antiAliasType) { + this.promptTextField.antiAliasType = this.antiAliasType; + this._updatedPromptStyles = true; + } + if (this.promptTextField.gridFitType != this.gridFitType) { + this.promptTextField.gridFitType = this.gridFitType; + this._updatedPromptStyles = true; + } var textFormat = this.getCurrentPromptTextFormat(); var simpleTextFormat = textFormat != null ? textFormat.toSimpleTextFormat() : null; if (simpleTextFormat == this._previousPromptSimpleTextFormat) { diff --git a/src/feathers/controls/ToggleButton.hx b/src/feathers/controls/ToggleButton.hx index df0e1d6c..944ead37 100644 --- a/src/feathers/controls/ToggleButton.hx +++ b/src/feathers/controls/ToggleButton.hx @@ -8,7 +8,6 @@ package feathers.controls; -import feathers.layout.ILayoutObject; import feathers.core.IFocusObject; import feathers.core.IHTMLTextControl; import feathers.core.IMeasureObject; @@ -17,6 +16,7 @@ import feathers.core.ITextControl; import feathers.core.IUIControl; import feathers.core.IValidating; import feathers.layout.HorizontalAlign; +import feathers.layout.ILayoutObject; import feathers.layout.Measurements; import feathers.layout.RelativePosition; import feathers.layout.VerticalAlign; @@ -28,6 +28,8 @@ import openfl.events.Event; import openfl.events.FocusEvent; import openfl.events.KeyboardEvent; import openfl.events.MouseEvent; +import openfl.text.AntiAliasType; +import openfl.text.GridFitType; import openfl.text.TextField; import openfl.ui.Keyboard; #if (openfl >= "9.2.0") @@ -367,6 +369,43 @@ class ToggleButton extends BasicToggleButton implements ITextControl implements @:style public var embedFonts:Bool = false; + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the button uses advanced anti-aliasing: + + ```haxe + button.embedFonts = true; + button.antiAliasType = ADVANCED; + ``` + + @see `ToggleButton.embedFonts` + @see `ToggleButton.gridFitType` + + @since 1.4.0 + **/ + @:style + public var antiAliasType:AntiAliasType = NORMAL; + + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the button uses sub-pixel grid fitting: + + ```haxe + button.embedFonts = true; + button.antiAliasType = ADVANCED; + button.gridFitType = SUBPIXEL; + ``` + + @see `ToggleButton.antiAliasType` + @see `ToggleButton.embedFonts` + + @since 1.4.0 + **/ + @:style + public var gridFitType:GridFitType = PIXEL; + /** Determines if the text is displayed on a single line, or if it wraps. @@ -1134,6 +1173,14 @@ class ToggleButton extends BasicToggleButton implements ITextControl implements this.textField.embedFonts = this.embedFonts; this._updatedTextStyles = true; } + if (this.textField.antiAliasType != this.antiAliasType) { + this.textField.antiAliasType = this.antiAliasType; + this._updatedTextStyles = true; + } + if (this.textField.gridFitType != this.gridFitType) { + this.textField.gridFitType = this.gridFitType; + this._updatedTextStyles = true; + } #if (openfl >= "9.2.0" || flash) if (this.textField.styleSheet != this.styleSheet) { this.textField.styleSheet = this.styleSheet; diff --git a/src/feathers/controls/ToggleSwitch.hx b/src/feathers/controls/ToggleSwitch.hx index 734406d2..984e8daa 100644 --- a/src/feathers/controls/ToggleSwitch.hx +++ b/src/feathers/controls/ToggleSwitch.hx @@ -15,7 +15,6 @@ import feathers.core.IValidating; import feathers.events.FeathersEvent; import feathers.layout.Measurements; import feathers.skins.IProgrammaticSkin; -import feathers.text.TextFormat.AbstractTextFormat; import feathers.text.TextFormat; import feathers.utils.ExclusivePointer; import motion.Actuate; @@ -28,6 +27,8 @@ import openfl.events.Event; import openfl.events.KeyboardEvent; import openfl.events.MouseEvent; import openfl.events.TouchEvent; +import openfl.text.AntiAliasType; +import openfl.text.GridFitType; import openfl.text.TextField; import openfl.ui.Keyboard; #if air @@ -278,6 +279,43 @@ class ToggleSwitch extends FeathersControl implements IToggle implements IFocusO @:style public var embedFonts:Bool = false; + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the toggle switch uses advanced anti-aliasing: + + ```haxe + toggleSwitch.embedFonts = true; + toggleSwitch.antiAliasType = ADVANCED; + ``` + + @see `ToggleSwitch.embedFonts` + @see `ToggleSwitch.gridFitType` + + @since 1.4.0 + **/ + @:style + public var antiAliasType:AntiAliasType = NORMAL; + + /** + Determines the type of anti-aliasing used for embedded fonts. + + In the following example, the toggle switch uses sub-pixel grid fitting: + + ```haxe + toggleSwitch.embedFonts = true; + toggleSwitch.antiAliasType = ADVANCED; + toggleSwitch.gridFitType = SUBPIXEL; + ``` + + @see `ToggleSwitch.antiAliasType` + @see `ToggleSwitch.embedFonts` + + @since 1.4.0 + **/ + @:style + public var gridFitType:GridFitType = PIXEL; + private var _currentThumbSkin:DisplayObject = null; private var _thumbSkinMeasurements:Measurements = null; @@ -636,6 +674,14 @@ class ToggleSwitch extends FeathersControl implements IToggle implements IFocusO this.offTextField.embedFonts = this.embedFonts; this._updatedOffTextStyles = true; } + if (this.offTextField.antiAliasType != this.antiAliasType) { + this.offTextField.antiAliasType = this.antiAliasType; + this._updatedOffTextStyles = true; + } + if (this.offTextField.gridFitType != this.gridFitType) { + this.offTextField.gridFitType = this.gridFitType; + this._updatedOffTextStyles = true; + } if (simpleTextFormat != this._previousOffSimpleTextFormat) { if (this._previousOffTextFormat != null) { this._previousOffTextFormat.removeEventListener(Event.CHANGE, toggleSwitch_offTextFormat_changeHandler); @@ -660,6 +706,14 @@ class ToggleSwitch extends FeathersControl implements IToggle implements IFocusO this.onTextField.embedFonts = this.embedFonts; this._updatedOnTextStyles = true; } + if (this.onTextField.antiAliasType != this.antiAliasType) { + this.onTextField.antiAliasType = this.antiAliasType; + this._updatedOnTextStyles = true; + } + if (this.onTextField.gridFitType != this.gridFitType) { + this.onTextField.gridFitType = this.gridFitType; + this._updatedOnTextStyles = true; + } if (simpleTextFormat != this._previousOnSimpleTextFormat) { if (this._previousOnTextFormat != null) { this._previousOnTextFormat.removeEventListener(Event.CHANGE, toggleSwitch_onTextFormat_changeHandler); diff --git a/src/feathers/controls/dataRenderers/ItemRenderer.hx b/src/feathers/controls/dataRenderers/ItemRenderer.hx index 4f893efc..d8c596ba 100644 --- a/src/feathers/controls/dataRenderers/ItemRenderer.hx +++ b/src/feathers/controls/dataRenderers/ItemRenderer.hx @@ -527,6 +527,14 @@ class ItemRenderer extends ToggleButton implements IFocusContainer implements IL this.secondaryTextField.embedFonts = this.embedFonts; this._updatedSecondaryTextStyles = true; } + if (this.secondaryTextField.antiAliasType != this.antiAliasType) { + this.secondaryTextField.antiAliasType = this.antiAliasType; + this._updatedSecondaryTextStyles = true; + } + if (this.secondaryTextField.gridFitType != this.gridFitType) { + this.secondaryTextField.gridFitType = this.gridFitType; + this._updatedSecondaryTextStyles = true; + } var textFormat = this.getCurrentSecondaryTextFormat(); var simpleTextFormat = textFormat != null ? textFormat.toSimpleTextFormat() : null; if (simpleTextFormat == this._previousSecondarySimpleTextFormat) { diff --git a/src/feathers/controls/supportClasses/TextFieldViewPort.hx b/src/feathers/controls/supportClasses/TextFieldViewPort.hx index d8aa902f..350ff2af 100644 --- a/src/feathers/controls/supportClasses/TextFieldViewPort.hx +++ b/src/feathers/controls/supportClasses/TextFieldViewPort.hx @@ -17,6 +17,8 @@ import openfl.display.InteractiveObject; import openfl.errors.ArgumentError; import openfl.events.Event; import openfl.events.FocusEvent; +import openfl.text.AntiAliasType; +import openfl.text.GridFitType; import openfl.text.TextField; import openfl.text.TextFieldType; import openfl.text.TextFormat; @@ -336,6 +338,51 @@ class TextFieldViewPort extends FeathersControl implements IViewPort implements return this._embedFonts; } + private var _antiAliasType:AntiAliasType = NORMAL; + + /** + Determines the anti-aliasing type used for embedded fonts. + + @since 1.4.0 + **/ + public var antiAliasType(get, set):AntiAliasType; + + private function get_antiAliasType():AntiAliasType { + return this._antiAliasType; + } + + private function set_antiAliasType(value:AntiAliasType):AntiAliasType { + if (this._antiAliasType == value) { + return this._antiAliasType; + } + this._antiAliasType = value; + this.setInvalid(STYLES); + return this._antiAliasType; + } + + private var _gridFitType:GridFitType = PIXEL; + + /** + Determines the grid fitting used for embedded fonts with advanced + anti-aliasing. + + @since 1.4.0 + **/ + public var gridFitType(get, set):GridFitType; + + private function get_gridFitType():GridFitType { + return this._gridFitType; + } + + private function set_gridFitType(value:GridFitType):GridFitType { + if (this._gridFitType == value) { + return this._gridFitType; + } + this._gridFitType = value; + this.setInvalid(STYLES); + return this._gridFitType; + } + private var _paddingTop:Float = 0.0; /** @@ -848,6 +895,14 @@ class TextFieldViewPort extends FeathersControl implements IViewPort implements this._textField.embedFonts = this._embedFonts; this._updatedTextStyles = true; } + if (this._textField.antiAliasType != this._antiAliasType) { + this._textField.antiAliasType = this._antiAliasType; + this._updatedTextStyles = true; + } + if (this._textField.gridFitType != this._gridFitType) { + this._textField.gridFitType = this._gridFitType; + this._updatedTextStyles = true; + } if (this._textFormat != this._previousTextFormat) { this._textField.defaultTextFormat = this._textFormat; this._updatedTextStyles = true;