fix documentlayout by requiring fixed width of target

This commit is contained in:
hippoz 2022-10-28 19:46:33 +03:00
parent fc59ad6e10
commit abbedd9db1
No known key found for this signature in database
GPG key ID: 7C52899193467641

View file

@ -1,6 +1,7 @@
#include "DocumentLayout.hpp"
#include "Point.hpp"
#include "Widget.hpp"
#include "src/Events.hpp"
#include <iostream>
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;
}
}