From abbedd9db10a4495960b2a48dd6c7dd42f3ae80d Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Fri, 28 Oct 2022 19:46:33 +0300 Subject: [PATCH] fix documentlayout by requiring fixed width of target --- src/DocumentLayout.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/DocumentLayout.cpp b/src/DocumentLayout.cpp index f401993..6b304f7 100644 --- a/src/DocumentLayout.cpp +++ b/src/DocumentLayout.cpp @@ -1,6 +1,7 @@ #include "DocumentLayout.hpp" #include "Point.hpp" #include "Widget.hpp" +#include "src/Events.hpp" #include namespace Raven { @@ -9,15 +10,20 @@ bool DocumentLayout::run() { if (!m_target) return false; - Point bound { m_margin + m_target->rect().max_geometry().width(), m_margin }; Point current_position { m_margin, m_margin }; double largest_height_so_far = -1.0; + double desired_height = m_margin * 2; auto& children = m_target->children(); for (auto child : children) { if (child->absolute()) continue; + if (child->layout() && child->layout()->dynamically_sizes_target()) { + auto event = RelayoutSubtreeEvent(); + child->dispatch_event(event); + } + if (child->rect().height() > largest_height_so_far) { largest_height_so_far = child->rect().height(); } @@ -27,7 +33,7 @@ bool DocumentLayout::run() { bool should_do_new_row = new_row_because_of_control_widget || new_row_because_of_justification; if (should_do_new_row) { current_position.add(0, largest_height_so_far + m_margin); - bound.add(0, largest_height_so_far + m_margin); + desired_height += largest_height_so_far + m_margin; current_position.set_x(m_margin); } @@ -39,13 +45,17 @@ bool DocumentLayout::run() { } } + for (auto &child : m_target->children()) { + auto event = RelayoutSubtreeEvent(); + child->dispatch_event(event); + } + /* account for the first row */ - bound.add(0, largest_height_so_far); + desired_height += largest_height_so_far; - m_target->rect().set_width(bound.x()); - m_target->rect().set_height(bound.y()); + m_target->rect().set_height(desired_height); - return false; + return true; } }