Project

General

Profile

Some problems with WBoxLayout manager

Added by Ali Ali 24 days ago

Hello

Consider the following code:

auto topBox = std::make_unique<Wt::WcontainerWidget>();
auto topLayout = topBox->setLayout<Wt::WVBoxLayout>(std::make_unique<Wt::WVBoxLayout>());
//Add some widgets to topLayout ...
auto bottomBox = std::make_unique<Wt::WContainerWidget>();
auto bottomLayout = bottomBox->setLayout<Wt::WVBoxLayout>(std::make_unique<Wt::WVBoxLayout>());
auto bottomContents = bottomLayout->addLayout<Wt::WVBoxLayout>(std::make_unique<Wt::WVBoxLayout>(), 1, Wt::AlignmentFlag::Top);
bottomContents->setObjectName ("bottomContent");
bottomContents->setSpacing (50);
auto text = bottomContents->addWidget<Wt::WText> (std::make_unique<Wt::WText>(test), 1, Wt::AlignmentFlag::Center);
auto btn = bottomContents->addWidget<Wt::WPushButton>(std::make_unique<Wt::WPushButton>("register"), 0, Wt::AlignmentFlag::Center);

1-> When "bottomContents->setSpacing (50);" is added, topLayout and bottomLayout overlap. In fact, the margin-top value of bottomLayout becomes −25. After checking the FlexLayoutImpl.C file and commenting out the following codes:

Orientation elOrientation = flexImpl->getOrientation();
if (elOrientation == Orientation::Horizontal) {
m[3] -= (flexImpl->grid_.horizontalSpacing_) / 2;
m[1] -= (flexImpl->grid_.horizontalSpacing_ + 1) / 2;
} else {
m[0] -= (flexImpl->grid_.verticalSpacing_) / 2;
m[2] -= (flexImpl->grid_.horizontalSpacing_ + 1) / 2;
}

In the FlexLayoutImpl::createElement() method, the problem was solved. What is the purpose of these codes?

2-> It seems that m[2] -= (flexImpl->grid_.horizontalSpacing_ + 1) / 2 in the above code snippet is wrong and should be m[2] -= (flexImpl->grid_.verticalSpacing_ + 1) / 2; (In any case, I think all these lines are redundant.).

3-> The bottomContents->setObjectName ("bottomContent"); doesn't change the name of DOM element.

Overall, it seems that the Layout Manager implementation as flexbox is in beta as I have found several issues with it, especially when the application direction is rtl. I have filed a few bugs and PRs to fix them.


Replies (1)

RE: Some problems with WBoxLayout manager - Added by Matthias Van Ceulebroeck about 23 hours ago

Hello Ali,

I believe that the Flex layout is the newest of the layouts, and that there are indeed still various small issues with it.

  1. This was likely meant to ensure that spacing applies a margin to each element. So that spacing of e.g. 50 results in 50 pixels of spacing for two elements. So I think the spacings should be +25px here, not -25px. (see #13670)
  2. Yes, that seems correct.
  3. It seems setObjectName is only specified in WWebWidget, so it will only affect the widgets, not layouts. That is a bug, I have filed (#13669) for it.

I will review your PRs soon, after Wt 4.11.4 has been released.

Best,
Matthias

    (1-1/1)