diff --git a/src/HorizontalBoxLayout.cpp b/src/HorizontalBoxLayout.cpp index 8c09728..d5e5813 100644 --- a/src/HorizontalBoxLayout.cpp +++ b/src/HorizontalBoxLayout.cpp @@ -28,8 +28,6 @@ void HorizontalBoxLayout::run() { child->rect().set_x(current_point.x()); child->rect().set_y(current_point.y()); - //std::cout << child->rect().x() << ", " << child->rect().y() << ", " << child->rect().width() << ", " << child->rect().height() << std::endl; - current_point.add(child->rect().width() + m_margin, 0); } diff --git a/src/VerticalBoxLayout.cpp b/src/VerticalBoxLayout.cpp index d7c551d..c0b83f4 100644 --- a/src/VerticalBoxLayout.cpp +++ b/src/VerticalBoxLayout.cpp @@ -9,19 +9,30 @@ void VerticalBoxLayout::run() { return; } - Point current_point { m_target->rect().x() + m_margin, m_target->rect().y() + m_margin }; - + Point current_point { m_margin, m_margin }; + double max_width_so_far = 0; + double requested_height = 0; + auto& children = m_target->children(); for (auto child : children) { if (child->absolute()) { continue; } + if (child->rect().width() > max_width_so_far) { + max_width_so_far = child->rect().height(); + } + + requested_height += child->rect().height() + m_margin; + child->rect().set_x(current_point.x()); child->rect().set_y(current_point.y()); current_point.add(0, child->rect().height() + m_margin); } + + m_target->rect().set_height(requested_height + m_margin); + m_target->rect().set_width(max_width_so_far + m_margin * 2); } } diff --git a/src/main.cpp b/src/main.cpp index f495601..be0d1f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,7 +8,9 @@ #include "RGB.hpp" #include "DocumentLayout.hpp" #include "Events.hpp" +#include "src/HorizontalBoxLayout.hpp" #include "src/Styles.hpp" +#include "src/VerticalBoxLayout.hpp" #include #include #include @@ -18,37 +20,19 @@ int main() { window.spawn_window(); auto main_widget = window.set_main_widget(); - main_widget->set_layout(10.0); + main_widget->set_layout(6.0); - auto second_widget = main_widget->add(); - second_widget->set_layout(20.0); - second_widget->resize(800, 800); + for (int i = 0; i < 12; i++) { + auto row = main_widget->add(); + row->set_layout(6.0); + for (int i = 0; i < 12; i++) { + auto button = row->add("0"); - auto inner_widget = second_widget->add(); - inner_widget->set_layout(8.0); - inner_widget->resize(600, 600); - - int number = 0; - - for (int i = 0; i < 250; i++) { - auto button = inner_widget->add("click me"); - button->set_style(&Raven::accent_button_style); - auto label = inner_widget->add("click one of the buttons!"); - button->on_click = [&]() { - number += 10; - - window.start_batch(); - auto& children = inner_widget->children(); - for (auto& child : children) { - if (child->type() == Raven::WidgetType::Button) { - std::static_pointer_cast(child)->set_text(std::to_string(number)); - } - if (child->type() == Raven::WidgetType::Label) { - std::static_pointer_cast(child)->set_text(std::to_string(number)); - } - } - window.end_batch(); - }; + button->on_click = [button]() { + int number = std::stoi(button->text()); + button->set_text(std::to_string(++number)); + }; + } } window.run(true);