public override void InitializeWindow() { base.InitializeWindow(); MyrmidonEditorLayoutElement panel01 = new MyrmidonEditorLayoutElement(0, 0, 1, 10); //20 MyrmidonEditorLayoutElement panel02 = new MyrmidonEditorLayoutElement(0, 0, 1, 10); //30 MyrmidonEditorLayoutElement panel03 = new MyrmidonEditorLayoutElement(0, 0, 1, 10); //50 MyrmidonEditorLayoutElement panel04 = new MyrmidonEditorLayoutElement(0, 0, 1, 70); //50 panel01.AssignBackgroundColor(Color.blue); panel02.AssignBackgroundColor(Color.red); panel03.AssignBackgroundColor(Color.green); panel04.AssignBackgroundColor(Color.yellow); MyrmidonEditorLayout panelLayout = new MyrmidonEditorHorizontalLayout(new List <MyrmidonEditorLayoutElement> { panel01, panel02, panel03, panel04 }, false, false, true); panelLayout.SetRect(new Rect(0, 0, position.width, position.height)); panelLayout.SetPadding(30, 30, 30, 30); panelLayout.AssignBackgroundColor(Color.cyan); panelLayout.ComputeRects(); _mWindowContainer = panelLayout; }
protected override MyrmidonEditorResizerElement CreateResizerForLayout(MyrmidonEditorLayoutElement previous, MyrmidonEditorLayoutElement next) { float resizerWidth = MyrmidonEditorResizerElement.RESIZER_SIZE; MyrmidonEditorResizerElement resizer = new MyrmidonEditorResizerElement(previous, next, 0, resizerWidth, 1, 0, MyrmidonResizerType.Vertical, true, false); return(resizer); }
/// <summary> /// /// </summary> /// <param name="deltaWidth"></param> /// <param name="deltaHeight"></param> public override void ProcessResizing(float deltaWidth, float deltaHeight) { base.ProcessResizing(deltaWidth, deltaHeight); float totalHeightPercentage = GetTotalHeightPercentageOverLayout(); float heightToAdd = 0f; for (int i = 0; i < _mElements.Count; i++) { MyrmidonEditorLayoutElement element = _mElements[i]; float percentageOverLayoutNormalized = GetHeightPercentageOverLayout(element) / totalHeightPercentage; float heightAttributed = (percentageOverLayoutNormalized * deltaHeight); element.ProcessResizing(deltaWidth, heightAttributed); Rect rect = element.Rect; rect.y += heightToAdd; element.SetRect(rect); if (element.IsResizableHeight) { heightToAdd += heightAttributed; } } }
private void TestLayoutHorizontal() { MyrmidonEditorLayoutElement panel01 = new MyrmidonEditorLayoutElement(0, 0, 10, 1); //20 MyrmidonEditorLayoutElement panel02 = new MyrmidonEditorLayoutElement(0, 0, 10, 1); //30 MyrmidonEditorLayoutElement panel03 = new MyrmidonEditorLayoutElement(0, 0, 10, 1); //50 MyrmidonEditorLayoutElement panel04 = new MyrmidonEditorLayoutElement(0, 0, 70, 1); //50 panel01.AssignBackgroundColor(Color.blue); panel02.AssignBackgroundColor(Color.red); panel03.AssignBackgroundColor(Color.green); panel04.AssignBackgroundColor(Color.yellow); MyrmidonEditorLayout panelLayout = new MyrmidonEditorHorizontalLayout(new List <MyrmidonEditorLayoutElement> { panel01, panel02, panel03, panel04 }, false, false, true); panelLayout.SetRect(new Rect(0, 0, position.width, position.height)); panelLayout.SetPadding(30, 30, 30, 30); panelLayout.AssignBackgroundColor(Color.cyan); panelLayout.ComputeRects(); panelLayout.Draw(); }
private void TestLayoutVerticalThenHorizontal() { MyrmidonEditorLayoutElement panel04_01 = new MyrmidonEditorLayoutElement(0, 0, 1, 10); MyrmidonEditorLayoutElement panel04_02 = new MyrmidonEditorLayoutElement(0, 0, 1, 10); MyrmidonEditorLayoutElement panel04_03 = new MyrmidonEditorLayoutElement(0, 0, 1, 10); panel04_01.AssignBackgroundColor(Color.magenta); panel04_02.AssignBackgroundColor(Color.black); panel04_03.AssignBackgroundColor(Color.grey); MyrmidonEditorLayoutElement panel01 = new MyrmidonEditorLayoutElement(0, 0, 1, 1); //20 MyrmidonEditorLayoutElement panel02 = new MyrmidonEditorLayoutElement(0, 0, 1, 1); //30 MyrmidonEditorLayoutElement panel03 = new MyrmidonEditorLayoutElement(0, 0, 1, 1); //50 MyrmidonEditorLayout panel04 = new MyrmidonEditorHorizontalLayout(new List <MyrmidonEditorLayoutElement> { panel04_01, panel04_02, panel04_03 }, true, true, false, 0, 0, 1, 1); panel04.SetPadding(10, 10, 10, 10); panel04.Spacing = 5f; panel01.AssignBackgroundColor(Color.blue); panel02.AssignBackgroundColor(Color.red); panel03.AssignBackgroundColor(Color.green); panel04.AssignBackgroundColor(Color.yellow); MyrmidonEditorLayout panelLayout = new MyrmidonEditorVerticalLayout(new List <MyrmidonEditorLayoutElement> { panel01, panel02, panel03, panel04 }, false, false, false); panelLayout.Spacing = 10f; panelLayout.SetRect(new Rect(0, 0, position.width, position.height)); panelLayout.SetPadding(30, 30, 30, 30); panelLayout.AssignBackgroundColor(Color.cyan); panelLayout.Draw(); }
public override void ComputeRects() { if (_mRect != null) { int nbElement = _mElements.Count; float widthAvailable = ComputeWidthAvailable(_mRect); float heightAvailable = ComputeHeightAvailable(_mRect); float remainingHeight = heightAvailable; Rect[] rects = new Rect[_mElements.Count]; // Assigning width and X position for (int i = 0; i < _mElements.Count; i++) { MyrmidonEditorLayoutElement element = _mElements[i]; rects[i].width = 0f; rects[i].x = _mRect.x + _mPaddingLeft; if (_mForceChildToExpandWidth) { rects[i].width = widthAvailable; } else if (element.FlexibleWidth > 0) { rects[i].width = widthAvailable; } else if (element.PreferredWidth > 0) { rects[i].width = Mathf.Clamp(element.PreferredWidth, 0, widthAvailable); } } // Assigning height preferred size for (int i = 0; i < _mElements.Count; i++) { MyrmidonEditorLayoutElement element = _mElements[i]; rects[i].height = element.PreferredHeight; remainingHeight -= rects[i].height; } // Assigning height flexible size if (_mForceChildToExpandHeight || Atleast1FlexibleHeight()) { float minBoundFlexibleHeight = 0f; float maxBoundFlexibleHeight = 0f; ComputeRangeFlexibleHeight(out minBoundFlexibleHeight, out maxBoundFlexibleHeight); for (int i = 0; i < _mElements.Count; i++) { MyrmidonEditorLayoutElement element = _mElements[i]; float normalizedValue = (element.FlexibleHeight - minBoundFlexibleHeight) / (maxBoundFlexibleHeight - minBoundFlexibleHeight); float additionalHeight = remainingHeight * normalizedValue; rects[i].height += additionalHeight; } } // Assigning Y position float currentY = _mRect.y + _mPaddingTop; for (int i = 0; i < _mElements.Count; i++) { rects[i].y = currentY; currentY += rects[i].height + _mSpacing; } // Assigning rects for (int i = 0; i < _mElements.Count; i++) { _mElements[i].SetRect(rects[i]); } } }