@Override public void resizeChild(OGLGUIObject object, int index, int childTotal) { if (index == 0) { topLeft = null; topCenter = null; topRight = null; middleLeft = null; content = null; middleRight = null; bottomLeft = null; bottomCenter = null; bottomRight = null; } Object attr = object.getLayoutAttrib(); if (attr == Attrib.TOP_LEFT) topLeft = object; else if (attr == Attrib.TOP_CENTER) topCenter = object; else if (attr == Attrib.TOP_RIGHT) topRight = object; else if (attr == Attrib.MIDDLE_LEFT) middleLeft = object; else if (attr == Attrib.CONTENT) content = object; else if (attr == Attrib.MIDDLE_RIGHT) middleRight = object; else if (attr == Attrib.BOTTOM_LEFT) bottomLeft = object; else if (attr == Attrib.BOTTOM_CENTER) bottomCenter = object; else if (attr == Attrib.BOTTOM_RIGHT) bottomRight = object; else if (attr == null && content == null) content = object; if (index + 1 == childTotal) orientChildren(); }
@Override public void resizeChild(OGLGUIObject object, int index, int childTotal) { Rectangle2F parentBounds = object.getParent().getBounds(); float pw = parentBounds.width; float ph = parentBounds.height; float x0 = paddingLeft <= 0f ? 0f : (paddingLeft < 1f ? pw * paddingLeft : paddingLeft); float y0 = paddingTop <= 0f ? 0f : (paddingTop < 1f ? ph * paddingTop : paddingTop); float x1 = paddingRight <= 0f ? pw : (paddingRight < 1f ? pw - (pw * paddingRight) : pw - paddingRight); float y1 = paddingBottom <= 0f ? ph : (paddingBottom < 1f ? ph - (ph * paddingBottom) : ph - paddingBottom); object.setBounds(x0, y0, x0 < x1 ? x1 - x0 : 0f, y0 < y1 ? y1 - y0 : 0f); }
/** Once objects with the required attributes are found, this will resize and reposition them. */ protected void orientChildren() { float x = 0f; float y = 0f; float w = 0f; float h = 0f; if (topLeft != null) { Rectangle2F pb = topLeft.getParent().getBounds(); x = 0f; y = 0f; w = topCenter != null ? frameWidth : topRight != null ? pb.width - frameWidth : pb.width; h = frameWidth; topLeft.setBounds(x, y, w, h); } if (topCenter != null) { Rectangle2F pb = topCenter.getParent().getBounds(); x = topLeft != null ? frameWidth : 0f; y = 0f; w = pb.width - (topLeft != null ? frameWidth : 0f) - (topRight != null ? frameWidth : 0f); h = frameWidth; topCenter.setBounds(x, y, w, h); } if (topRight != null) { Rectangle2F pb = topRight.getParent().getBounds(); x = topCenter != null ? pb.width - frameWidth : topLeft != null ? pb.width - frameWidth : 0f; y = 0f; w = frameWidth; h = frameWidth; topRight.setBounds(x, y, w, h); } if (middleLeft != null) { Rectangle2F pb = middleLeft.getParent().getBounds(); boolean hasTop = topLeft != null || topCenter != null || topRight != null; boolean hasBottom = bottomLeft != null || bottomCenter != null || bottomRight != null; x = 0f; y = hasTop ? frameWidth : 0f; w = content != null ? frameWidth : middleRight != null ? pb.width - frameWidth : pb.width; h = pb.height - (hasTop ? frameWidth : 0f) - (hasBottom ? frameWidth : 0f); middleLeft.setBounds(x, y, w, h); } if (content != null) { Rectangle2F pb = content.getParent().getBounds(); boolean hasTop = topLeft != null || topCenter != null || topRight != null; boolean hasBottom = bottomLeft != null || bottomCenter != null || bottomRight != null; x = middleLeft != null ? frameWidth : 0f; y = hasTop ? frameWidth : 0f; w = pb.width - (middleLeft != null ? frameWidth : 0f) - (middleRight != null ? frameWidth : 0f); h = pb.height - (hasTop ? frameWidth : 0f) - (hasBottom ? frameWidth : 0f); content.setBounds(x, y, w, h); } if (middleRight != null) { Rectangle2F pb = middleRight.getParent().getBounds(); boolean hasTop = topLeft != null || topCenter != null || topRight != null; boolean hasBottom = bottomLeft != null || bottomCenter != null || bottomRight != null; x = content != null ? pb.width - frameWidth : middleLeft != null ? pb.width - frameWidth : 0f; y = hasTop ? frameWidth : 0f; w = content != null ? frameWidth : middleLeft != null ? frameWidth : pb.width; h = pb.height - (hasTop ? frameWidth : 0f) - (hasBottom ? frameWidth : 0f); middleRight.setBounds(x, y, w, h); } if (bottomLeft != null) { Rectangle2F pb = bottomLeft.getParent().getBounds(); boolean hasTop = topLeft != null || topCenter != null || topRight != null; boolean hasMiddle = middleLeft != null || content != null || middleRight != null; x = 0f; y = hasMiddle ? pb.height - frameWidth : hasTop ? frameWidth : 0f; w = bottomCenter != null ? frameWidth : bottomRight != null ? pb.width - frameWidth : pb.width; h = hasMiddle ? frameWidth : hasTop ? pb.height - frameWidth : pb.height; bottomLeft.setBounds(x, y, w, h); } if (bottomCenter != null) { Rectangle2F pb = bottomCenter.getParent().getBounds(); boolean hasTop = topLeft != null || topCenter != null || topRight != null; boolean hasMiddle = middleLeft != null || content != null || middleRight != null; x = bottomLeft != null ? frameWidth : 0f; y = hasMiddle ? pb.height - frameWidth : hasTop ? frameWidth : 0f; w = pb.width - (bottomLeft != null ? frameWidth : 0f) - (bottomRight != null ? frameWidth : 0f); h = hasMiddle ? frameWidth : hasTop ? pb.height - frameWidth : pb.height; bottomCenter.setBounds(x, y, w, h); } if (bottomRight != null) { Rectangle2F pb = bottomRight.getParent().getBounds(); boolean hasTop = topLeft != null || topCenter != null || topRight != null; boolean hasMiddle = middleLeft != null || content != null || middleRight != null; x = bottomCenter != null ? pb.width - frameWidth : bottomLeft != null ? frameWidth : 0f; y = hasMiddle ? pb.height - frameWidth : hasTop ? frameWidth : 0f; w = bottomCenter != null ? frameWidth : bottomLeft != null ? pb.width - frameWidth : pb.width; h = hasMiddle ? frameWidth : hasTop ? pb.height - frameWidth : pb.height; bottomRight.setBounds(x, y, w, h); } }