Project

General

Profile

Improvements #11001 ยป flexbox_spacing.cpp

Roel Standaert, 10/12/2022 04:10 PM

 
#include <Wt/WApplication.h>
#include <Wt/WColor.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WCssDecorationStyle.h>
#include <Wt/WHBoxLayout.h>
#include <Wt/WText.h>
#include <Wt/WVBoxLayout.h>

#include <memory>

class Application final : public Wt::WApplication {
public:
explicit Application(const Wt::WEnvironment& env);

void initialize() override;
};

Application::Application(const Wt::WEnvironment &env)
: Wt::WApplication(env)
{}

void Application::initialize()
{
auto vLayout = root()->setLayout(std::make_unique<Wt::WVBoxLayout>());

vLayout->setContentsMargins(0, 0, 0, 0);
vLayout->setSpacing(0);

auto description = vLayout->addWidget(std::make_unique<Wt::WText>(), 0);
description->setTextFormat(Wt::TextFormat::XHTML);
description->setText(Wt::utf8(
"<h1>Box layout inconsistency</h1>"
"<p>Note the difference between flex implementation (top), "
"and JS implementation (bottom)</p>"));

auto top = vLayout->addWidget(std::make_unique<Wt::WContainerWidget>(), 1);
auto bottom = vLayout->addWidget(std::make_unique<Wt::WContainerWidget>(), 1);

for (auto& container : {top, bottom}){
auto layout = container->setLayout(std::make_unique<Wt::WHBoxLayout>());

if (container == bottom) {
layout->setPreferredImplementation(Wt::LayoutImplementation::JavaScript);
}

layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(40);

auto container1 = layout->addWidget(std::make_unique<Wt::WContainerWidget>());
auto container2 = layout->addWidget(std::make_unique<Wt::WContainerWidget>());
auto container3 = layout->addWidget(std::make_unique<Wt::WContainerWidget>());

container1->decorationStyle().setBackgroundColor(Wt::StandardColor::Red);
container2->decorationStyle().setBackgroundColor(Wt::StandardColor::Green);
container3->decorationStyle().setBackgroundColor(Wt::StandardColor::Blue);
}
}

int main(int argc, char** argv)
{
return Wt::WRun(argc, argv, [](const Wt::WEnvironment& env) {
return std::make_unique<Application>(env);
});
}
    (1-1/1)