LayoutTable.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 "LayoutBlockBox.h"
  31. #include "../../Include/RmlUi/Core/Types.h"
  32. namespace Rml {
  33. class Box;
  34. class LayoutTable
  35. {
  36. public:
  37. /// Formats and positions a table, including all elements contained within.
  38. /// @param[inout] box The box used for dimensioning the table, the resulting table size is set on the box.
  39. /// @param[in] min_size Minimum width and height of the table.
  40. /// @param[in] max_size Maximum width and height of the table.
  41. /// @param[in] element_table The table element.
  42. /// @return The content size of the table's overflowing content.
  43. static Vector2f FormatTable(Box& box, Vector2f min_size, Vector2f max_size, Element* element_table);
  44. private:
  45. LayoutTable(Element* element_table, Vector2f table_gap, Vector2f table_content_offset, Vector2f table_initial_content_size, Vector2f table_min_size, Vector2f table_max_size);
  46. struct Column {
  47. Element* element_column = nullptr; // The '<col>' element which begins at this column, or nullptr if there is no such element or if the column is spanned from a previous column.
  48. Element* element_group = nullptr; // The '<colgroup>' element which begins at this column, otherwise nullptr.
  49. float cell_width = 0; // The *border* width of cells in this column.
  50. float cell_offset = 0; // Horizontal offset from the table content box to the border box of cells in this column.
  51. float column_width = 0; // The *content* width of the column element, which may span multiple columns.
  52. float column_offset = 0; // Horizontal offset from the table content box to the border box of the column element.
  53. float group_width = 0; // The *content* width of the column group element, which may span multiple columns.
  54. float group_offset = 0; // Horizontal offset from the table content box to the border box of the column group element.
  55. };
  56. using ColumnList = Vector<Column>;
  57. struct Cell {
  58. Element* element_cell; // The <td> element.
  59. int row_last; // The last row the cell spans.
  60. int column_begin, column_last; // The first and last columns the cell spans.
  61. Box box; // The cell element's resulting sizing box.
  62. Vector2f table_offset; // The cell element's offset from the table border box.
  63. };
  64. using CellList = Vector<Cell>;
  65. struct Row {
  66. const int index;
  67. const float content_position_y;
  68. const float fixed_height;
  69. const float min_height, max_height;
  70. float content_height;
  71. };
  72. // Format the table.
  73. void FormatTable();
  74. // Determines the column widths and populates the 'columns' data member.
  75. void DetermineColumnWidths();
  76. // Format the table row element, add cell elements beginning at this row, and format all table cells ending at this row.
  77. // @return The y-position of the row's bottom edge.
  78. float FormatTableRow(int row_index, Element* element_row, float row_position_y);
  79. // Add cell elements beginning at this row and format all cells ending at this row.
  80. // @return The y-position of the row's bottom content edge.
  81. float FormatCellsInRow(const ElementList& cell_elements, Row& row);
  82. Element* const element_table;
  83. const Vector2f table_min_size, table_max_size;
  84. const Vector2f table_gap;
  85. const Vector2f table_content_offset;
  86. const Vector2f table_initial_content_size;
  87. // The final size of the table which will be determined by the size of its columns, rows, and spacing.
  88. Vector2f table_resulting_content_size;
  89. // Overflow size in case the contents of any cells overflow their cell box (without being caught by the cell).
  90. Vector2f table_content_overflow_size;
  91. // Defines all the columns of this table, one entry per table column (spanning columns will add multiple entries).
  92. ColumnList columns;
  93. // Cells are added during iteration of each table row, and removed once they are placed at the last of the rows they span.
  94. CellList cells;
  95. };
  96. } // namespace Rml
  97. #endif