Resolved issues with DisplayAbove and using a 0 ItemsToDisplay
parent
b3bb76246b
commit
e085cbe076
|
@ -369,6 +369,10 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
|
float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
|
||||||
_scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
|
_scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
|
||||||
|
|
||||||
|
float dropdownHeight = _itemsToDisplay > 0 ? _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) : _rectTransform.sizeDelta.y * _panelItems.Count;
|
||||||
|
dropdownHeight += dropdownOffset;
|
||||||
|
|
||||||
if (!_hasDrawnOnce || _rectTransform.sizeDelta != _inputRT.sizeDelta)
|
if (!_hasDrawnOnce || _rectTransform.sizeDelta != _inputRT.sizeDelta)
|
||||||
{
|
{
|
||||||
_hasDrawnOnce = true;
|
_hasDrawnOnce = true;
|
||||||
|
@ -380,8 +384,8 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
_scrollPanelRT.SetParent(transform, true);
|
_scrollPanelRT.SetParent(transform, true);
|
||||||
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
|
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
|
||||||
new Vector2(0, dropdownOffset + _rectTransform.sizeDelta.y * (_panelItems.Count - itemsRemaining) - 1) :
|
new Vector2(0, dropdownOffset + dropdownHeight) :
|
||||||
new Vector2(0, -_rectTransform.sizeDelta.y);
|
new Vector2(0, -(dropdownOffset + _rectTransform.sizeDelta.y));
|
||||||
|
|
||||||
//make the overlay fill the screen
|
//make the overlay fill the screen
|
||||||
_overlayRT.SetParent(_canvas.transform, false);
|
_overlayRT.SetParent(_canvas.transform, false);
|
||||||
|
@ -394,8 +398,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
if (_panelItems.Count < 1) return;
|
if (_panelItems.Count < 1) return;
|
||||||
|
|
||||||
float dropdownHeight = _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) + dropdownOffset;
|
|
||||||
|
|
||||||
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
|
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
|
||||||
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
|
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
|
||||||
|
|
||||||
|
|
|
@ -280,6 +280,10 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
|
float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
|
||||||
_scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
|
_scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
|
||||||
|
|
||||||
|
float dropdownHeight = _itemsToDisplay > 0 ? _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) : _rectTransform.sizeDelta.y * _panelItems.Count;
|
||||||
|
dropdownHeight += dropdownOffset;
|
||||||
|
|
||||||
if (!_hasDrawnOnce || _rectTransform.sizeDelta != _inputRT.sizeDelta)
|
if (!_hasDrawnOnce || _rectTransform.sizeDelta != _inputRT.sizeDelta)
|
||||||
{
|
{
|
||||||
_hasDrawnOnce = true;
|
_hasDrawnOnce = true;
|
||||||
|
@ -291,8 +295,8 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
_scrollPanelRT.SetParent(transform, true);
|
_scrollPanelRT.SetParent(transform, true);
|
||||||
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
|
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
|
||||||
new Vector2(0, dropdownOffset + _rectTransform.sizeDelta.y * (_panelItems.Count - itemsRemaining) - 1) :
|
new Vector2(0, dropdownOffset + dropdownHeight) :
|
||||||
new Vector2(0, -_rectTransform.sizeDelta.y);
|
new Vector2(0, -(dropdownOffset + _rectTransform.sizeDelta.y));
|
||||||
|
|
||||||
//make the overlay fill the screen
|
//make the overlay fill the screen
|
||||||
_overlayRT.SetParent(_canvas.transform, false);
|
_overlayRT.SetParent(_canvas.transform, false);
|
||||||
|
@ -305,8 +309,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
if (_panelItems.Count < 1) return;
|
if (_panelItems.Count < 1) return;
|
||||||
|
|
||||||
float dropdownHeight = _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) + dropdownOffset;
|
|
||||||
|
|
||||||
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
|
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
|
||||||
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
|
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
|
||||||
|
|
||||||
|
|
|
@ -363,6 +363,10 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
|
float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
|
||||||
_scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
|
_scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
|
||||||
|
|
||||||
|
float dropdownHeight = _itemsToDisplay > 0 ? _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) : _rectTransform.sizeDelta.y * _panelItems.Count;
|
||||||
|
dropdownHeight += dropdownOffset;
|
||||||
|
|
||||||
if (!_hasDrawnOnce || _rectTransform.sizeDelta != _mainButton.rectTransform.sizeDelta)
|
if (!_hasDrawnOnce || _rectTransform.sizeDelta != _mainButton.rectTransform.sizeDelta)
|
||||||
{
|
{
|
||||||
_hasDrawnOnce = true;
|
_hasDrawnOnce = true;
|
||||||
|
@ -374,8 +378,8 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
_scrollPanelRT.SetParent(transform, true);
|
_scrollPanelRT.SetParent(transform, true);
|
||||||
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
|
_scrollPanelRT.anchoredPosition = _displayPanelAbove ?
|
||||||
new Vector2(0, dropdownOffset + _rectTransform.sizeDelta.y * (_panelItems.Count - itemsRemaining) - 1) :
|
new Vector2(0, dropdownOffset + dropdownHeight) :
|
||||||
new Vector2(0, -_rectTransform.sizeDelta.y);
|
new Vector2(0, -(dropdownOffset + _rectTransform.sizeDelta.y));
|
||||||
|
|
||||||
//make the overlay fill the screen
|
//make the overlay fill the screen
|
||||||
_overlayRT.SetParent(_canvas.transform, false);
|
_overlayRT.SetParent(_canvas.transform, false);
|
||||||
|
@ -388,8 +392,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
if (_panelItems.Count < 1) return;
|
if (_panelItems.Count < 1) return;
|
||||||
|
|
||||||
float dropdownHeight = _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) + dropdownOffset;
|
|
||||||
|
|
||||||
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
|
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
|
||||||
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
|
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue