LayoutBlockBoxSpace.h 4.6 KB

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