LayoutTable.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUI_CORE_LAYOUTTABLE_H
  29. #define RMLUI_CORE_LAYOUTTABLE_H
  30. #include "../../Include/RmlUi/Core/Types.h"
  31. namespace Rml {
  32. class Box;
  33. class TableGrid;
  34. struct TrackBox;
  35. using TrackBoxList = Vector<TrackBox>;
  36. class LayoutTable {
  37. public:
  38. /// Formats and positions a table, including all elements contained within.
  39. /// @param[inout] box The box used for dimensioning the table, the resulting table size is set on the box.
  40. /// @param[in] min_size Minimum width and height of the table.
  41. /// @param[in] max_size Maximum width and height of the table.
  42. /// @param[in] element_table The table element.
  43. /// @return The content size of the table's overflowing content.
  44. static Vector2f FormatTable(Box& box, Vector2f min_size, Vector2f max_size, Element* element_table);
  45. private:
  46. LayoutTable(Element* element_table, const TableGrid& grid, Vector2f table_gap, Vector2f table_content_offset,
  47. Vector2f table_initial_content_size, bool table_auto_height, Vector2f table_min_size, Vector2f table_max_size);
  48. // Format the table.
  49. void FormatTable();
  50. // Determines the column widths and populates the 'columns' data member.
  51. void DetermineColumnWidths();
  52. // Generate the initial boxes for all cells, content height may be indeterminate for now (-1).
  53. void InitializeCellBoxes();
  54. // Determines the row heights and populates the 'rows' data member.
  55. void DetermineRowHeights();
  56. // Format the table row and row group elements.
  57. void FormatRows();
  58. // Format the table row and row group elements.
  59. void FormatColumns();
  60. // Format the table cell elements.
  61. void FormatCells();
  62. Element* const element_table;
  63. const TableGrid& grid;
  64. const bool table_auto_height;
  65. const Vector2f table_min_size, table_max_size;
  66. const Vector2f table_gap;
  67. const Vector2f table_content_offset;
  68. const Vector2f table_initial_content_size;
  69. // The final size of the table which will be determined by the size of its columns, rows, and spacing.
  70. Vector2f table_resulting_content_size;
  71. // Overflow size in case the contents of any cells overflow their cell box (without being caught by the cell).
  72. Vector2f table_content_overflow_size;
  73. // Defines the boxes for all columns in this table, one entry per table column (spanning columns will add multiple entries).
  74. TrackBoxList columns;
  75. // Defines the boxes for all rows in this table, one entry per table row.
  76. TrackBoxList rows;
  77. // Defines the boxes for all cells in this table.
  78. using BoxList = Vector<Box>;
  79. BoxList cells;
  80. };
  81. } // namespace Rml
  82. #endif