LayoutLineBox.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_LAYOUTLINEBOX_H
  29. #define RMLUI_CORE_LAYOUTLINEBOX_H
  30. #include "LayoutInlineBox.h"
  31. namespace Rml {
  32. class LayoutBlockBox;
  33. /**
  34. @author Peter Curry
  35. */
  36. class LayoutLineBox
  37. {
  38. public:
  39. LayoutLineBox(LayoutBlockBox* parent);
  40. ~LayoutLineBox();
  41. /// Closes the line box, positioning all inline elements within it.
  42. /// @param overflow[in] The overflow box from a split inline box that caused this line to close. Leave this as nullptr if we closed naturally.
  43. /// @return If there was any overflow, this will be the last element generated by the spilling content. Otherwise, this will be nullptr.
  44. LayoutInlineBox* Close(UniquePtr<LayoutInlineBox> overflow = nullptr);
  45. /// Closes one of the line box's inline boxes.
  46. /// @param inline_box[in] The inline box to close. This should always be the line box's open box.
  47. void CloseInlineBox(LayoutInlineBox* inline_box);
  48. /// Attempts to add a new element to this line box. If it can't fit, or needs to be split, new line boxes will
  49. /// be created. The inline box for the final section of the element will be returned.
  50. /// @param element[in] The element to fit into this line box.
  51. /// @param box[in] The element's extents.
  52. /// @return The inline box for the element.
  53. LayoutInlineBox* AddElement(Element* element, const Box& box);
  54. /// Attempts to add a new inline box to this line. If it can't fit, or needs to be split, new line boxes will
  55. /// be created. The inline box for the final section of the element will be returned.
  56. /// @param box[in] The inline box to be added to the line.
  57. /// @return The final inline box.
  58. LayoutInlineBox* AddBox(UniquePtr<LayoutInlineBox> box);
  59. /// Adds an inline box as a chained hierarchy overflowing to this line. The chain will be extended into
  60. /// this line box.
  61. /// @param split_box[in] The box overflowed from a previous line.
  62. void AddChainedBox(LayoutInlineBox* chained_box);
  63. /// Returns the position of the line box, relative to its parent's block box's content area.
  64. /// @return The position of the line box.
  65. Vector2f GetPosition() const;
  66. /// Returns the position of the line box, relative to its parent's block box's offset parent.
  67. /// @return The relative position of the line box.
  68. Vector2f GetRelativePosition() const;
  69. /// Returns the dimensions of the line box.
  70. /// @return The dimensions of the line box.
  71. Vector2f GetDimensions() const;
  72. /// Returns the line box's open inline box.
  73. /// @return The line's open inline box, or nullptr if it currently has none.
  74. LayoutInlineBox* GetOpenInlineBox();
  75. /// Returns the line's containing block box.
  76. /// @return The line's block box.
  77. LayoutBlockBox* GetBlockBox();
  78. float GetBoxCursor() const;
  79. bool GetBaselineOfLastLine(float& baseline) const;
  80. void* operator new(size_t size);
  81. void operator delete(void* chunk, size_t size);
  82. private:
  83. /// Appends an inline box to the end of the line box's list of inline boxes. Returns a pointer to the appended box.
  84. LayoutInlineBox* AppendBox(UniquePtr<LayoutInlineBox> box);
  85. using InlineBoxList = Vector< UniquePtr<LayoutInlineBox> >;
  86. // The block box containing this line.
  87. LayoutBlockBox* parent;
  88. // The top-left position of the line box; this is set when the first inline box is placed.
  89. Vector2f position;
  90. bool position_set;
  91. // The width and height of the line box; this is set when the line box is placed.
  92. Vector2f dimensions;
  93. bool wrap_content;
  94. // The horizontal cursor. This is where the next inline box will be placed along the line.
  95. float box_cursor;
  96. // The list of inline boxes in this line box. These line boxes may be parented to others in this list.
  97. InlineBoxList inline_boxes;
  98. // The open inline box; this is nullptr if all inline boxes are closed.
  99. LayoutInlineBox* open_inline_box;
  100. };
  101. } // namespace Rml
  102. #endif