Skip to content

Commit

Permalink
Clean up show-scrollbar
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoco007 committed Mar 25, 2024
1 parent 3f929b6 commit 90f1b65
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override void DidActivate(bool firstActivation, bool addedToHierarchy,

if (firstActivation)
{
rectTransform.sizeDelta = new Vector2(35, 0);
rectTransform.sizeDelta = new Vector2(40, 0);
rectTransform.anchorMin = new Vector2(0.5f, 0);
rectTransform.anchorMax = new Vector2(0.5f, 1);
}
Expand Down
25 changes: 12 additions & 13 deletions BeatSaberMarkupLanguage/Tags/CustomListTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ public class CustomListTag : BSMLTag

public override GameObject CreateObject(Transform parent)
{
RectTransform container = (RectTransform)new GameObject("BSMLCustomListContainer", typeof(RectTransform)).transform;
LayoutElement layoutElement = container.gameObject.AddComponent<LayoutElement>();
RectTransform container = (RectTransform)new GameObject("BSMLCustomListContainer", typeof(LayoutElement)).transform;
container.SetParent(parent, false);

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

gameObject.transform.SetParent(container, false);
gameObject.SetActive(false);

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

if (canvasTemplate == null)
{
canvasTemplate = Resources.FindObjectsOfTypeAll<Canvas>().Where(x => x.name == "DropdownTableView").First();
Expand Down Expand Up @@ -60,15 +64,10 @@ public override GameObject CreateObject(Transform parent)
scrollView._contentRectTransform = content;
scrollView._viewport = viewport;

(viewport.transform as RectTransform).anchorMin = new Vector2(0f, 0f);
(viewport.transform as RectTransform).anchorMax = new Vector2(1f, 1f);
(viewport.transform as RectTransform).sizeDelta = new Vector2(0f, 0f);
(viewport.transform as RectTransform).anchoredPosition = new Vector3(0f, 0f);

(tableView.transform as RectTransform).anchorMin = new Vector2(0f, 0f);
(tableView.transform as RectTransform).anchorMax = new Vector2(1f, 1f);
(tableView.transform as RectTransform).sizeDelta = new Vector2(0f, 0f);
(tableView.transform as RectTransform).anchoredPosition = new Vector3(0f, 0f);
viewport.anchorMin = Vector2.zero;
viewport.anchorMax = Vector2.one;
viewport.sizeDelta = Vector2.zero;
viewport.anchoredPosition = Vector2.zero;

// Changed the bool param to "false", as it would otherwise trigger LazyInit earlier than we want it to
tableView.SetDataSource(tableData, false);
Expand Down
25 changes: 12 additions & 13 deletions BeatSaberMarkupLanguage/Tags/ListTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ public class ListTag : BSMLTag

public override GameObject CreateObject(Transform parent)
{
RectTransform container = new GameObject("BSMLListContainer", typeof(RectTransform)).transform as RectTransform;
LayoutElement layoutElement = container.gameObject.AddComponent<LayoutElement>();
RectTransform container = (RectTransform)new GameObject("BSMLListContainer", typeof(LayoutElement)).transform;
container.SetParent(parent, false);

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

gameObject.transform.SetParent(container, false);
gameObject.SetActive(false);

RectTransform rectTransform = gameObject.AddComponent<RectTransform>();
rectTransform.SetParent(container, false);
rectTransform.anchorMin = Vector2.zero;
rectTransform.anchorMax = Vector2.one;
rectTransform.sizeDelta = Vector2.zero;
rectTransform.anchoredPosition = Vector2.zero;

if (canvasTemplate == null)
{
canvasTemplate = Resources.FindObjectsOfTypeAll<Canvas>().Where(x => x.name == "DropdownTableView").First();
Expand Down Expand Up @@ -58,15 +62,10 @@ public override GameObject CreateObject(Transform parent)
scrollView._contentRectTransform = content;
scrollView._viewport = viewport;

(viewport.transform as RectTransform).anchorMin = new Vector2(0f, 0f);
(viewport.transform as RectTransform).anchorMax = new Vector2(1f, 1f);
(viewport.transform as RectTransform).sizeDelta = new Vector2(0f, 0f);
(viewport.transform as RectTransform).anchoredPosition = new Vector3(0f, 0f);

(tableView.transform as RectTransform).anchorMin = new Vector2(0f, 0f);
(tableView.transform as RectTransform).anchorMax = new Vector2(1f, 1f);
(tableView.transform as RectTransform).sizeDelta = new Vector2(0f, 0f);
(tableView.transform as RectTransform).anchoredPosition = new Vector3(0f, 0f);
viewport.anchorMin = Vector2.zero;
viewport.anchorMax = Vector2.one;
viewport.sizeDelta = Vector2.zero;
viewport.anchoredPosition = Vector2.zero;

tableView.SetDataSource(tableData, false);
return container.gameObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class CustomCellListTableDataHandler : TypeHandler
{ "cellClickable", new[] { "clickable-cells" } },
{ "cellTemplate", new[] { "_children" } },
{ "alignCenter", new[] { "align-to-center" } },
{ "stickScrolling", new[] { "stick-scrolling" } },
{ "showScrollbar", new[] { "show-scrollbar" } },
};

Expand Down Expand Up @@ -80,29 +79,29 @@ public override void HandleType(ComponentTypeWithData componentType, BSMLParserP
}

// We can only show the scroll bar for vertical lists
if (verticalList && componentType.data.TryGetValue("showScrollbar", out string showScrollbar))
if (verticalList && componentType.data.TryGetValue("showScrollbar", out string showScrollbar) && Parse.Bool(showScrollbar))
{
if (Parse.Bool(showScrollbar))
{
TextPageScrollView textScrollView = Object.Instantiate(ScrollViewTag.ScrollViewTemplate, componentType.component.transform);

Button pageUpButton = textScrollView._pageUpButton;
Button pageDownButton = textScrollView._pageDownButton;
VerticalScrollIndicator verticalScrollIndicator = textScrollView._verticalScrollIndicator;
RectTransform scrollBar = verticalScrollIndicator.transform.parent as RectTransform;

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

// Need to adjust scroll bar positioning
scrollBar.anchorMin = new Vector2(1, 0);
scrollBar.anchorMax = Vector2.one;
scrollBar.offsetMin = Vector2.zero;
scrollBar.offsetMax = new Vector2(8, 0);
}
TextPageScrollView textScrollView = Object.Instantiate(ScrollViewTag.ScrollViewTemplate);

Button pageUpButton = textScrollView._pageUpButton;
Button pageDownButton = textScrollView._pageDownButton;
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);

scrollView._pageUpButton = pageUpButton;
scrollView._pageDownButton = pageDownButton;
scrollView._verticalScrollIndicator = verticalScrollIndicator;
scrollBar.SetParent(scrollView.viewportTransform.parent, 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
56 changes: 29 additions & 27 deletions BeatSaberMarkupLanguage/TypeHandlers/CustomListTableDataHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class CustomListTableDataHandler : TypeHandler
{ "listStyle", new[] { "list-style" } },
{ "listDirection", new[] { "list-direction" } },
{ "alignCenter", new[] { "align-to-center" } },
{ "stickScrolling", new[] { "stick-scrolling" } },
{ "showScrollbar", new[] { "show-scrollbar" } },
};

Expand Down Expand Up @@ -80,29 +79,29 @@ public override void HandleType(ComponentTypeWithData componentType, BSMLParserP
}

// We can only show the scroll bar for vertical lists
if (verticalList && componentType.data.TryGetValue("showScrollbar", out string showScrollbar))
if (verticalList && componentType.data.TryGetValue("showScrollbar", out string showScrollbar) && Parse.Bool(showScrollbar))
{
if (Parse.Bool(showScrollbar))
{
TextPageScrollView textScrollView = Object.Instantiate(ScrollViewTag.ScrollViewTemplate, componentType.component.transform);

Button pageUpButton = textScrollView._pageUpButton;
Button pageDownButton = textScrollView._pageDownButton;
VerticalScrollIndicator verticalScrollIndicator = textScrollView._verticalScrollIndicator;
RectTransform scrollBar = verticalScrollIndicator.transform.parent as RectTransform;

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

// Need to adjust scroll bar positioning
scrollBar.anchorMin = new Vector2(1, 0);
scrollBar.anchorMax = Vector2.one;
scrollBar.offsetMin = Vector2.zero;
scrollBar.offsetMax = new Vector2(8, 0);
}
TextPageScrollView textScrollView = Object.Instantiate(ScrollViewTag.ScrollViewTemplate);

Button pageUpButton = textScrollView._pageUpButton;
Button pageDownButton = textScrollView._pageDownButton;
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);

scrollView._pageUpButton = pageUpButton;
scrollView._pageDownButton = pageDownButton;
scrollView._verticalScrollIndicator = verticalScrollIndicator;
scrollBar.SetParent(scrollView.viewportTransform.parent, 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 All @@ -116,18 +115,21 @@ public override void HandleType(ComponentTypeWithData componentType, BSMLParserP
tableData.tableView.ReloadData();
}

RectTransform rectTransform = (RectTransform)componentType.component.transform;

switch (tableData.tableView.tableType)
{
case TableView.TableType.Vertical:
(componentType.component.gameObject.transform as RectTransform).sizeDelta = new Vector2(componentType.data.TryGetValue("listWidth", out string vListWidth) ? Parse.Float(vListWidth) : 60, tableData.cellSize * (componentType.data.TryGetValue("visibleCells", out string vVisibleCells) ? Parse.Float(vVisibleCells) : 7));
rectTransform.sizeDelta = new Vector2(componentType.data.TryGetValue("listWidth", out string vListWidth) ? Parse.Float(vListWidth) : 60, tableData.cellSize * (componentType.data.TryGetValue("visibleCells", out string vVisibleCells) ? Parse.Float(vVisibleCells) : 7));
break;
case TableView.TableType.Horizontal:
(componentType.component.gameObject.transform as RectTransform).sizeDelta = new Vector2(tableData.cellSize * (componentType.data.TryGetValue("visibleCells", out string hVisibleCells) ? Parse.Float(hVisibleCells) : 4), componentType.data.TryGetValue("listHeight", out string hListHeight) ? Parse.Float(hListHeight) : 40);
rectTransform.sizeDelta = new Vector2(tableData.cellSize * (componentType.data.TryGetValue("visibleCells", out string hVisibleCells) ? Parse.Float(hVisibleCells) : 4), componentType.data.TryGetValue("listHeight", out string hListHeight) ? Parse.Float(hListHeight) : 40);
break;
}

componentType.component.gameObject.GetComponent<LayoutElement>().preferredHeight = (componentType.component.gameObject.transform as RectTransform).sizeDelta.y;
componentType.component.gameObject.GetComponent<LayoutElement>().preferredWidth = (componentType.component.gameObject.transform as RectTransform).sizeDelta.x;
LayoutElement layoutElement = componentType.component.GetComponent<LayoutElement>();
layoutElement.preferredHeight = rectTransform.sizeDelta.y;
layoutElement.preferredWidth = rectTransform.sizeDelta.x;

tableData.tableView.gameObject.SetActive(true);
tableData.tableView.LazyInit();
Expand Down
2 changes: 1 addition & 1 deletion BeatSaberMarkupLanguage/Views/gameplay-setup-cell.bsml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<horizontal vertical-fit='PreferredSize' pref-height='8' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='https://monkeymanboy.github.io/BSML-Docs/ https://raw.githubusercontent.com/monkeymanboy/BSML-Docs/gh-pages/BSMLSchema.xsd'>
<horizontal vertical-fit='PreferredSize' size-delta-x='-1' anchor-pos-x='1' pref-height='8' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='https://monkeymanboy.github.io/BSML-Docs/ https://raw.githubusercontent.com/monkeymanboy/BSML-Docs/gh-pages/BSMLSchema.xsd'>
<checkbox-setting text='~tab-name' value='tab-visible' bind-value='true' apply-on-change='true' />
</horizontal>
4 changes: 2 additions & 2 deletions BeatSaberMarkupLanguage/Views/gameplay-setup.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</macro.for-each>
<modal id='list-modal' clickerino-offerino-closerino='true' size-delta-x='65' size-delta-y='35'>
<loading-indicator active='~is-loading' preserve-aspect='true' pref-width='20' pref-height='20' />
<horizontal anchor-pos-x='-2' horizontal-fit='PreferredSize' vertical-fit='PreferredSize'>
<list id='mods-list' active='~loaded' show-scrollbar='true' stick-scrolling='true' size-delta-y='32' pref-width='55' pref-height='32' />
<horizontal horizontal-fit='PreferredSize' vertical-fit='PreferredSize'>
<list id='mods-list' active='~loaded' show-scrollbar='true' size-delta-y='32' pref-width='60' pref-height='32' />
</horizontal>
</modal>
</tab>
Expand Down
8 changes: 3 additions & 5 deletions BeatSaberMarkupLanguage/Views/settings-list.bsml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<vertical child-expand-height='false' spacing='2' pad-top='2'>
<page-button click-event='list#PageUp' direction='Up' pref-width='30' pref-height='5'></page-button>
<list id='list' select-cell='settings-click' list-style='Simple' list-width='30' visible-cells='6' anchor-pos-y='8'></list>
<page-button click-event='list#PageDown' direction='Down' pref-width='30' pref-height='5'></page-button>
</vertical>
<bg>
<list id='list' select-cell='settings-click' list-style='Simple' list-width='40' visible-cells='7' show-scrollbar='true' />
</bg>

0 comments on commit 90f1b65

Please sign in to comment.