Skip to content

Commit

Permalink
Merge pull request #105 from suzuryg/fix/incorrect-branch-list-elemen…
Browse files Browse the repository at this point in the history
…t-height

fix: Incorrect BranchListView element height calculation in Unity2022
  • Loading branch information
suzuryg authored Jan 11, 2024
2 parents cf75ff6 + 8067afc commit a9ad6e0
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ public class BranchListElement : IDisposable
private static readonly Color ActiveElementColor = new Color(0f, 0.5f, 1f, 0.4f);
private static readonly Color FocusedElementColor = new Color(0f, 0.5f, 1f, 0.4f);

#if UNITY_2022_1_OR_NEWER
// In Unity2022, the height of the element passed to the ReorderableList callback is not equal to the actual height of the element.
private static readonly float ElementHeightGap = 2;
#else
private static readonly float ElementHeightGap = 0;
#endif

public IMenu Menu { get; private set; }
public string SelectedModeId { get; private set; }
public bool IsSimplified { get; set; } = false;
Expand Down Expand Up @@ -232,7 +239,7 @@ public void OnGUI(Rect rect)
float totalHeight = 0;
for (int i = 0; i < _reorderableList.list.Count; i++)
{
totalHeight += GetElementHeight(i);
totalHeight += GetElementHeight(i) + ElementHeightGap;
}
var viewRect = new Rect(rect.x, rect.y,
rect.width - EditorGUIUtility.singleLineHeight,
Expand Down Expand Up @@ -273,7 +280,7 @@ public void ChangeBranchSelection(int branchIndex)
var height = 0f;
for (int i = 0; i <= branchIndex; i++)
{
height = GetElementHeight(i);
height = GetElementHeight(i) + ElementHeightGap;
yBottom += height;
}
var yTop = yBottom - height;
Expand Down

0 comments on commit a9ad6e0

Please sign in to comment.