Browse Source

Fixed scroll content position

pull/46/head
Anairkoen Schno 5 years ago
parent
commit
8404ca0947
2 changed files with 29 additions and 60 deletions
  1. +29
    -36
      BSIPA-ModList/UI/ViewControllers/MarkdownView.cs
  2. +0
    -24
      BSIPA-ModList/manifest.json

+ 29
- 36
BSIPA-ModList/UI/ViewControllers/MarkdownView.cs View File

@ -72,20 +72,6 @@ namespace BSIPA_ModList.UI.ViewControllers
protected void Awake() protected void Awake()
{ {
/*view = GetComponent<ScrollRect>();
view.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide;
view.vertical = true;
view.horizontal = false;
view.scrollSensitivity = 0f;
view.inertia = true;
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;*/
gameObject.SetActive(false); gameObject.SetActive(false);
var vpgo = new GameObject("Viewport"); var vpgo = new GameObject("Viewport");
@ -103,23 +89,23 @@ namespace BSIPA_ModList.UI.ViewControllers
vpim.sprite = WhitePixel; vpim.sprite = WhitePixel;
vpim.material = CustomUI.Utilities.UIUtilities.NoGlowMaterial; vpim.material = CustomUI.Utilities.UIUtilities.NoGlowMaterial;
//view.viewport = viewport;
content = new GameObject("Content Wrapper").AddComponent<RectTransform>(); content = new GameObject("Content Wrapper").AddComponent<RectTransform>();
content.SetParent(viewport); content.SetParent(viewport);
var contentLayout = content.gameObject.AddComponent<LayoutElement>();
var contentFitter = content.gameObject.AddComponent<ContentSizeFitter>();
contentFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
contentFitter.verticalFit = ContentSizeFitter.FitMode.Unconstrained;
contentLayout.preferredWidth = contentLayout.minWidth = rectTransform.sizeDelta.x; // to be adjusted
content.gameObject.AddComponent<TagTypeComponent>(); content.gameObject.AddComponent<TagTypeComponent>();
content.localPosition = Vector2.zero; content.localPosition = Vector2.zero;
content.anchorMin = new Vector2(.5f, .5f);
content.anchorMax = new Vector2(.5f, .5f);
content.anchorMin = new Vector2(0f, 1f);
content.anchorMax = new Vector2(1f, 1f);
content.anchoredPosition = Vector2.zero; content.anchoredPosition = Vector2.zero;
//content.sizeDelta = Vector2.zero;
//view.content = content;
var contentLayout = content.gameObject.AddComponent<VerticalLayoutGroup>();
var contentFitter = content.gameObject.AddComponent<ContentSizeFitter>();
contentFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
contentFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
contentLayout.childControlHeight = true;
contentLayout.childControlWidth = false;
contentLayout.childForceExpandHeight = false;
contentLayout.childForceExpandWidth = true;
contentLayout.childAlignment = TextAnchor.UpperCenter;
contentLayout.spacing = 0f;
var pageUp = Instantiate(Resources.FindObjectsOfTypeAll<Button>().Last((Button x) => x.name == "PageUpButton"), rectTransform, false); var pageUp = Instantiate(Resources.FindObjectsOfTypeAll<Button>().Last((Button x) => x.name == "PageUpButton"), rectTransform, false);
var pageDown = Instantiate(Resources.FindObjectsOfTypeAll<Button>().Last((Button x) => x.name == "PageDownButton"), rectTransform, false); var pageDown = Instantiate(Resources.FindObjectsOfTypeAll<Button>().Last((Button x) => x.name == "PageDownButton"), rectTransform, false);
@ -191,10 +177,12 @@ namespace BSIPA_ModList.UI.ViewControllers
else if (resetContentPosition) else if (resetContentPosition)
{ {
resetContentPosition = false; resetContentPosition = false;
/*var v = content.anchoredPosition;
v.y = -(content.rect.height / 2);
content.anchoredPosition = v;*/
scrView.Setup(); scrView.Setup();
// this is the bullshit I have to use to make it work properly
content.gameObject.GetComponent<VerticalLayoutGroup>().enabled = false;
var childRt = content.GetChild(0) as RectTransform;
childRt.anchoredPosition = new Vector2(0f, childRt.anchoredPosition.y);
} }
} }
@ -204,6 +192,9 @@ namespace BSIPA_ModList.UI.ViewControllers
mdDirty = false; mdDirty = false;
Clear(); Clear();
// enable so it will set stuff up
content.gameObject.GetComponent<VerticalLayoutGroup>().enabled = true;
var doc = CommonMarkConverter.Parse(markdown, settings); var doc = CommonMarkConverter.Parse(markdown, settings);
Stack<RectTransform> layout = new Stack<RectTransform>(); Stack<RectTransform> layout = new Stack<RectTransform>();
@ -251,10 +242,10 @@ namespace BSIPA_ModList.UI.ViewControllers
vlayout.localPosition = Vector3.zero; vlayout.localPosition = Vector3.zero;
if (isDoc) if (isDoc)
{ {
vlayout.sizeDelta = Vector2.zero;
vlayout.anchorMin = Vector2.zero;
vlayout.anchorMax = Vector2.one;
vlayout.anchoredPosition = new Vector2(0f, -30f); // no idea where this -30 comes from, but it works for my use
vlayout.sizeDelta = new Vector2(rectTransform.rect.width, 0f);
vlayout.anchorMin = new Vector2(0f, 1f);
vlayout.anchorMax = new Vector2(1f, 1f);
//vlayout.anchoredPosition = new Vector2(0f, -30f); // no idea where this -30 comes from, but it works for my use
} }
var tt = go.AddComponent<TagTypeComponent>(); var tt = go.AddComponent<TagTypeComponent>();
tt.Tag = block.Tag; tt.Tag = block.Tag;
@ -271,9 +262,11 @@ namespace BSIPA_ModList.UI.ViewControllers
l.childForceExpandHeight = l.childForceExpandWidth = false; l.childForceExpandHeight = l.childForceExpandWidth = false;
l.childForceExpandWidth = isDoc; l.childForceExpandWidth = isDoc;
l.spacing = spacing; l.spacing = spacing;
/*var cfit = go.AddComponent<ContentSizeFitter>();
cfit.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
cfit.verticalFit = ContentSizeFitter.FitMode.Unconstrained;*/
if (isDoc)
{
vlayout.anchoredPosition = new Vector2(0f, -vlayout.rect.height);
}
return l; return l;
} }


+ 0
- 24
BSIPA-ModList/manifest.json View File

@ -22,30 +22,6 @@
"and many lines to come!", "and many lines to come!",
"", "",
"and many lines to come!", "and many lines to come!",
"",
"and many lines to come!",
"",
"and many lines to come!",
"",
"and many lines to come!",
"",
"and many lines to come!",
"",
"and many lines to come!",
"",
"and many lines to come!",
"",
"and many lines to come!",
"",
"and many lines to come!",
"",
"and many lines to come!",
"",
"and many lines to come!",
"",
"and many lines to come!",
"",
"and many lines to come!"
], ],
"gameVersion": "0.13.2", "gameVersion": "0.13.2",
"id": "BSIPA Mod List", "id": "BSIPA Mod List",


Loading…
Cancel
Save