LayoutBox.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #include "../../../Include/RmlUi/Core/Box.h"
  3. #include "../../../Include/RmlUi/Core/Types.h"
  4. namespace Rml {
  5. /*
  6. A box used to represent the formatting structure of the document, taking part in the box tree.
  7. */
  8. class LayoutBox {
  9. public:
  10. enum class Type { Root, BlockContainer, InlineContainer, FlexContainer, TableWrapper, Replaced };
  11. virtual ~LayoutBox() = default;
  12. Type GetType() const { return type; }
  13. Vector2f GetVisibleOverflowSize() const { return visible_overflow_size; }
  14. // Returns a pointer to the dimensions box if this layout box has one.
  15. virtual const Box* GetIfBox() const;
  16. // Returns the baseline of the last line of this box, if any. Returns true if a baseline was found, otherwise false.
  17. virtual bool GetBaselineOfLastLine(float& out_baseline) const;
  18. // Calculates the box's inner content width, i.e. the size used to calculate the shrink-to-fit width.
  19. virtual float GetShrinkToFitWidth() const;
  20. // Debug dump layout tree.
  21. String DumpLayoutTree(int depth = 0) const { return DebugDumpTree(depth); }
  22. void* operator new(size_t size);
  23. void operator delete(void* chunk, size_t size);
  24. protected:
  25. LayoutBox(Type type) : type(type) {}
  26. void SetVisibleOverflowSize(Vector2f size) { visible_overflow_size = size; }
  27. virtual String DebugDumpTree(int depth) const = 0;
  28. private:
  29. Type type;
  30. // Visible overflow size is the border size of this box, plus any overflowing content. If this is a scroll
  31. // container, then any overflow should be caught here, and not contribute to our visible overflow size.
  32. Vector2f visible_overflow_size;
  33. };
  34. } // namespace Rml