TableFormattingContext.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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-2023 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_LAYOUT_TABLEFORMATTINGCONTEXT_H
  29. #define RMLUI_CORE_LAYOUT_TABLEFORMATTINGCONTEXT_H
  30. #include "../../../Include/RmlUi/Core/Types.h"
  31. #include "FormattingContext.h"
  32. #include "TableFormattingDetails.h"
  33. namespace Rml {
  34. class Box;
  35. class TableGrid;
  36. class TableWrapper;
  37. struct TrackBox;
  38. using TrackBoxList = Vector<TrackBox>;
  39. /*
  40. Formats a table element and its parts according to table layout rules.
  41. */
  42. class TableFormattingContext final : public FormattingContext {
  43. public:
  44. static UniquePtr<LayoutBox> Format(ContainerBox* parent_container, Element* element, const Box* override_initial_box);
  45. private:
  46. TableFormattingContext() = default;
  47. using BoxList = Vector<Box>;
  48. /// Format the table and its children.
  49. /// @param[out] table_content_size The final size of the table which will be determined by the size of its columns, rows, and spacing.
  50. /// @param[out] table_overflow_size Overflow size in case the contents of any cells overflow their cell box (without being caught by the cell).
  51. /// @param[out] table_baseline The baseline of the table wrapper, in terms of the vertical distance from its top-left border corner.
  52. /// @note Expects the table grid to have been built, and all table parameters to be set already.
  53. void FormatTable(Vector2f& table_content_size, Vector2f& table_overflow_size, float& table_baseline) const;
  54. // Determines the column widths, and populates the columns.
  55. void DetermineColumnWidths(TrackBoxList& columns, float& table_content_width) const;
  56. // Generate the initial boxes for all cells, content height may be indeterminate for now (-1).
  57. void InitializeCellBoxes(BoxList& cells, const TrackBoxList& columns) const;
  58. // Determines the row heights, and populates the rows.
  59. void DetermineRowHeights(TrackBoxList& rows, BoxList& cells, float& table_content_height) const;
  60. // Format the table row and row group elements.
  61. void FormatRows(const TrackBoxList& rows, float table_content_width) const;
  62. // Format the table row and row group elements.
  63. void FormatColumns(const TrackBoxList& columns, float table_content_height) const;
  64. // Format the table cell elements.
  65. void FormatCells(BoxList& cells, Vector2f& table_overflow_size, const TrackBoxList& rows, const TrackBoxList& columns,
  66. float& table_baseline) const;
  67. Element* element_table = nullptr;
  68. TableWrapper* table_wrapper_box = nullptr;
  69. TableGrid grid;
  70. bool table_auto_height = false;
  71. Vector2f table_min_size, table_max_size;
  72. Vector2f table_gap;
  73. Vector2f table_content_offset;
  74. Vector2f table_initial_content_size;
  75. };
  76. } // namespace Rml
  77. #endif