Browse Source

Re-added ScrollRect with scrollbar

pull/46/head
Anairkoen Schno 5 years ago
parent
commit
ad84443844
2 changed files with 32 additions and 8 deletions
  1. +27
    -8
      BSIPA-ModList/UI/ViewControllers/MarkdownView.cs
  2. +5
    -0
      BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs

+ 27
- 8
BSIPA-ModList/UI/ViewControllers/MarkdownView.cs View File

@ -12,7 +12,7 @@ using CustomUI.BeatSaber;
namespace BSIPA_ModList.UI.ViewControllers namespace BSIPA_ModList.UI.ViewControllers
{ {
[RequireComponent(/*typeof(ScrollRect),*/ typeof(RectTransform))]
[RequireComponent(typeof(RectTransform), typeof(ScrollRect))]
public class MarkdownView : MonoBehaviour public class MarkdownView : MonoBehaviour
{ {
private class TagTypeComponent : MonoBehaviour private class TagTypeComponent : MonoBehaviour
@ -34,8 +34,10 @@ namespace BSIPA_ModList.UI.ViewControllers
public RectTransform rectTransform => GetComponent<RectTransform>(); public RectTransform rectTransform => GetComponent<RectTransform>();
//private ScrollRect view;
private ScrollRect view;
private RectTransform content; private RectTransform content;
private RectTransform viewport;
private Scrollbar scrollbar;
private CommonMarkSettings settings; private CommonMarkSettings settings;
public MarkdownView() public MarkdownView()
@ -70,9 +72,31 @@ namespace BSIPA_ModList.UI.ViewControllers
protected void Awake() protected void Awake()
{ {
rectTransform.sizeDelta = new Vector2(100f, 100f); rectTransform.sizeDelta = new Vector2(100f, 100f);
view = GetComponent<ScrollRect>();
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>();
scrollbar.transform.SetParent(transform);
scrollbar.direction = Scrollbar.Direction.TopToBottom;
scrollbar.interactable = true;
view.verticalScrollbar = scrollbar;
var vpgo = new GameObject("Viewport");
viewport = vpgo.AddComponent<RectTransform>();
viewport.SetParent(transform);
viewport.localPosition = Vector2.zero;
viewport.anchorMin = Vector2.zero;
viewport.anchorMax = Vector2.one;
vpgo.AddComponent<Mask>();
view.viewport = viewport;
content = new GameObject("Content Wrapper").AddComponent<RectTransform>(); content = new GameObject("Content Wrapper").AddComponent<RectTransform>();
content.SetParent(transform);
content.SetParent(viewport);
content.localPosition = Vector2.zero; content.localPosition = Vector2.zero;
content.anchorMin = Vector2.zero; content.anchorMin = Vector2.zero;
content.anchorMax = Vector2.one; content.anchorMax = Vector2.one;
@ -84,12 +108,7 @@ namespace BSIPA_ModList.UI.ViewControllers
contentLayout.preferredHeight = 0f; contentLayout.preferredHeight = 0f;
content.gameObject.AddComponent<TagTypeComponent>(); content.gameObject.AddComponent<TagTypeComponent>();
/*view = GetComponent<ScrollRect>();
view.content = content; view.content = content;
view.vertical = true;
view.horizontal = false;
view.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide;
view.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide;*/
} }
private static Sprite whitePixel; private static Sprite whitePixel;


+ 5
- 0
BSIPA-ModList/UI/ViewControllers/ModInfoViewController.cs View File

@ -195,6 +195,11 @@ namespace BSIPA_ModList.UI
mdv.rectTransform.anchorMin = new Vector2(.22f, 0f); mdv.rectTransform.anchorMin = new Vector2(.22f, 0f);
mdv.rectTransform.anchorMax = new Vector2(1f, .25f); mdv.rectTransform.anchorMax = new Vector2(1f, .25f);
mdv.rectTransform.anchoredPosition = Vector2.zero; mdv.rectTransform.anchoredPosition = Vector2.zero;
var le = mdv.gameObject.AddComponent<LayoutElement>();
le.minWidth = le.preferredWidth = 30f;
var asv = mdv.gameObject.AddComponent<AspectRatioFitter>();
asv.aspectMode = AspectRatioFitter.AspectMode.HeightControlsWidth;
asv.aspectRatio = 1f;
mdv.Markdown = controller.Description; mdv.Markdown = controller.Description;
icon = new GameObject("Mod Info View Icon", typeof(RectTransform)).AddComponent<Image>(); icon = new GameObject("Mod Info View Icon", typeof(RectTransform)).AddComponent<Image>();


Loading…
Cancel
Save