make DocumentLayout responsive in regards to the parent's width
This commit is contained in:
parent
5d672e9eec
commit
3039646b6b
3 changed files with 19 additions and 16 deletions
|
@ -9,22 +9,26 @@ void DocumentLayout::run() {
|
|||
if (!m_target)
|
||||
return;
|
||||
|
||||
Point point { m_target->current_geometry().x() + m_margin, m_target->current_geometry().y() + m_margin };
|
||||
double row_largest_height = 0.0;
|
||||
Point current_position { m_target->current_geometry().x() + m_margin, m_target->current_geometry().y() + m_margin };
|
||||
double largest_height_so_far = -1.0;
|
||||
auto& children = m_target->children();
|
||||
|
||||
auto children = m_target->children();
|
||||
for (auto& c : children) {
|
||||
if (c->control_type() == ControlWidgetType::NewRow && row_largest_height) {
|
||||
point.add(0, row_largest_height + m_margin);
|
||||
row_largest_height = 0.0;
|
||||
point.set_x(0);
|
||||
for (auto& child : children) {
|
||||
if (child->current_geometry().height() > largest_height_so_far) {
|
||||
largest_height_so_far = child->current_geometry().height();
|
||||
}
|
||||
if (c->current_geometry().height() > row_largest_height) {
|
||||
row_largest_height = c->current_geometry().height();
|
||||
|
||||
bool new_row_because_of_control_widget = (child->control_type() == ControlWidgetType::NewRow && largest_height_so_far);
|
||||
bool new_row_because_of_justification = (current_position.x() + child->current_geometry().width() + m_margin) >= m_target->current_geometry().width();
|
||||
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);
|
||||
current_position.set_x(m_margin);
|
||||
}
|
||||
c->current_geometry().set_x(point.x());
|
||||
c->current_geometry().set_y(point.y());
|
||||
point.add(c->current_geometry().width() + m_margin, 0);
|
||||
|
||||
child->current_geometry().set_x(current_position.x());
|
||||
child->current_geometry().set_y(current_position.y());
|
||||
current_position.add(child->current_geometry().width() + m_margin, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ void Window::run(bool block) {
|
|||
m_main_widget->current_geometry().set_width(m_current_geometry.width());
|
||||
m_main_widget->current_geometry().set_height(m_current_geometry.height());
|
||||
}
|
||||
dispatch_full_repaint();
|
||||
dispatch_full_relayout();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@ int main() {
|
|||
|
||||
int number = 0;
|
||||
|
||||
window.spawn_window();
|
||||
|
||||
add_button->on_click = [&]() {
|
||||
number++;
|
||||
label->set_text(std::to_string(number));
|
||||
|
@ -32,6 +30,7 @@ int main() {
|
|||
label->set_text(std::to_string(number));
|
||||
};
|
||||
|
||||
window.spawn_window();
|
||||
window.run(true);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue