|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using JetBrains.Annotations; |
|
|
|
using UIWidgets.foundation; |
|
|
|
namespace UIWidgets.ui { |
|
|
|
|
|
|
|
public enum FontStyle { |
|
|
|
namespace UIWidgets.ui |
|
|
|
{ |
|
|
|
public enum FontStyle |
|
|
|
{ |
|
|
|
/// Use the upright glyphs
|
|
|
|
normal, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public enum TextBaseline { |
|
|
|
public enum TextBaseline |
|
|
|
{ |
|
|
|
public enum TextAlign { |
|
|
|
public enum TextAlign |
|
|
|
{ |
|
|
|
/// Align the text on the left edge of the container.
|
|
|
|
left, |
|
|
|
|
|
|
|
|
|
|
justify, |
|
|
|
} |
|
|
|
|
|
|
|
public class ParagraphConstraints: IEquatable<ParagraphConstraints> |
|
|
|
public class ParagraphConstraints : IEquatable<ParagraphConstraints> |
|
|
|
|
|
|
|
|
|
|
|
public ParagraphConstraints(double width) |
|
|
|
{ |
|
|
|
this.width = width; |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class TextStyle:IEquatable<TextStyle> |
|
|
|
public class TextStyle : IEquatable<TextStyle> |
|
|
|
{ |
|
|
|
public static readonly string defaultFontFamily = "Helvetica"; |
|
|
|
public static readonly double defaultFontSize = 14.0; |
|
|
|
|
|
|
public Color color; |
|
|
|
public double? fontSize; |
|
|
|
public FontWeight? fontWeight; |
|
|
|
public FontStyle? fontStyle; |
|
|
|
public double? letterSpacing; |
|
|
|
public double? wordSpacing; |
|
|
|
public TextBaseline? textBaseline; |
|
|
|
public double? height; |
|
|
|
public TextDecoration decoration; |
|
|
|
public string fontFamily; |
|
|
|
public readonly Color color; |
|
|
|
public readonly double? fontSize; |
|
|
|
public readonly FontWeight? fontWeight; |
|
|
|
public readonly FontStyle? fontStyle; |
|
|
|
public readonly double? letterSpacing; |
|
|
|
public readonly double? wordSpacing; |
|
|
|
public readonly TextBaseline? textBaseline; |
|
|
|
public readonly double? height; |
|
|
|
public readonly TextDecoration decoration; |
|
|
|
public readonly Color decorationColor; |
|
|
|
public readonly TextDecorationStyle? decorationStyle; |
|
|
|
public readonly string fontFamily; |
|
|
|
public readonly Paint background; |
|
|
|
public FontStyle safeFontStyle |
|
|
|
public FontStyle fontStyleOrDefault |
|
|
|
public string safeFontFamily |
|
|
|
public string fontFamilyOrDefault |
|
|
|
public double safeFontSize |
|
|
|
public double fontSizeOrDefault |
|
|
|
} |
|
|
|
|
|
|
|
public Color colorOrDefault |
|
|
|
{ |
|
|
|
get { return color ?? defaultColor; } |
|
|
|
public TextDecorationStyle decorationStyleOrDefault |
|
|
|
{ |
|
|
|
get { return decorationStyle ?? TextDecorationStyle.solid; } |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public FontWeight safeFontWeight |
|
|
|
{ |
|
|
|
get { return fontWeight ?? defaultFontWeight; } |
|
|
|
|
|
|
{ |
|
|
|
get { return (color ?? defaultColor).toColor(); } |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (safeFontStyle == FontStyle.italic) |
|
|
|
if (fontStyleOrDefault == FontStyle.italic) |
|
|
|
{ |
|
|
|
if (safeFontWeight == FontWeight.w700) |
|
|
|
{ |
|
|
|
|
|
|
{ |
|
|
|
return UnityEngine.FontStyle.Italic; |
|
|
|
} |
|
|
|
} else if (safeFontWeight == FontWeight.w700) |
|
|
|
} |
|
|
|
else if (safeFontWeight == FontWeight.w700) |
|
|
|
{ |
|
|
|
return UnityEngine.FontStyle.Bold; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
public int UnityFontSize |
|
|
|
{ |
|
|
|
get { return (int) safeFontSize; } |
|
|
|
get { return (int) fontSizeOrDefault; } |
|
|
|
|
|
|
|
|
|
|
|
var ret = new TextStyle(); |
|
|
|
ret.color = style.color??color; |
|
|
|
ret.fontSize = style.fontSize??fontSize; |
|
|
|
ret.fontWeight = style.fontWeight??fontWeight; |
|
|
|
ret.fontStyle = style.fontStyle??fontStyle; |
|
|
|
ret.letterSpacing = style.letterSpacing??letterSpacing; |
|
|
|
ret.textBaseline = style.textBaseline??textBaseline; |
|
|
|
ret.height = style.height??height; |
|
|
|
ret.decoration = style.decoration??decoration; |
|
|
|
ret.fontFamily = style.fontFamily??fontFamily; |
|
|
|
var ret = new TextStyle( |
|
|
|
color: style.color ?? color, |
|
|
|
fontSize: style.fontSize ?? fontSize, |
|
|
|
fontWeight: style.fontWeight ?? fontWeight, |
|
|
|
fontStyle: style.fontStyle ?? fontStyle, |
|
|
|
letterSpacing: style.letterSpacing ?? letterSpacing, |
|
|
|
textBaseline: style.textBaseline ?? textBaseline, |
|
|
|
height: style.height ?? height, |
|
|
|
decoration: style.decoration ?? decoration, |
|
|
|
decorationColor: style.decorationColor ?? decorationColor, |
|
|
|
decorationStyle: style.decorationStyle ?? decorationStyle, |
|
|
|
background: style.background ?? background, |
|
|
|
fontFamily: style.fontFamily ?? fontFamily |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return color == other.color && fontSize == other.fontSize && fontWeight == other.fontWeight && |
|
|
|
fontStyle == other.fontStyle && letterSpacing == other.letterSpacing && |
|
|
|
wordSpacing == other.wordSpacing && textBaseline == other.textBaseline && |
|
|
|
height == other.height && decoration == other.decoration && fontFamily == other.fontFamily; |
|
|
|
return Equals(color, other.color) && fontSize.Equals(other.fontSize) && fontWeight == other.fontWeight && |
|
|
|
fontStyle == other.fontStyle && letterSpacing.Equals(other.letterSpacing) && |
|
|
|
wordSpacing.Equals(other.wordSpacing) && textBaseline == other.textBaseline && |
|
|
|
height.Equals(other.height) && Equals(decoration, other.decoration) && |
|
|
|
Equals(decorationColor, other.decorationColor) && decorationStyle == other.decorationStyle && |
|
|
|
string.Equals(fontFamily, other.fontFamily); |
|
|
|
} |
|
|
|
|
|
|
|
public override bool Equals(object obj) |
|
|
|
|
|
|
hashCode = (hashCode * 397) ^ textBaseline.GetHashCode(); |
|
|
|
hashCode = (hashCode * 397) ^ height.GetHashCode(); |
|
|
|
hashCode = (hashCode * 397) ^ (decoration != null ? decoration.GetHashCode() : 0); |
|
|
|
hashCode = (hashCode * 397) ^ (decorationColor != null ? decorationColor.GetHashCode() : 0); |
|
|
|
hashCode = (hashCode * 397) ^ decorationStyle.GetHashCode(); |
|
|
|
hashCode = (hashCode * 397) ^ (fontFamily != null ? fontFamily.GetHashCode() : 0); |
|
|
|
return hashCode; |
|
|
|
} |
|
|
|
|
|
|
return !Equals(left, right); |
|
|
|
} |
|
|
|
|
|
|
|
public TextStyle(Color color = null, double? fontSize = default(double?), FontWeight? fontWeight = default(FontWeight?), FontStyle? fontStyle = default(FontStyle?), double? letterSpacing = default(double?), double? wordSpacing = default(double?), TextBaseline? textBaseline = default(TextBaseline?), double? height = default(double?), TextDecoration decoration = null, string fontFamily = null) |
|
|
|
public TextStyle(Color color = null, double? fontSize = default(double?), |
|
|
|
FontWeight? fontWeight = default(FontWeight?), |
|
|
|
FontStyle? fontStyle = default(FontStyle?), double? letterSpacing = default(double?), |
|
|
|
double? wordSpacing = default(double?), TextBaseline? textBaseline = default(TextBaseline?), |
|
|
|
double? height = default(double?), TextDecoration decoration = null, Color decorationColor = null, |
|
|
|
TextDecorationStyle? decorationStyle = null, string fontFamily = null, Paint background = null) |
|
|
|
{ |
|
|
|
this.color = color; |
|
|
|
this.fontSize = fontSize; |
|
|
|
|
|
|
this.height = height; |
|
|
|
this.decoration = decoration; |
|
|
|
this.fontFamily = fontFamily; |
|
|
|
this.decorationStyle = decorationStyle; |
|
|
|
this.decorationColor = decorationColor; |
|
|
|
this.background = background; |
|
|
|
|
|
|
|
public class ParagraphStyle: IEquatable<ParagraphStyle> |
|
|
|
|
|
|
|
public class ParagraphStyle : IEquatable<ParagraphStyle> |
|
|
|
|
|
|
|
public ParagraphStyle(TextAlign? textAlign = null, |
|
|
|
TextDirection? textDirection = null, |
|
|
|
FontWeight? fontWeight = null, |
|
|
|
FontStyle? fontStyle = null, |
|
|
|
int? maxLines = null, |
|
|
|
double? fontSize = null, |
|
|
|
string fontFamily = null, |
|
|
|
public ParagraphStyle(TextAlign? textAlign = null, |
|
|
|
TextDirection? textDirection = null, |
|
|
|
FontWeight? fontWeight = null, |
|
|
|
FontStyle? fontStyle = null, |
|
|
|
int? maxLines = null, |
|
|
|
double? fontSize = null, |
|
|
|
string fontFamily = null, |
|
|
|
double? lineHeight = null, // todo
|
|
|
|
string ellipsis = null) |
|
|
|
{ |
|
|
|
|
|
|
{ |
|
|
|
if (ReferenceEquals(null, other)) return false; |
|
|
|
if (ReferenceEquals(this, other)) return true; |
|
|
|
return textAlign == other.textAlign && textDirection == other.textDirection && fontWeight == other.fontWeight && fontStyle == other.fontStyle && maxLines == other.maxLines && fontSize.Equals(other.fontSize) && string.Equals(fontFamily, other.fontFamily) && lineHeight.Equals(other.lineHeight) && string.Equals(ellipsis, other.ellipsis); |
|
|
|
return textAlign == other.textAlign && textDirection == other.textDirection && |
|
|
|
fontWeight == other.fontWeight && fontStyle == other.fontStyle && maxLines == other.maxLines && |
|
|
|
fontSize.Equals(other.fontSize) && string.Equals(fontFamily, other.fontFamily) && |
|
|
|
lineHeight.Equals(other.lineHeight) && string.Equals(ellipsis, other.ellipsis); |
|
|
|
} |
|
|
|
|
|
|
|
public override bool Equals(object obj) |
|
|
|
|
|
|
if (obj.GetType() != this.GetType()) return false; |
|
|
|
return Equals((ParagraphStyle) obj); |
|
|
|
} |
|
|
|
|
|
|
|
public static bool operator ==(ParagraphStyle a, ParagraphStyle b) { |
|
|
|
|
|
|
|
public static bool operator ==(ParagraphStyle a, ParagraphStyle b) |
|
|
|
{ |
|
|
|
public static bool operator !=(ParagraphStyle a, ParagraphStyle b) { |
|
|
|
public static bool operator !=(ParagraphStyle a, ParagraphStyle b) |
|
|
|
{ |
|
|
|
return !(a == b); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
fontFamily: fontFamily, |
|
|
|
fontSize: fontSize, |
|
|
|
height: lineHeight |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public TextAlign TextAlign |
|
|
|
|
|
|
public readonly double? lineHeight; |
|
|
|
public readonly string ellipsis; |
|
|
|
} |
|
|
|
|
|
|
|
public class TextDecoration: IEquatable<TextDecoration> |
|
|
|
|
|
|
|
public enum TextDecorationStyle |
|
|
|
{ |
|
|
|
solid, |
|
|
|
doubleLine, |
|
|
|
} |
|
|
|
|
|
|
|
public class TextDecoration : IEquatable<TextDecoration> |
|
|
|
{ |
|
|
|
public bool Equals(TextDecoration other) |
|
|
|
{ |
|
|
|
|
|
|
{ |
|
|
|
return mask; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static bool operator ==(TextDecoration a, TextDecoration b) { |
|
|
|
|
|
|
|
|
|
|
|
public static bool operator ==(TextDecoration a, TextDecoration b) |
|
|
|
{ |
|
|
|
public static bool operator !=(TextDecoration a, TextDecoration b) { |
|
|
|
public static bool operator !=(TextDecoration a, TextDecoration b) |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public readonly int mask; |
|
|
|
|
|
|
|
public TextDecoration(int mask) |
|
|
|
|
|
|
|
|
|
|
bool contains(TextDecoration other) { |
|
|
|
|
|
|
|
public bool contains(TextDecoration other) |
|
|
|
{ |
|
|
|
|
|
|
|
public enum TextDirection { |
|
|
|
|
|
|
|
public enum TextDirection |
|
|
|
{ |
|
|
|
|
|
|
|
public enum TextAffinity { |
|
|
|
|
|
|
|
public enum TextAffinity |
|
|
|
{ |
|
|
|
upstream, |
|
|
|
downstream, |
|
|
|
} |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class TextBox: IEquatable<TextBox> |
|
|
|
public class TextBox : IEquatable<TextBox> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public readonly double bottom; |
|
|
|
|
|
|
|
public readonly TextDirection direction; |
|
|
|
|
|
|
this.bottom = bottom; |
|
|
|
this.direction = direction; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static TextBox fromLTBD(double left, double top, double right, double bottom, TextDirection direction) |
|
|
|
{ |
|
|
|
return new TextBox(left, top, right, bottom, direction); |
|
|
|
|
|
|
{ |
|
|
|
get { return direction == TextDirection.ltr ? left : right; } |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public double end |
|
|
|
{ |
|
|
|
get { return direction == TextDirection.ltr ? right : left; } |
|
|
|
|
|
|
{ |
|
|
|
if (ReferenceEquals(null, other)) return false; |
|
|
|
if (ReferenceEquals(this, other)) return true; |
|
|
|
return left.Equals(other.left) && top.Equals(other.top) && right.Equals(other.right) && bottom.Equals(other.bottom) && direction == other.direction; |
|
|
|
return left.Equals(other.left) && top.Equals(other.top) && right.Equals(other.right) && |
|
|
|
bottom.Equals(other.bottom) && direction == other.direction; |
|
|
|
} |
|
|
|
|
|
|
|
public override bool Equals(object obj) |
|
|
|
|
|
|
|
|
|
|
public override string ToString() |
|
|
|
{ |
|
|
|
return string.Format("Left: {0}, Top: {1}, Right: {2}, Bottom: {3}, Direction: {4}", left, top, right, bottom, direction); |
|
|
|
return string.Format("Left: {0}, Top: {1}, Right: {2}, Bottom: {3}, Direction: {4}", left, top, right, |
|
|
|
bottom, direction); |
|
|
|
} |
|
|
|
|
|
|
|
public override int GetHashCode() |
|
|
|