Skip to content

Commit

Permalink
Use draggable fields for float scalable settings (#2227)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-de-tocqueville authored and sebastienlagarde committed Oct 25, 2020
1 parent ebdc18c commit 79fb235
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed cullmode for SceneSelectionPass.
- Fixed issue that caused non-static object to not render at times in OnEnable reflection probes.
- Baked reflection probes now correctly use static sky for ambient lighting.
- Use draggable fields for float scalable settings

### Changed
- Preparation pass for RTSSShadows to be supported by render graph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ static void MultiField<T>(Rect position, GUIContent[] subLabels, T[] values)
var indentLevel = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;

// Save labelWidth
float labelWidth = EditorGUIUtility.labelWidth;

// Variable to keep track of the current pixel shift in the rectangle we were assigned for this whole section.
float pixelShift = 0;

Expand All @@ -155,39 +158,27 @@ static void MultiField<T>(Rect position, GUIContent[] subLabels, T[] values)
{
// Let's first compute what is the width of the label of this scalable setting level
// We make sure that the label doesn't go beyond the space available for this scalable setting level
var labelWidth = Mathf.Clamp(CalcPrefixLabelWidth(subLabels[index], (GUIStyle)null), 0, num);

// Draw the Label at the expected position
EditorGUI.LabelField(new Rect(position.x + pixelShift, position.y, labelWidth, position.height), subLabels[index]);

// We need to remove from the position the label size that we've just drawn and shift by it's length
pixelShift += labelWidth;

// The amount of space left for the field
float spaceLeft = num - labelWidth;

// If at least two pixels are left to draw this field, draw it, otherwise, skip
if (spaceLeft > 2)
{
// Define the rectangle for the field
var fieldSlot = new Rect(position.x + pixelShift, position.y, num - labelWidth, position.height);

// Draw the right field depending on its type.
if (typeof(T) == typeof(int))
values[index] = (T)(object)EditorGUI.DelayedIntField(fieldSlot, (int)(object)values[index]);
else if (typeof(T) == typeof(bool))
values[index] = (T)(object)EditorGUI.Toggle(fieldSlot, (bool)(object)values[index]);
else if (typeof(T) == typeof(float))
values[index] = (T)(object)EditorGUI.FloatField(fieldSlot, (float)(object)values[index]);
else if (typeof(T).IsEnum)
values[index] = (T)(object)EditorGUI.EnumPopup(fieldSlot, (Enum)(object)values[index]);
else
throw new ArgumentOutOfRangeException($"<{typeof(T)}> is not a supported type for multi field");
}
EditorGUIUtility.labelWidth = Mathf.Clamp(CalcPrefixLabelWidth(subLabels[index], (GUIStyle)null), 0, num);

// Define the rectangle for the field
var fieldSlot = new Rect(position.x + pixelShift, position.y, num, position.height);

// Draw the right field depending on its type.
if (typeof(T) == typeof(int))
values[index] = (T)(object)EditorGUI.DelayedIntField(fieldSlot, subLabels[index], (int)(object)values[index]);
else if (typeof(T) == typeof(bool))
values[index] = (T)(object)EditorGUI.Toggle(fieldSlot, subLabels[index], (bool)(object)values[index]);
else if (typeof(T) == typeof(float))
values[index] = (T)(object)EditorGUI.FloatField(fieldSlot, subLabels[index], (float)(object)values[index]);
else if (typeof(T).IsEnum)
values[index] = (T)(object)EditorGUI.EnumPopup(fieldSlot, subLabels[index], (Enum)(object)values[index]);
else
throw new ArgumentOutOfRangeException($"<{typeof(T)}> is not a supported type for multi field");

// Shift by the slot that was left for the field
pixelShift += spaceLeft;
// Shift by the slot that was used for the field
pixelShift += num;
}
EditorGUIUtility.labelWidth = labelWidth;
EditorGUI.indentLevel = indentLevel;
}

Expand Down

0 comments on commit 79fb235

Please sign in to comment.