LayoutLineBox.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 RMLUICORELAYOUTLINEBOX_H
  29. #define RMLUICORELAYOUTLINEBOX_H
  30. #include "LayoutInlineBox.h"
  31. namespace Rml {
  32. namespace Core {
  33. class LayoutBlockBox;
  34. /**
  35. @author Peter Curry
  36. */
  37. class LayoutLineBox
  38. {
  39. public:
  40. LayoutLineBox(LayoutBlockBox* parent);
  41. ~LayoutLineBox();
  42. /// Closes the line box, positioning all inline elements within it.
  43. /// @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.
  44. /// @return If there was any overflow, this will be the last element generated by the spilling content. Otherwise, this will be nullptr.
  45. LayoutInlineBox* Close(LayoutInlineBox* overflow = nullptr);
  46. /// Closes one of the line box's inline boxes.
  47. /// @param inline_box[in] The inline box to close. This should always be the line box's open box.
  48. void CloseInlineBox(LayoutInlineBox* inline_box);
  49. /// Attempts to add a new element to this line box. If it can't fit, or needs to be split, new line boxes will
  50. /// be created. The inline box for the final section of the element will be returned.
  51. /// @param element[in] The element to fit into this line box.
  52. /// @param box[in] The element's extents.
  53. /// @return The inline box for the element.
  54. LayoutInlineBox* AddElement(Element* element, const Box& box);
  55. /// Attempts to add a new inline box to this line. If it can't fit, or needs to be split, new line boxes will
  56. /// be created. The inline box for the final section of the element will be returned.
  57. /// @param box[in] The inline box to be added to the line.
  58. /// @return The final inline box.
  59. LayoutInlineBox* AddBox(LayoutInlineBox* box);
  60. /// Adds an inline box as a chained hierarchy overflowing to this line. The chain will be extended into
  61. /// this line box.
  62. /// @param split_box[in] The box overflowed from a previous line.
  63. void AddChainedBox(LayoutInlineBox* chained_box);
  64. /// Returns the position of the line box, relative to its parent's block box's content area.
  65. /// @return The position of the line box.
  66. const Vector2f& GetPosition() const;
  67. /// Returns the position of the line box, relative to its parent's block box's offset parent.
  68. /// @return The relative position of the line box.
  69. Vector2f GetRelativePosition() const;
  70. /// Returns the dimensions of the line box.
  71. /// @return The dimensions of the line box.
  72. const Vector2f& GetDimensions() const;
  73. /// Returns the line box's open inline box.
  74. /// @return The line's open inline box, or nullptr if it currently has none.
  75. LayoutInlineBox* GetOpenInlineBox();
  76. /// Returns the line's containing block box.
  77. /// @return The line's block box.
  78. LayoutBlockBox* GetBlockBox();
  79. float GetBoxCursor() const;
  80. void* operator new(size_t size);
  81. void operator delete(void* chunk);
  82. private:
  83. /// Appends an inline box to the end of the line box's list of inline boxes.
  84. void AppendBox(LayoutInlineBox* box);
  85. typedef std::vector< LayoutInlineBox* > InlineBoxList;
  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. }
  102. }
  103. #endif