Skip to content

Commit

Permalink
Text Controls: added antiAliasType and gridFitType to pass to interna…
Browse files Browse the repository at this point in the history
…l TextField (closes #180)
  • Loading branch information
joshtynjala committed Jan 22, 2025
1 parent 6021a07 commit 311f7ed
Show file tree
Hide file tree
Showing 10 changed files with 460 additions and 4 deletions.
49 changes: 48 additions & 1 deletion src/feathers/controls/Button.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

package feathers.controls;

import feathers.layout.ILayoutObject;
import feathers.core.IFocusObject;
import feathers.core.IHTMLTextControl;
import feathers.core.IMeasureObject;
Expand All @@ -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;
Expand All @@ -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")
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
49 changes: 48 additions & 1 deletion src/feathers/controls/FormItem.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

package feathers.controls;

import feathers.events.FeathersEvent;
import feathers.core.FeathersControl;
import feathers.core.IFocusManagerAware;
import feathers.core.IFocusObject;
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
47 changes: 47 additions & 0 deletions src/feathers/controls/Header.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
47 changes: 47 additions & 0 deletions src/feathers/controls/Label.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
Expand Down
49 changes: 49 additions & 0 deletions src/feathers/controls/TextArea.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -560,6 +562,43 @@ class TextArea extends BaseScrollContainer implements IStateContext<TextInputSta
@:style
public var embedFonts:Bool = false;

/**
Determines the type of anti-aliasing used for embedded fonts.
In the following example, the text area uses advanced anti-aliasing:
```haxe
textArea.embedFonts = true;
textArea.antiAliasType = ADVANCED;
```
@see `TextArea.embedFonts`
@see `TextArea.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 area uses sub-pixel grid fitting:
```haxe
textArea.embedFonts = true;
textArea.antiAliasType = ADVANCED;
textArea.gridFitType = SUBPIXEL;
```
@see `TextArea.antiAliasType`
@see `TextArea.embedFonts`
@since 1.4.0
**/
@:style
public var gridFitType:GridFitType = PIXEL;

/**
Determines if the text will wrap when reaching the right edge, or if
horizontal scrolling will be required.
Expand Down Expand Up @@ -981,6 +1020,8 @@ class TextArea extends BaseScrollContainer implements IStateContext<TextInputSta
if (stylesInvalid) {
this.refreshTextStyles();
this.textFieldViewPort.embedFonts = this.embedFonts;
this.textFieldViewPort.antiAliasType = this.antiAliasType;
this.textFieldViewPort.gridFitType = this.gridFitType;
this.textFieldViewPort.wordWrap = this.wordWrap;
this.textFieldViewPort.paddingTop = this.textPaddingTop;
this.textFieldViewPort.paddingRight = this.textPaddingRight;
Expand Down Expand Up @@ -1116,6 +1157,14 @@ class TextArea extends BaseScrollContainer implements IStateContext<TextInputSta
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._previousSimplePromptTextFormat) {
Expand Down
Loading

0 comments on commit 311f7ed

Please sign in to comment.