Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Zgh/fix color and editable text bugs #267

Merged
merged 4 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions com.unity.uiwidgets/Runtime/painting/colors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ internal static float _getHue(float red, float green, float blue, float max, flo
if (max == 0.0f || delta == 0.0f) {
hue = 0.0f;
}
else if (max == red) {
else if (Math.Abs(max - red) < foundation_.precisionErrorTolerance) {
hue = 60.0f * (((green - blue) / delta) % 6);
}
else if (max == green) {
else if (Math.Abs(max - green) < foundation_.precisionErrorTolerance) {
hue = 60.0f * (((blue - red) / delta) + 2);
}
else if (max == blue) {
else if (Math.Abs(max - blue) < foundation_.precisionErrorTolerance) {
hue = 60.0f * (((red - green) / delta) + 4);
}

Expand Down Expand Up @@ -92,14 +92,14 @@ public static HSVColor fromAHSV(float alpha, float hue, float saturation, float
}

public static HSVColor fromColor(Color color) {
float red = color.red / 0xFF;
float green = color.green / 0xFF;
float blue = color.blue / 0xFF;
float red = (float)color.red / 0xFF;
float green = (float)color.green / 0xFF;
float blue = (float)color.blue / 0xFF;

float max = Mathf.Max(red, Mathf.Max(green, blue));
float min = Mathf.Min(red, Mathf.Min(green, blue));
float delta = max - min;
float alpha = color.alpha / 0xFF;
float alpha = (float)color.alpha / 0xFF;
float hue = painting_._getHue(red, green, blue, max, delta);
float saturation = max == 0.0f ? 0.0f : delta / max;

Expand Down Expand Up @@ -164,18 +164,18 @@ public static HSLColor fromAHSL(float alpha, float hue, float saturation, float
}

public static HSLColor fromColor(Color color) {
float red = color.red / 0xFF;
float green = color.green / 0xFF;
float blue = color.blue / 0xFF;
float red = (float)color.red / 0xFF;
float green = (float)color.green / 0xFF;
float blue = (float)color.blue / 0xFF;

float max = Mathf.Max(red, Mathf.Max(green, blue));
float min = Mathf.Min(red, Mathf.Min(green, blue));
float delta = max - min;

float alpha = color.alpha / 0xFF;
float alpha = (float)color.alpha / 0xFF;
float hue = painting_._getHue(red, green, blue, max, delta);
float lightness = (max + min) / 2.0f;
float saturation = lightness == 1.0f
float saturation = Math.Abs(lightness - 1.0f) < foundation_.precisionErrorTolerance
? 0.0f
: ((delta / (1.0f - Mathf.Abs(2.0f * lightness - 1.0f))).clamp(0.0f, 1.0f));
return HSLColor.fromAHSL(alpha, hue, saturation, lightness);
Expand Down
16 changes: 3 additions & 13 deletions com.unity.uiwidgets/Runtime/widgets/editable_text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,13 @@ public EditableText(
paste: true,
selectAll: true
);
inputFormatters = inputFormatters ?? new List<TextInputFormatter>();
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline);
List<TextInputFormatter> formatters = new List<TextInputFormatter>();
if (inputFormatters == null) {
formatters = inputFormatters;
}

inputFormatters = maxLines == 1
? new List<TextInputFormatter>() {
BlacklistingTextInputFormatter.singleLineFormatter,
}
: inputFormatters;
this.inputFormatters = inputFormatters?? new List<TextInputFormatter>();
if (maxLines == 1) {
foreach (var formatter in formatters) {
inputFormatters.Add(formatter);
}
this.inputFormatters.Add(BlacklistingTextInputFormatter.singleLineFormatter);
}

showCursor = showCursor ?? !readOnly;

this.readOnly = readOnly;
Expand Down