Skip to content

Commit

Permalink
Partially undo scrollbar changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoco007 committed Mar 29, 2024
1 parent b88558b commit 3e74453
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 51 deletions.
6 changes: 0 additions & 6 deletions BeatSaberMarkupLanguage/Components/BSMLScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ public class BSMLScrollView : ScrollView
{
private Coroutine updateLayoutCoroutine;

internal void UpdateViewport()
{
// Resize viewport so it doesn't overlap with scroll bar
viewportTransform.offsetMax = _verticalScrollIndicator != null && _verticalScrollIndicator.gameObject.activeSelf ? new Vector2(-6, 0) : Vector3.zero;
}

private void OnRectTransformDimensionsChange()
{
if (isActiveAndEnabled && updateLayoutCoroutine == null)
Expand Down

This file was deleted.

24 changes: 18 additions & 6 deletions BeatSaberMarkupLanguage/Tags/CustomListTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace BeatSaberMarkupLanguage.Tags
{
public class CustomListTag : BSMLTag
public class CustomListTag : ListTag
{
private Canvas canvasTemplate;

Expand All @@ -16,14 +16,26 @@ public class CustomListTag : BSMLTag

public override GameObject CreateObject(Transform parent)
{
GameObject gameObject = new("BSMLCustomList", typeof(LayoutElement))
GameObject containerObject = new("BSMLCustomListContainer", typeof(LayoutElement))
{
layer = 5,
};

RectTransform container = (RectTransform)containerObject.transform;
container.SetParent(parent, false);
container.anchorMin = Vector2.zero;
container.anchorMax = Vector2.one;
container.sizeDelta = Vector2.zero;
container.anchoredPosition = Vector2.zero;

GameObject gameObject = new("BSMLCustomList")
{
layer = 5,
};
gameObject.SetActive(false);

RectTransform rectTransform = (RectTransform)gameObject.transform;
rectTransform.SetParent(parent, false);
RectTransform rectTransform = gameObject.AddComponent<RectTransform>();
rectTransform.SetParent(container, false);
rectTransform.anchorMin = Vector2.zero;
rectTransform.anchorMax = Vector2.one;
rectTransform.sizeDelta = Vector2.zero;
Expand All @@ -42,7 +54,7 @@ public override GameObject CreateObject(Transform parent)
ScrollView scrollView = DiContainer.InstantiateComponent<BSMLScrollView>(gameObject);

TableView tableView = gameObject.AddComponent<BSMLTableView>();
CustomCellListTableData tableData = gameObject.AddComponent<CustomCellListTableData>();
CustomCellListTableData tableData = containerObject.AddComponent<CustomCellListTableData>();
tableData.tableView = tableView;

tableView._preallocatedCells = new TableView.CellsGroup[0];
Expand All @@ -67,7 +79,7 @@ public override GameObject CreateObject(Transform parent)

// Changed the bool param to "false", as it would otherwise trigger LazyInit earlier than we want it to
tableView.SetDataSource(tableData, false);
return gameObject;
return containerObject;
}
}
}
22 changes: 17 additions & 5 deletions BeatSaberMarkupLanguage/Tags/ListTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@ public class ListTag : BSMLTag

public override GameObject CreateObject(Transform parent)
{
GameObject gameObject = new("BSMLList", typeof(LayoutElement))
GameObject containerObject = new("BSMLListContainer", typeof(LayoutElement))
{
layer = 5,
};

RectTransform container = (RectTransform)containerObject.transform;
container.SetParent(parent, false);
container.anchorMin = Vector2.zero;
container.anchorMax = Vector2.one;
container.sizeDelta = Vector2.zero;
container.anchoredPosition = Vector2.zero;

GameObject gameObject = new("BSMLList")
{
layer = 5,
};
gameObject.SetActive(false);

RectTransform rectTransform = (RectTransform)gameObject.transform;
rectTransform.SetParent(parent, false);
RectTransform rectTransform = gameObject.AddComponent<RectTransform>();
rectTransform.SetParent(container, false);
rectTransform.anchorMin = Vector2.zero;
rectTransform.anchorMax = Vector2.one;
rectTransform.sizeDelta = Vector2.zero;
Expand All @@ -40,7 +52,7 @@ public override GameObject CreateObject(Transform parent)
ScrollView scrollView = DiContainer.InstantiateComponent<BSMLScrollView>(gameObject);

TableView tableView = gameObject.AddComponent<BSMLTableView>();
CustomListTableData tableData = gameObject.AddComponent<CustomListTableData>();
CustomListTableData tableData = containerObject.AddComponent<CustomListTableData>();
tableData.tableView = tableView;

tableView._preallocatedCells = new TableView.CellsGroup[0];
Expand All @@ -64,7 +76,7 @@ public override GameObject CreateObject(Transform parent)
viewport.anchoredPosition = Vector2.zero;

tableView.SetDataSource(tableData, false);
return gameObject;
return containerObject;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,13 @@ public override void HandleType(ComponentTypeWithData componentType, BSMLParserP
VerticalScrollIndicator verticalScrollIndicator = textScrollView._verticalScrollIndicator;
RectTransform scrollBar = (RectTransform)verticalScrollIndicator.transform.parent;

// Make scrollbar have less padding on the right
scrollBar.offsetMin = new Vector2(-6, 0);
((RectTransform)verticalScrollIndicator.transform).anchoredPosition = new Vector2(1, -8);
((RectTransform)pageUpButton.transform.Find("Icon")).anchoredPosition = new Vector2(-2, -4);
((RectTransform)pageDownButton.transform.Find("Icon")).anchoredPosition = new Vector2(-2, 4);
scrollBar.offsetMin = Vector2.zero;
scrollBar.offsetMax = new Vector2(8, 0);

scrollView._pageUpButton = pageUpButton;
scrollView._pageDownButton = pageDownButton;
scrollView._verticalScrollIndicator = verticalScrollIndicator;
scrollBar.SetParent(scrollView.viewportTransform.parent, false);
scrollBar.SetParent(componentType.component.transform, false);
Object.Destroy(textScrollView.gameObject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,14 @@ public override void HandleType(ComponentTypeWithData componentType, BSMLParserP
VerticalScrollIndicator verticalScrollIndicator = textScrollView._verticalScrollIndicator;
RectTransform scrollBar = (RectTransform)verticalScrollIndicator.transform.parent;

// Make scrollbar have less padding on the right
scrollBar.offsetMin = new Vector2(-6, 0);
((RectTransform)verticalScrollIndicator.transform).anchoredPosition = new Vector2(1, -8);
((RectTransform)pageUpButton.transform.Find("Icon")).anchoredPosition = new Vector2(-2, -4);
((RectTransform)pageDownButton.transform.Find("Icon")).anchoredPosition = new Vector2(-2, 4);
scrollBar.offsetMin = Vector2.zero;
scrollBar.offsetMax = new Vector2(8, 0);

scrollView._pageUpButton = pageUpButton;
scrollView._pageDownButton = pageDownButton;
scrollView._verticalScrollIndicator = verticalScrollIndicator;
scrollBar.SetParent(scrollView.viewportTransform.parent, false);
scrollBar.SetParent(componentType.component.transform, false);
Object.Destroy(textScrollView.gameObject);

// Resize viewport so it doesn't overlap with scroll bar
scrollView.viewportTransform.offsetMax = new Vector2(-6, 0);
}

if (componentType.data.TryGetValue("data", out string value))
Expand Down
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/Views/settings-list.bsml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<bg>
<bg size-delta-x='-6' anchor-pos-x='-3'>
<list id='list' select-cell='settings-click' list-style='Simple' visible-cells='7' show-scrollbar='true' />
</bg>

0 comments on commit 3e74453

Please sign in to comment.