LayoutBlockBoxSpace.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_LAYOUTBLOCKBOXSPACE_H
  29. #define RMLUI_CORE_LAYOUTBLOCKBOXSPACE_H
  30. #include "../../Include/RmlUi/Core/ComputedValues.h"
  31. #include "../../Include/RmlUi/Core/Types.h"
  32. namespace Rml {
  33. class Element;
  34. class LayoutBlockBox;
  35. /**
  36. Each block box has a space object for managing the space occupied by its floating elements, and those of its
  37. ancestors as relevant.
  38. @author Peter Curry
  39. */
  40. class LayoutBlockBoxSpace
  41. {
  42. public:
  43. LayoutBlockBoxSpace(LayoutBlockBox* parent);
  44. ~LayoutBlockBoxSpace();
  45. /// Imports boxes from another block into this space.
  46. /// @param[in] space The space to import boxes from.
  47. void ImportSpace(const LayoutBlockBoxSpace& space);
  48. /// Generates the position for a box of a given size within our block box.
  49. /// @param[out] box_position The generated position for the box.
  50. /// @param[out] box_width The available width for the box.
  51. /// @param[in] cursor The ideal vertical position for the box.
  52. /// @param[in] dimensions The minimum available space required for the box.
  53. void PositionBox(Vector2f& box_position, float& box_width, float cursor, Vector2f dimensions) const;
  54. /// Generates and sets the position for a floating box of a given size within our block box. The element's box
  55. /// is then added into our list of floating boxes.
  56. /// @param[in] cursor The ideal vertical position for the box.
  57. /// @param[in] element The element to position.
  58. /// @return The offset of the bottom outer edge of the element.
  59. float PositionBox(float cursor, Element* element);
  60. /// Determines the appropriate vertical position for an object that is choosing to clear floating elements to
  61. /// the left or right (or both).
  62. /// @param[in] cursor The ideal vertical position.
  63. /// @param[in] clear_property The value of the clear property of the clearing object.
  64. /// @return The appropriate vertical position for the clearing object.
  65. float ClearBoxes(float cursor, Style::Clear clear_property) const;
  66. /// Returns the top-left corner of the boxes within the space.
  67. /// @return The space's offset.
  68. Vector2f GetOffset() const;
  69. /// Returns the dimensions of the boxes within the space.
  70. /// @return The space's dimensions.
  71. Vector2f GetDimensions() const;
  72. void* operator new(size_t size);
  73. void operator delete(void* chunk, size_t size);
  74. private:
  75. enum AnchorEdge
  76. {
  77. LEFT = 0,
  78. RIGHT = 1,
  79. NUM_ANCHOR_EDGES = 2
  80. };
  81. /// Generates the position for an arbitrary box within our space layout, floated against either the left or
  82. /// right edge.
  83. /// @param box_position[out] The generated position for the box.
  84. /// @param cursor[in] The ideal vertical position for the box.
  85. /// @param dimensions[in] The size of the box to place.
  86. /// @return The maximum width at the box position.
  87. float PositionBox(Vector2f& box_position, float cursor, Vector2f dimensions, Style::Float float_property = Style::Float::None) const;
  88. struct SpaceBox
  89. {
  90. SpaceBox();
  91. SpaceBox(Vector2f offset, Vector2f dimensions);
  92. Vector2f offset;
  93. Vector2f dimensions;
  94. };
  95. using SpaceBoxList = Vector< SpaceBox >;
  96. // Our block-box parent.
  97. LayoutBlockBox* parent;
  98. // The boxes floating in our space.
  99. SpaceBoxList boxes[NUM_ANCHOR_EDGES];
  100. // The offset and dimensions of the boxes added specifically into this space.
  101. Vector2f offset;
  102. Vector2f dimensions;
  103. };
  104. } // namespace Rml
  105. #endif