// Get parent public GenericValues(Component _ele) { //Get parent TabComponent _parent = _ele.transform.parent.GetComponent <TabComponent>(); if (_parent != null) { parent = _parent.tab; } else { parent.geometry = new TabType.Geometry(); parent.geometry.tabContainer.rect.width = Screen.width; parent.geometry.tabContainer.rect.height = Screen.height; parent.geometry.tabBody.rect.width = Screen.width; parent.geometry.tabBody.rect.height = Screen.height; parent.data = new TabType.Data(); parent.data.type = SubType.TabType.Panel; } //Get values by component BranchValuesComponent _branchValues = _ele.GetComponentInParent <BranchValuesComponent>(); if (_ele.GetType() == typeof(TabComponent)) { ele = TabType.Generic(_ele.GetComponents <TabComponent>()[0].tab); componentPosition = ele.geometry.tabContainer.position; branchPosition = _branchValues.tab.geometry.tabContainer.position; componentSize = ele.geometry.tabContainer.size; branchSize = _branchValues.tab.geometry.tabContainer.size; } else if (_ele.GetType() == typeof(ButtonComponent)) { ele = ButtonType.Generic(_ele.GetComponents <ButtonComponent>()[0].button); componentPosition = ele.geometry.buttonBody.position; branchPosition = _branchValues.button.geometry.buttonBody.position; componentSize = ele.geometry.buttonBody.size; branchSize = _branchValues.button.geometry.buttonBody.size; } else if (_ele.GetType() == typeof(TextareaComponent)) { ele = TextareaType.Generic(_ele.GetComponents <TextareaComponent>()[0].textarea); componentPosition = ele.geometry.textareaBody.position; branchPosition = _branchValues.textarea.geometry.textareaBody.position; componentSize = ele.geometry.textareaBody.size; branchSize = _branchValues.textarea.geometry.textareaBody.size; } }
public GenericPosition(Component _e, Size eSize) { _ele = _e; GenericValues val = new GenericValues(_ele); componentValues = val.componentPosition; branchValues = val.branchPosition; parent = val.parent; ele = val.ele; index = _ele.transform.GetSiblingIndex(); brotherCount = _ele.transform.parent.childCount; SetX(eSize); SetY(eSize); SetPivot(eSize); setXStick(eSize); }
private void SetPivot(Size eSize) { SubType.PositionGeneric values = componentValues; //branch if (values.pivotFollowBranch || branchValues.pivotFollowBranch) { values = branchValues; } switch (values.pivot) { case SubType.PositionGeneric.Pivot.Center: position.x = position.x + (-eSize.w / 2); position.y = position.y + (-eSize.h / 2); break; case SubType.PositionGeneric.Pivot.TopLeft: //Default Position break; } }
private void SetY(Size eSize) { //Y SubType.PositionGeneric values = componentValues; //SubType.PositionGeneric values; //branch if (componentValues.yFollowBranch || branchValues.yFollowBranch) { componentValues = branchValues; } if (values.XFill) { return; } // Y is set by setX //YStick if (values.yStick != SubType.PositionGeneric.ystick.None) { setYStick(eSize); if (values.yMirror) { position.y = eSize.h - position.y; } return; } //YFill if (values.YFill) { // all children must have same size int pH = (int)parent.geometry.tabBody.rect.height; int eH = (int)eSize.h; int elementCountByCol = pH / eH; position.y = eSize.h * ((index) % elementCountByCol); position.x = eSize.w * ((index) / elementCountByCol); if (values.yMirror) { position.y = parent.geometry.tabBody.rect.height - eSize.h - position.y; } if (values.xMirror) { position.x = parent.geometry.tabBody.rect.width - eSize.w - position.x; } return; } //Ystack if (values.YStack) { int index = _ele.transform.GetSiblingIndex(); int brotherCount = _ele.transform.parent.childCount; int i = 0; if (index > 0) { i = index - 1; } TabComponent brotherTab = _ele.transform.parent.GetChild(i).GetComponent <TabComponent>(); ButtonComponent brotherButton = _ele.transform.parent.GetChild(i).GetComponent <ButtonComponent>(); TextareaComponent brotherTextarea = _ele.transform.parent.GetChild(i).GetComponent <TextareaComponent>(); Rect container = new Rect(0, 0, 0, 0); if (brotherTab != null) { container = brotherTab.tab.geometry.tabContainer.rect; } if (brotherButton != null) { container = brotherButton.button.geometry.buttonBody.rect; } if (brotherTextarea != null) { container = brotherTextarea.textarea.geometry.textareaBody.rect; } if (values.yMirror) { position.y = container.y - eSize.h; return; } if (!values.yMirror) { position.y = container.height + container.y; return; } /* * position.y = parent.geometry.tabContent.rect.height; * if (values.yMirror) { position.y = parent.geometry.tabBody.rect.height - eSize.h - position.y; } * return; * */ } //Yrel if (values.RelY) { position.y = values.y * parent.geometry.tabContainer.rect.height; if (values.yMirror) { position.y = parent.geometry.tabBody.rect.height - eSize.h - position.y; } return; } //YLIteral position.y = values.y; if (values.yMirror) { position.y = parent.geometry.tabBody.rect.height - eSize.h - position.y; } return; }
private void SetX(Size eSize) { //Values from component or branch SubType.PositionGeneric values = componentValues; if (values.xFollowBranch || branchValues.xFollowBranch) { values = branchValues; } // if Yfill X set in SetY if (values.YFill) { return; } //XStick if (values.xStick != SubType.PositionGeneric.xstick.None) { setXStick(eSize); if (values.xMirror) { position.x = parent.geometry.tabBody.rect.width - eSize.w - position.x; } return; } //XFill if (values.XFill) // all children must have same size { int pW = (int)parent.geometry.tabBody.rect.width; //int eW = (int)eSize.w; int eW = (int)eSize.w; int elementCountByRow = pW / eW; position.x = eSize.w * ((index) % elementCountByRow); position.y = eSize.h * ((index) / elementCountByRow); if (values.xMirror) { position.x = parent.geometry.tabBody.rect.width - eSize.w - position.x; } if (values.yMirror) { position.y = parent.geometry.tabBody.rect.height - eSize.h - position.y; } return; } //Xstack if (values.XStack) { int index = _ele.transform.GetSiblingIndex(); int brotherCount = _ele.transform.parent.childCount; int i = 0; if (index > 0) { i = index - 1; } TabComponent brotherTab = _ele.transform.parent.GetChild(i).GetComponent <TabComponent>(); ButtonComponent brotherButton = _ele.transform.parent.GetChild(i).GetComponent <ButtonComponent>(); TextareaComponent brotherTextarea = _ele.transform.parent.GetChild(i).GetComponent <TextareaComponent>(); Rect container = new Rect(0, 0, 0, 0); if (brotherTab != null) { container = brotherTab.tab.geometry.tabContainer.rect; } if (brotherButton != null) { container = brotherButton.button.geometry.buttonBody.rect; } if (brotherTextarea != null) { container = brotherTextarea.textarea.geometry.textareaBody.rect; } if (values.xMirror) { position.x = container.x - eSize.w; return; } if (!values.xMirror) { position.x = container.width + container.x; return; } } //x rel if (values.RelX) { position.x = values.x * parent.geometry.tabContainer.rect.width; if (values.xMirror) { position.x = parent.geometry.tabBody.rect.width - eSize.w - position.x; } return; } //x literal position.x = values.x; if (values.xMirror) { position.x = parent.geometry.tabBody.rect.width - eSize.w - position.x; } return; }