From 64371c723f7f9bcfeccdf218c3eacb8516d66f0d Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Wed, 8 May 2019 18:25:07 -0500 Subject: [PATCH] Re-added ScrollRect with scrollbar --- .../UI/ViewControllers/MarkdownView.cs | 35 ++++++++++++++----- .../ViewControllers/ModInfoViewController.cs | 5 +++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/BSIPA-ModList/UI/ViewControllers/MarkdownView.cs b/BSIPA-ModList/UI/ViewControllers/MarkdownView.cs index a3c0760c..6222277d 100644 --- a/BSIPA-ModList/UI/ViewControllers/MarkdownView.cs +++ b/BSIPA-ModList/UI/ViewControllers/MarkdownView.cs @@ -12,7 +12,7 @@ using CustomUI.BeatSaber; namespace BSIPA_ModList.UI.ViewControllers { - [RequireComponent(/*typeof(ScrollRect),*/ typeof(RectTransform))] + [RequireComponent(typeof(RectTransform), typeof(ScrollRect))] public class MarkdownView : MonoBehaviour { private class TagTypeComponent : MonoBehaviour @@ -34,8 +34,10 @@ namespace BSIPA_ModList.UI.ViewControllers public RectTransform rectTransform => GetComponent(); - //private ScrollRect view; + private ScrollRect view; private RectTransform content; + private RectTransform viewport; + private Scrollbar scrollbar; private CommonMarkSettings settings; public MarkdownView() @@ -70,9 +72,31 @@ namespace BSIPA_ModList.UI.ViewControllers protected void Awake() { rectTransform.sizeDelta = new Vector2(100f, 100f); + view = GetComponent(); + view.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide; + view.vertical = true; + view.horizontal = false; + view.scrollSensitivity = 0f; + view.movementType = ScrollRect.MovementType.Clamped; + + scrollbar = new GameObject("Scrollbar", typeof(RectTransform)).AddComponent(); + scrollbar.transform.SetParent(transform); + scrollbar.direction = Scrollbar.Direction.TopToBottom; + scrollbar.interactable = true; + view.verticalScrollbar = scrollbar; + + var vpgo = new GameObject("Viewport"); + viewport = vpgo.AddComponent(); + viewport.SetParent(transform); + viewport.localPosition = Vector2.zero; + viewport.anchorMin = Vector2.zero; + viewport.anchorMax = Vector2.one; + vpgo.AddComponent(); + + view.viewport = viewport; content = new GameObject("Content Wrapper").AddComponent(); - content.SetParent(transform); + content.SetParent(viewport); content.localPosition = Vector2.zero; content.anchorMin = Vector2.zero; content.anchorMax = Vector2.one; @@ -84,12 +108,7 @@ namespace BSIPA_ModList.UI.ViewControllers contentLayout.preferredHeight = 0f; content.gameObject.AddComponent(); - /*view = GetComponent(); view.content = content; - view.vertical = true; - view.horizontal = false; - view.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide; - view.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide;*/ } private static Sprite whitePixel; diff --git a/BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs b/BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs index 96bd0b69..838fb2f0 100644 --- a/BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs +++ b/BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs @@ -195,6 +195,11 @@ namespace BSIPA_ModList.UI mdv.rectTransform.anchorMin = new Vector2(.22f, 0f); mdv.rectTransform.anchorMax = new Vector2(1f, .25f); mdv.rectTransform.anchoredPosition = Vector2.zero; + var le = mdv.gameObject.AddComponent(); + le.minWidth = le.preferredWidth = 30f; + var asv = mdv.gameObject.AddComponent(); + asv.aspectMode = AspectRatioFitter.AspectMode.HeightControlsWidth; + asv.aspectRatio = 1f; mdv.Markdown = controller.Description; icon = new GameObject("Mod Info View Icon", typeof(RectTransform)).AddComponent();