LayoutEngine.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. #include "LayoutEngine.h"
  2. #include "../../../Include/RmlUi/Core/Element.h"
  3. #include "../../../Include/RmlUi/Core/Log.h"
  4. #include "../../../Include/RmlUi/Core/Profiling.h"
  5. #include "ContainerBox.h"
  6. #include "FormattingContext.h"
  7. namespace Rml {
  8. void LayoutEngine::FormatElement(Element* element, Vector2f containing_block)
  9. {
  10. RMLUI_ASSERT(element && containing_block.x >= 0 && containing_block.y >= 0);
  11. RootBox root(containing_block);
  12. auto layout_box = FormattingContext::FormatIndependent(&root, element, nullptr, FormattingContextType::Block);
  13. if (!layout_box)
  14. {
  15. Log::Message(Log::LT_ERROR, "Error while formatting element: %s", element->GetAddress().c_str());
  16. }
  17. {
  18. RMLUI_ZoneScopedN("ClampScrollOffsetRecursive");
  19. // The size of the scrollable area might have changed, so clamp the scroll offset to avoid scrolling outside the
  20. // scrollable area. During layouting, we might be changing the scrollable overflow area of the element several
  21. // times, such as after enabling scrollbars. For this reason, we don't clamp the scroll offset during layouting,
  22. // as that could inadvertently clamp it to a temporary size. Now that we know the final layout, including the
  23. // size of each element's scrollable area, we can finally clamp the scroll offset.
  24. element->ClampScrollOffsetRecursive();
  25. }
  26. }
  27. } // namespace Rml