public void Initialize(List <Viewer.ImageMiniaturePair> images, ViewerFullscreenImage vfs) { _fullscreenImage = vfs; int currentRowCount = 0; for (int i = 0; i < images.Count; ++i) { ViewerImageButton btn = SpawnButton(); // adjust size if it is wide image if (images[i].IsWide) { MakeWide(btn); } // initialize btn.Initialize(images[i], _fullscreenImage); btn.GetComponent <RectTransform>().SetParent(GetComponent <RectTransform>(), false); // calculate current position in grid and offset if (i == 0) { Vector2 currentPosition = Vector2.zero; btn.GetComponent <RectTransform>().anchoredPosition = currentPosition; ++currentRowCount; } else if (currentRowCount == 4 || (currentRowCount == 3 && images[i - 1].IsWide)) { Vector3 currentPosition = _iButtons[i - 1].GetComponent <RectTransform>().anchoredPosition; currentPosition.x = 0.0f; currentPosition.y -= _iButtons[i - 1].GetComponent <RectTransform>().sizeDelta.y; btn.GetComponent <RectTransform>().anchoredPosition = currentPosition; currentRowCount = 1; } else { Vector3 currentPosition = _iButtons[i - 1].GetComponent <RectTransform>().anchoredPosition; currentPosition.x += _iButtons[i - 1].GetComponent <RectTransform>().sizeDelta.x; btn.GetComponent <RectTransform>().anchoredPosition = currentPosition; ++currentRowCount; } btn.GetComponent <RectTransform>().localScale = Vector3.one; _iButtons.Add(btn); } }
protected void MakeWide(ViewerImageButton vcb) { vcb.GetComponent <RectTransform>().sizeDelta = new Vector2(BUTTON_WIDE_SIZE_X, BUTTON_SQUARE_SIZE); }