/// <summary> /// {@link #pack() Packs} the dialog and adds it to the stage /// </summary> /// <param name="stage">Stage.</param> public Dialog Show(Stage stage) { stage.AddElement(this); SetPosition(Mathf.Round((stage.GetWidth() - GetWidth()) / 2), Mathf.Round((stage.GetHeight() - GetHeight()) / 2)); Pack(); return(this); }
public void Show(Stage stage) { if (ListBox.IsTouchable()) { return; } stage.AddElement(this); _screenPosition = _selectBox.LocalToStageCoordinates(Vector2.Zero); // show the list above or below the select box, limited to a number of items and the available height in the stage. float itemHeight = ListBox.GetItemHeight(); float height = itemHeight * (MaxListCount <= 0 ? _selectBox.GetItems().Count : Math.Min(MaxListCount, _selectBox.GetItems().Count)); var scrollPaneBackground = GetStyle().Background; if (scrollPaneBackground != null) { height += scrollPaneBackground.TopHeight + scrollPaneBackground.BottomHeight; } var listBackground = ListBox.GetStyle().Background; if (listBackground != null) { height += listBackground.TopHeight + listBackground.BottomHeight; } float heightAbove = _screenPosition.Y; float heightBelow = Screen.Height /*camera.viewportHeight */ - _screenPosition.Y - _selectBox.GetHeight(); _isListBelowSelectBox = true; if (height > heightBelow) { if (heightAbove > heightBelow) { _isListBelowSelectBox = false; height = Math.Min(height, heightAbove); } else { height = heightBelow; } } if (!_isListBelowSelectBox) { SetY(_screenPosition.Y - height); } else { SetY(_screenPosition.Y + _selectBox.GetHeight()); } SetX(_screenPosition.X); SetHeight(height); Validate(); var width = Math.Max(PreferredWidth, _selectBox.GetWidth()); if (PreferredHeight > height && !_disableY) { width += GetScrollBarWidth(); } SetWidth(width); Validate(); ScrollTo(0, ListBox.GetHeight() - _selectBox.GetSelectedIndex() * itemHeight - itemHeight / 2, 0, 0, true, true); UpdateVisualScroll(); _previousScrollFocus = null; ListBox.GetSelection().Set(_selectBox.GetSelected()); ListBox.SetTouchable(Touchable.Enabled); _selectBox.OnShow(this, _isListBelowSelectBox); }