document layout automatic resize
This commit is contained in:
parent
a1f544ae82
commit
72720d216d
2 changed files with 18 additions and 6 deletions
|
@ -9,6 +9,7 @@ void DocumentLayout::run() {
|
||||||
if (!m_target)
|
if (!m_target)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Point bound { m_margin * 2, m_margin * 2 };
|
||||||
Point current_position { m_margin, m_margin };
|
Point current_position { m_margin, m_margin };
|
||||||
double largest_height_so_far = -1.0;
|
double largest_height_so_far = -1.0;
|
||||||
|
|
||||||
|
@ -22,10 +23,11 @@ void DocumentLayout::run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool new_row_because_of_control_widget = (child->control_type() == ControlWidgetType::NewRow);
|
bool new_row_because_of_control_widget = (child->control_type() == ControlWidgetType::NewRow);
|
||||||
bool new_row_because_of_justification = (current_position.x() + child->rect().width() + m_margin) >= m_target->rect().width();
|
bool new_row_because_of_justification = (current_position.x() + child->rect().width() + m_margin) >= m_target->rect().max_geometry().width();
|
||||||
bool should_do_new_row = new_row_because_of_control_widget || new_row_because_of_justification;
|
bool should_do_new_row = new_row_because_of_control_widget || new_row_because_of_justification;
|
||||||
if (should_do_new_row) {
|
if (should_do_new_row) {
|
||||||
current_position.add(0, largest_height_so_far + m_margin);
|
current_position.add(0, largest_height_so_far + m_margin);
|
||||||
|
bound.add(0, largest_height_so_far + m_margin);
|
||||||
current_position.set_x(m_margin);
|
current_position.set_x(m_margin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +36,12 @@ void DocumentLayout::run() {
|
||||||
|
|
||||||
if (!new_row_because_of_control_widget) {
|
if (!new_row_because_of_control_widget) {
|
||||||
current_position.add(child->rect().width() + m_margin, 0);
|
current_position.add(child->rect().width() + m_margin, 0);
|
||||||
|
bound.add(child->rect().width() + m_margin, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_target->rect().set_width(bound.x());
|
||||||
|
m_target->rect().set_height(bound.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
16
src/main.cpp
16
src/main.cpp
|
@ -23,11 +23,17 @@ int main() {
|
||||||
auto main_widget = window.set_main_widget<Raven::Widget>();
|
auto main_widget = window.set_main_widget<Raven::Widget>();
|
||||||
main_widget->set_layout<Raven::VerticalBoxLayout>(6.0);
|
main_widget->set_layout<Raven::VerticalBoxLayout>(6.0);
|
||||||
|
|
||||||
auto compile_button = main_widget->add<Raven::Button>("compile and run program");
|
auto scroll = main_widget->add<Raven::ScrollContainer>();
|
||||||
compile_button->set_style(&Raven::accent_button_style);
|
scroll->set_style(&Raven::accent_widget_style);
|
||||||
compile_button->on_click = []() {
|
scroll->resize(200, 200);
|
||||||
system("./compile.sh");
|
auto target = scroll->make_target();
|
||||||
};
|
target->set_layout<Raven::VerticalBoxLayout>(8.0);
|
||||||
|
target->rect().set_max_width(200);
|
||||||
|
|
||||||
|
for (int i = 0; i < 300; i++) {
|
||||||
|
auto button = target->add<Raven::Button>(std::to_string(i));
|
||||||
|
button->set_style(&Raven::accent_button_style);
|
||||||
|
}
|
||||||
|
|
||||||
window.run(true);
|
window.run(true);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue