Ejemplo n.º 1
0
    void Grid::updateWidgets()
    {
        // Reset the column widths
        for (std::vector<unsigned int>::iterator it = m_ColumnWidth.begin(); it != m_ColumnWidth.end(); ++it)
            *it = 0;

        // Loop through all widgets
        for (unsigned int row = 0; row < m_GridWidgets.size(); ++row)
        {
            // Reset the row height
            m_RowHeight[row] = 0;

            for (unsigned int col = 0; col < m_GridWidgets[row].size(); ++col)
            {
                if (m_GridWidgets[row][col].get() == nullptr)
                    continue;

                // Remember the biggest column width
                if (m_ColumnWidth[col] < m_GridWidgets[row][col]->getFullSize().x + m_ObjBorders[row][col].left + m_ObjBorders[row][col].right)
                    m_ColumnWidth[col] = static_cast<unsigned int>(m_GridWidgets[row][col]->getFullSize().x + m_ObjBorders[row][col].left + m_ObjBorders[row][col].right);

                // Remember the biggest row height
                if (m_RowHeight[row] < m_GridWidgets[row][col]->getFullSize().y + m_ObjBorders[row][col].top + m_ObjBorders[row][col].bottom)
                    m_RowHeight[row] = static_cast<unsigned int>(m_GridWidgets[row][col]->getFullSize().y + m_ObjBorders[row][col].top + m_ObjBorders[row][col].bottom);
            }
        }

        // Reposition all widgets
        updatePositionsOfAllWidgets();
    }
Ejemplo n.º 2
0
Archivo: Grid.cpp Proyecto: texus/TGUI
    bool Grid::remove(const Widget::Ptr& widget)
    {
        auto callbackIt = m_connectedCallbacks.find(widget);
        if (callbackIt != m_connectedCallbacks.end())
            m_connectedCallbacks.erase(callbackIt);

        // Find the widget in the grid
        for (unsigned int row = 0; row < m_gridWidgets.size(); ++row)
        {
            for (unsigned int col = 0; col < m_gridWidgets[row].size(); ++col)
            {
                if (m_gridWidgets[row][col] == widget)
                {
                    // Remove the widget from the grid
                    m_gridWidgets[row].erase(m_gridWidgets[row].begin() + col);
                    m_objBorders[row].erase(m_objBorders[row].begin() + col);
                    m_objAlignment[row].erase(m_objAlignment[row].begin() + col);

                    // Check if this is the last column
                    if (m_columnWidth.size() == m_gridWidgets[row].size() + 1)
                    {
                        // Check if there is another row with this many columns
                        bool rowFound = false;
                        for (unsigned int i = 0; i < m_gridWidgets.size(); ++i)
                        {
                            if (m_gridWidgets[i].size() >= m_columnWidth.size())
                            {
                                rowFound = true;
                                break;
                            }
                        }

                        // Erase the last column if no other row is using it
                        if (!rowFound)
                            m_columnWidth.erase(m_columnWidth.end()-1);
                    }

                    // If the row is empty then remove it as well
                    if (m_gridWidgets[row].empty())
                    {
                        m_gridWidgets.erase(m_gridWidgets.begin() + row);
                        m_objBorders.erase(m_objBorders.begin() + row);
                        m_objAlignment.erase(m_objAlignment.begin() + row);
                        m_rowHeight.erase(m_rowHeight.begin() + row);
                    }

                    // Update the positions of all remaining widgets
                    updatePositionsOfAllWidgets();
                }
            }
        }

        return Container::remove(widget);
    }
Ejemplo n.º 3
0
    void Grid::setSize(float width, float height)
    {
        // A negative size is not allowed for this object
        if (width  < 0) width  = -width;
        if (height < 0) height = -height;

        // Change the intended size of the grid
        m_IntendedSize.x = width;
        m_IntendedSize.y = height;

        updatePositionsOfAllWidgets();
    }
Ejemplo n.º 4
0
    void Grid::remove(Widget* widget)
    {
        // Find the widget in the grid
        for (unsigned int row = 0; row < m_GridWidgets.size(); ++row)
        {
            for (unsigned int col = 0; col < m_GridWidgets[row].size(); ++col)
            {
                if (m_GridWidgets[row][col].get() == widget)
                {
                    // Remove the widget from the grid
                    m_GridWidgets[row].erase(m_GridWidgets[row].begin() + col);
                    m_ObjBorders[row].erase(m_ObjBorders[row].begin() + col);
                    m_ObjLayout[row].erase(m_ObjLayout[row].begin() + col);

                    // Check if this is the last column
                    if (m_ColumnWidth.size() == m_GridWidgets[row].size() + 1)
                    {
                        // Check if there is another row with this many columns
                        bool rowFound = false;
                        for (unsigned int i = 0; i < m_GridWidgets.size(); ++i)
                        {
                            if (m_GridWidgets[i].size() >= m_ColumnWidth.size())
                            {
                                rowFound = true;
                                break;
                            }
                        }

                        // Erase the last column if no other row is using it
                        if (rowFound == false)
                            m_ColumnWidth.erase(m_ColumnWidth.end()-1);
                    }

                    // If the row is empty then remove it as well
                    if (m_GridWidgets[row].empty())
                    {
                        m_GridWidgets.erase(m_GridWidgets.begin() + row);
                        m_ObjBorders.erase(m_ObjBorders.begin() + row);
                        m_ObjLayout.erase(m_ObjLayout.begin() + row);
                        m_RowHeight.erase(m_RowHeight.begin() + row);
                    }

                    // Update the positions of all remaining widgets
                    updatePositionsOfAllWidgets();
                }
            }
        }

        Container::remove(widget);
    }
Ejemplo n.º 5
0
Archivo: Grid.cpp Proyecto: texus/TGUI
    void Grid::setSize(const Layout2d& size)
    {
        Widget::setSize(size);

        updatePositionsOfAllWidgets();
    }