//----------------------------------------------------------------------------// void GridLayoutContainer::layout() { std::vector<UDim> colSizes(d_gridWidth, UDim(0, 0)); std::vector<UDim> rowSizes(d_gridHeight, UDim(0, 0)); // used to compare UDims const float absWidth = getChildContentArea().get().getWidth(); const float absHeight = getChildContentArea().get().getHeight(); // first, we need to determine rowSizes and colSizes, this is needed before // any layouting work takes place for (size_t y = 0; y < d_gridHeight; ++y) { for (size_t x = 0; x < d_gridWidth; ++x) { // x and y is the position of window in the grid const size_t childIdx = mapFromGridToIdx(x, y, d_gridWidth, d_gridHeight); Window* window = getChildAtIdx(childIdx); const UVector2 size = getBoundingSizeForWindow(window); if (CoordConverter::asAbsolute(colSizes[x], absWidth) < CoordConverter::asAbsolute(size.d_x, absWidth)) { colSizes[x] = size.d_x; } if (CoordConverter::asAbsolute(rowSizes[y], absHeight) < CoordConverter::asAbsolute(size.d_y, absHeight)) { rowSizes[y] = size.d_y; } } } // OK, now in rowSizes[y] is the height of y-th row // in colSizes[x] is the width of x-th column // second layouting phase starts now for (size_t y = 0; y < d_gridHeight; ++y) { for (size_t x = 0; x < d_gridWidth; ++x) { // x and y is the position of window in the grid const size_t childIdx = mapFromGridToIdx(x, y, d_gridWidth, d_gridHeight); Window* window = getChildAtIdx(childIdx); const UVector2 offset = getOffsetForWindow(window); const UVector2 gridCellOffset = getGridCellOffset(colSizes, rowSizes, x, y); window->setPosition(gridCellOffset + offset); } } // now we just need to determine the total width and height and set it setSize(getGridSize(colSizes, rowSizes)); }
//----------------------------------------------------------------------------// Rect ScrolledContainer::getChildExtentsArea(void) const { Rect extents(0, 0, 0, 0); const size_t childCount = getChildCount(); if (childCount == 0) return extents; for (size_t i = 0; i < childCount; ++i) { const Window* const wnd = getChildAtIdx(i); const Rect area(wnd->getArea().asAbsolute(d_pixelSize)); if (area.d_left < extents.d_left) extents.d_left = area.d_left; if (area.d_top < extents.d_top) extents.d_top = area.d_top; if (area.d_right > extents.d_right) extents.d_right = area.d_right; if (area.d_bottom > extents.d_bottom) extents.d_bottom = area.d_bottom; } return extents; }
//----------------------------------------------------------------------------// Rectf ScrolledContainer::getChildExtentsArea(void) const { Rectf extents(0, 0, 0, 0); const size_t childCount = getChildCount(); if (childCount == 0) return extents; for (size_t i = 0; i < childCount; ++i) { const Window* const wnd = getChildAtIdx(i); Rectf area( CoordConverter::asAbsolute(wnd->getPosition(), d_pixelSize), wnd->getPixelSize()); if (wnd->getHorizontalAlignment() == HA_CENTRE) area.setPosition(area.getPosition() - Vector2<float>(area.getWidth() * 0.5f - d_pixelSize.d_width * 0.5f, 0.0f)); if (wnd->getVerticalAlignment() == VA_CENTRE) area.setPosition(area.getPosition() - Vector2<float>(0.0f, area.getHeight() * 0.5f - d_pixelSize.d_height * 0.5f)); if (area.d_min.d_x < extents.d_min.d_x) extents.d_min.d_x = area.d_min.d_x; if (area.d_min.d_y < extents.d_min.d_y) extents.d_min.d_y = area.d_min.d_y; if (area.d_max.d_x > extents.d_max.d_x) extents.d_max.d_x = area.d_max.d_x; if (area.d_max.d_y > extents.d_max.d_y) extents.d_max.d_y = area.d_max.d_y; } return extents; }
//----------------------------------------------------------------------------// Rectf ScrolledContainer::getChildExtentsArea(void) const { Rectf extents(0, 0, 0, 0); const size_t childCount = getChildCount(); if (childCount == 0) return extents; for (size_t i = 0; i < childCount; ++i) { const Window* const wnd = getChildAtIdx(i); const Rectf area( CoordConverter::asAbsolute(wnd->getPosition(), d_pixelSize), wnd->getPixelSize()); if (area.d_min.d_x < extents.d_min.d_x) extents.d_min.d_x = area.d_min.d_x; if (area.d_min.d_y < extents.d_min.d_y) extents.d_min.d_y = area.d_min.d_y; if (area.d_max.d_x > extents.d_max.d_x) extents.d_max.d_x = area.d_max.d_x; if (area.d_max.d_y > extents.d_max.d_y) extents.d_max.d_y = area.d_max.d_y; } return extents; }
//----------------------------------------------------------------------------// Window* GridLayoutContainer::getChildAtPosition(size_t gridX, size_t gridY) { assert(gridX < d_gridWidth && "out of bounds"); assert(gridY < d_gridHeight && "out of bounds"); return getChildAtIdx(mapFromGridToIdx(gridX, gridY, d_gridWidth, d_gridHeight)); }
//----------------------------------------------------------------------------// size_t LayoutContainer::getIdxOfChild(Window* wnd) const { for (size_t i = 0; i < getChildCount(); ++i) { if (getChildAtIdx(i) == wnd) { return i; } } assert(0); return 0; }