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

Commit 037b258

Browse files
authored
Merge pull request #267 from Unity-Technologies/zgh/fix_color_and_editable_text_bugs
Zgh/fix color and editable text bugs
2 parents a4c30c3 + 8b0bb0c commit 037b258

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

com.unity.uiwidgets/Runtime/foundation/diagnostics.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,8 @@ public static bool _isSingleLine(DiagnosticsTreeStyle? style) {
627627
return style == DiagnosticsTreeStyle.singleLine;
628628
}
629629

630-
public static bool FloatEqual(float left, float right) {
631-
return Mathf.Abs(left - right) < precisionErrorTolerance;
630+
public static bool FloatEqual(float left, float right, float precisionTolerance = precisionErrorTolerance) {
631+
return Mathf.Abs(left - right) < precisionTolerance;
632632
}
633633
}
634634

com.unity.uiwidgets/Runtime/painting/colors.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ internal static float _getHue(float red, float green, float blue, float max, flo
1212
if (max == 0.0f || delta == 0.0f) {
1313
hue = 0.0f;
1414
}
15-
else if (max == red) {
15+
else if (foundation_.FloatEqual(max,red)) {
1616
hue = 60.0f * (((green - blue) / delta) % 6);
1717
}
18-
else if (max == green) {
18+
else if (foundation_.FloatEqual(max,green)) {
1919
hue = 60.0f * (((blue - red) / delta) + 2);
2020
}
21-
else if (max == blue) {
21+
else if (foundation_.FloatEqual(max,blue)) {
2222
hue = 60.0f * (((red - green) / delta) + 4);
2323
}
2424

@@ -92,14 +92,14 @@ public static HSVColor fromAHSV(float alpha, float hue, float saturation, float
9292
}
9393

9494
public static HSVColor fromColor(Color color) {
95-
float red = color.red / 0xFF;
96-
float green = color.green / 0xFF;
97-
float blue = color.blue / 0xFF;
95+
float red = (float)color.red / 0xFF;
96+
float green = (float)color.green / 0xFF;
97+
float blue = (float)color.blue / 0xFF;
9898

9999
float max = Mathf.Max(red, Mathf.Max(green, blue));
100100
float min = Mathf.Min(red, Mathf.Min(green, blue));
101101
float delta = max - min;
102-
float alpha = color.alpha / 0xFF;
102+
float alpha = (float)color.alpha / 0xFF;
103103
float hue = painting_._getHue(red, green, blue, max, delta);
104104
float saturation = max == 0.0f ? 0.0f : delta / max;
105105

@@ -164,18 +164,18 @@ public static HSLColor fromAHSL(float alpha, float hue, float saturation, float
164164
}
165165

166166
public static HSLColor fromColor(Color color) {
167-
float red = color.red / 0xFF;
168-
float green = color.green / 0xFF;
169-
float blue = color.blue / 0xFF;
167+
float red = (float)color.red / 0xFF;
168+
float green = (float)color.green / 0xFF;
169+
float blue = (float)color.blue / 0xFF;
170170

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

175-
float alpha = color.alpha / 0xFF;
175+
float alpha = (float)color.alpha / 0xFF;
176176
float hue = painting_._getHue(red, green, blue, max, delta);
177177
float lightness = (max + min) / 2.0f;
178-
float saturation = lightness == 1.0f
178+
float saturation = foundation_.FloatEqual(lightness, 1.0f)
179179
? 0.0f
180180
: ((delta / (1.0f - Mathf.Abs(2.0f * lightness - 1.0f))).clamp(0.0f, 1.0f));
181181
return HSLColor.fromAHSL(alpha, hue, saturation, lightness);

com.unity.uiwidgets/Runtime/widgets/editable_text.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,23 +191,13 @@ public EditableText(
191191
paste: true,
192192
selectAll: true
193193
);
194-
inputFormatters = inputFormatters ?? new List<TextInputFormatter>();
195194
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline);
196-
List<TextInputFormatter> formatters = new List<TextInputFormatter>();
197-
if (inputFormatters == null) {
198-
formatters = inputFormatters;
199-
}
200195

201-
inputFormatters = maxLines == 1
202-
? new List<TextInputFormatter>() {
203-
BlacklistingTextInputFormatter.singleLineFormatter,
204-
}
205-
: inputFormatters;
196+
this.inputFormatters = inputFormatters?? new List<TextInputFormatter>();
206197
if (maxLines == 1) {
207-
foreach (var formatter in formatters) {
208-
inputFormatters.Add(formatter);
209-
}
198+
this.inputFormatters.Add(BlacklistingTextInputFormatter.singleLineFormatter);
210199
}
200+
211201
showCursor = showCursor ?? !readOnly;
212202

213203
this.readOnly = readOnly;

0 commit comments

Comments
 (0)