Project

General

Profile

Bug #13958 ยป main.cpp

Michael Seibt, 02/09/2026 01:09 PM

 
#include <Wt/WApplication.h>
#include <Wt/WBootstrap5Theme.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WGridLayout.h>
#include <Wt/WHBoxLayout.h>
#include <Wt/WPanel.h>
#include <Wt/WPushButton.h>
#include <Wt/WServer.h>
#include <Wt/WText.h>
#include <Wt/WVBoxLayout.h>

using namespace std;
using namespace Wt;

#define SET_BS5THEME 1

// Always apply theme before creating widgets!
class CThemedApplication : public WApplication
{
public:
CThemedApplication(const WEnvironment& rcEnv)
: WApplication{rcEnv}
{
#if SET_BS5THEME
setTheme(make_shared<WBootstrap5Theme>());
#endif
}
};

template<typename T, typename... TArgs>
constexpr inline
std::unique_ptr<T> create(std::function<void (T&)>&& fInitialize, TArgs&&... args)
{
std::unique_ptr<T> Ptr{std::make_unique<T>(std::forward<TArgs>(args)...)};
fInitialize(*Ptr);
return Ptr;
}

class CApplication final : public CThemedApplication
{
public:
CApplication(const WEnvironment& rcEnv);

private:
WServer& _Server; //!< The associated WServer instance, needed for async operations.

WContainerWidget& _cntRoot{*root()};
WBoxLayout& _lytRoot{*_cntRoot.setLayout(make_unique<WVBoxLayout>())};

WPushButton& _btnP{*_lytRoot.addWidget(create<WPushButton>([this](auto& btnP)
{
btnP.clicked().connect([this] { _pnlBottom.setDisabled(true); });
}, "Enable bottom panel"))};

WPanel& _pnlBottom{*_lytRoot.addWidget(create<WPanel>([this](auto&)
{
_lytRoot.addStretch(100);
}))};
WContainerWidget& _cntBottom{*_pnlBottom.setCentralWidget(make_unique<WContainerWidget>())};
WBoxLayout& _lytBottom{*_cntBottom.setLayout(make_unique<WHBoxLayout>())};

WPushButton& _btnDummy{*_lytBottom.addWidget(make_unique<WPushButton>("Dummy button just in order to avoid somebody saying the final stretch would not make sense"))};
};

CApplication::CApplication(const WEnvironment& rcEnv)
: CThemedApplication{rcEnv}
, _Server{*environment().server()}
{
setTitle("bug repro");

_lytBottom.addStretch(100);

_pnlBottom.setDisabled(true);

// final action after creating the UI
enableUpdates();
}

int main(int argc, char* argv[])
{
return WRun(argc, argv, [](const WEnvironment& rcEnv)
{
try
{
return make_unique<CApplication>(rcEnv);
}
catch (const std::exception& rcException)
{
cerr << "exception " << typeid(remove_cvref<decltype(rcException)>::type).name() << ": " << rcException.what() << endl;

#if DEBUG
exit(-1);
#endif
throw;
}
});
}
    (1-1/1)