Skip to content

Commit 1deafc4

Browse files
committed
fix: compute real min/max values in inspector number field including asDegrees
#565
1 parent 32df861 commit 1deafc4

File tree

1 file changed

+23
-7
lines changed
  • editor/src/editor/layout/inspector/fields

1 file changed

+23
-7
lines changed

editor/src/editor/layout/inspector/fields/number.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ export function EditorInspectorNumberField(props: IEditorInspectorNumberFieldPro
7878
return ratio.toFixed(0);
7979
}
8080

81+
function getFinalValueOf(v: number) {
82+
if (props.asDegrees) {
83+
return Tools.ToRadians(v);
84+
}
85+
86+
return v;
87+
}
88+
89+
function getMinMaxValueOf(v: number) {
90+
if (props.asDegrees) {
91+
return Tools.ToDegrees(v);
92+
}
93+
94+
return v;
95+
}
96+
8197
const hasMinMax = props.min !== undefined && props.max !== undefined;
8298
const ratio = hasMinMax ? getRatio() : 0;
8399

@@ -122,18 +138,16 @@ export function EditorInspectorNumberField(props: IEditorInspectorNumberFieldPro
122138
}
123139

124140
if (!isNaN(float)) {
125-
if (props.asDegrees) {
126-
float = Tools.ToRadians(float);
127-
}
141+
float = getFinalValueOf(float);
128142

129143
if (props.min !== undefined && float < props.min) {
130144
float = props.min;
131-
setValue(float.toFixed(digitCount));
145+
setValue(getMinMaxValueOf(props.min).toFixed(digitCount));
132146
}
133147

134148
if (props.max !== undefined && float > props.max) {
135149
float = props.max;
136-
setValue(float.toFixed(digitCount));
150+
setValue(getMinMaxValueOf(props.max).toFixed(digitCount));
137151
}
138152

139153
setInspectorEffectivePropertyValue(props.object, props.property, float);
@@ -217,11 +231,13 @@ export function EditorInspectorNumberField(props: IEditorInspectorNumberFieldPro
217231
}
218232

219233
if (props.min !== undefined && finalValue < props.min) {
220-
v = props.min;
234+
finalValue = props.min;
235+
v = getMinMaxValueOf(props.min);
221236
}
222237

223238
if (props.max !== undefined && finalValue > props.max) {
224-
v = props.max;
239+
finalValue = props.max;
240+
v = getMinMaxValueOf(props.max);
225241
}
226242

227243
setValue(v.toFixed(digitCount));

0 commit comments

Comments
 (0)