InlineLevelBox.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #pragma once
  2. #include "../../../Include/RmlUi/Core/Box.h"
  3. #include "../../../Include/RmlUi/Core/StyleTypes.h"
  4. #include "InlineTypes.h"
  5. namespace Rml {
  6. class ElementText;
  7. struct FontMetrics;
  8. /**
  9. A box that takes part in inline layout.
  10. The inline-level box is used to generate fragments that are placed within line boxes.
  11. */
  12. class InlineLevelBox {
  13. public:
  14. virtual ~InlineLevelBox();
  15. // Create a fragment from this box, if it can fit within the available width.
  16. virtual FragmentConstructor CreateFragment(InlineLayoutMode mode, float available_width, float right_spacing_width, bool first_box,
  17. LayoutOverflowHandle overflow_handle) = 0;
  18. // Submit a fragment's position and size to be displayed on the underlying element.
  19. virtual void Submit(const PlacedFragment& placed_fragment) = 0;
  20. float GetHeightAboveBaseline() const { return height_above_baseline; }
  21. float GetDepthBelowBaseline() const { return depth_below_baseline; }
  22. Style::VerticalAlign::Type GetVerticalAlign() const { return vertical_align_type; }
  23. float GetVerticalOffsetFromParent() const { return vertical_offset_from_parent; }
  24. float GetSpacingLeft() const { return spacing_left; }
  25. float GetSpacingRight() const { return spacing_right; }
  26. virtual String DebugDumpNameValue() const = 0;
  27. virtual String DebugDumpTree(int depth) const;
  28. void* operator new(size_t size);
  29. void operator delete(void* chunk, size_t size);
  30. protected:
  31. InlineLevelBox(Element* element) : element(element) { RMLUI_ASSERT(element); }
  32. Element* GetElement() const { return element; }
  33. const FontMetrics& GetFontMetrics() const;
  34. // Set the height used for inline layout, and the vertical offset relative to our parent box.
  35. void SetHeightAndVerticalAlignment(float height_above_baseline, float depth_below_baseline, const InlineLevelBox* parent);
  36. // Set the height used for inline layout.
  37. void SetHeight(float height_above_baseline, float depth_below_baseline);
  38. // Set the inner-to-outer spacing (margin + border + padding) for inline boxes.
  39. void SetInlineBoxSpacing(float spacing_left, float spacing_right);
  40. // Calls Element::OnLayout (proxy for private access to Element).
  41. void SubmitElementOnLayout();
  42. private:
  43. float height_above_baseline = 0.f;
  44. float depth_below_baseline = 0.f;
  45. Style::VerticalAlign::Type vertical_align_type = {};
  46. float vertical_offset_from_parent = 0.f;
  47. float spacing_left = 0.f; // Left margin-border-padding for inline boxes.
  48. float spacing_right = 0.f; // Right margin-border-padding for inline boxes.
  49. Element* element;
  50. };
  51. /**
  52. Atomic inline-level boxes are sized boxes that cannot be split.
  53. This includes inline-block elements, replaced inline-level elements, inline tables, and inline flex containers.
  54. */
  55. class InlineLevelBox_Atomic final : public InlineLevelBox {
  56. public:
  57. InlineLevelBox_Atomic(const InlineLevelBox* parent, Element* element, const Box& box);
  58. FragmentConstructor CreateFragment(InlineLayoutMode mode, float available_width, float right_spacing_width, bool first_box,
  59. LayoutOverflowHandle overflow_handle) override;
  60. void Submit(const PlacedFragment& placed_fragment) override;
  61. String DebugDumpNameValue() const override { return "InlineLevelBox_Atomic"; }
  62. private:
  63. Box box;
  64. };
  65. /**
  66. Inline-level text boxes represent text nodes.
  67. Generates fragments to display its text, splitting it up as necessary to fit in the available space.
  68. */
  69. class InlineLevelBox_Text final : public InlineLevelBox {
  70. public:
  71. InlineLevelBox_Text(ElementText* element);
  72. FragmentConstructor CreateFragment(InlineLayoutMode mode, float available_width, float right_spacing_width, bool first_box,
  73. LayoutOverflowHandle overflow_handle) override;
  74. void Submit(const PlacedFragment& placed_fragment) override;
  75. String DebugDumpNameValue() const override;
  76. private:
  77. ElementText* GetTextElement();
  78. Vector2f element_offset;
  79. StringList fragments;
  80. };
  81. } // namespace Rml