Project

General

Profile

Actions

Bug #8335

closed

layoutSizeChanged stops being called after widgets rearrangement

Added by Andrii Zhuk over 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
Start date:
04/12/2021
Due date:
% Done:

100%

Estimated time:

Description

The goal is to update widget positions after width>height or height>width (kind of desktop vs mobile version)
I have the code:

    InteractiveContainer::InteractiveContainer()
    {
        rearrange(ratio_); // Initially is 1.0f
    }

    void InteractiveContainer::layoutSizeChanged (int width, int height)
    {
        const float ratio = (float)width / (float)height;
        bool needResize = (ratio > ratio_*1.1f) || (ratio < ratio_*0.9f); // check for 10% deviation
        LOG(logINFO) << "Need resize: " << needResize << " (" << ratio << ")";
        if (needResize || !resized_)
        {
            LOG(logINFO) << "Layout has been changed: w" << width << " h" << height;
            optionsSection_->setWidth(width/5); // TODO magic number
            optionsSection_->setRatio(ratio);

            const bool needRearange = ((ratio>=1.0f)^(ratio_>=1.0f));
            if (needRearange) rearrange(ratio);

            resized_ = true;
            ratio_ = ratio;
        }//if
    }

    void InteractiveContainer::rearrange(float ratio)
    {
        LOG(logINFO) << "Rearrange called for ratio: " << ratio;
        setStyleClass(CssStyleTypes::interactiveContainer(ratio_)); // style is also changed depending on ratio

        // detach widgets
        auto chat = chatContainer_ ? static_cast<ChatContainer*>(layout_->removeWidget(chatContainer_).release()) : nullptr;
        auto options = optionsSection_ ? static_cast<OptionsContainer*>(layout_->removeWidget(optionsSection_).release()) : nullptr;

        // create or attach widgets
        if (ratio >= 1.0f)
            layout_ = setLayout(Wt::cpp14::make_unique<Wt::WHBoxLayout>());
        else
            layout_ = setLayout(Wt::cpp14::make_unique<Wt::WVBoxLayout>());

        chatContainer_ = layout_->addWidget(chat ? std::unique_ptr<ChatContainer>(chat) : Wt::cpp14::make_unique<ChatContainer>(), 1);
        optionsSection_ = layout_->addWidget(options ? std::unique_ptr<OptionsContainer>(options) : Wt::cpp14::make_unique<OptionsContainer>());
        setLayoutSizeAware(true);
    }

At first layoutSizeChanged is called with making width smaller. So transformation from desktop to mobile version is successful, but when the width grows after this (first rearrange call), layoutSizeChanged is never called anymore.

Need resize: 1 (1.06309)
Layout has been changed: w674 h634
Need resize: 0 (1.05047)
Need resize: 0 (1.04416)
Need resize: 0 (1.01262)
Need resize: 0 (1.00631)
Need resize: 0 (0.995268)
Need resize: 0 (0.985804)
Need resize: 0 (0.974763)
Need resize: 0 (0.968454)
Need resize: 0 (0.958991)
Need resize: 1 (0.919558)
Layout has been changed: w583 h634
Rearrange called for ratio: 0.919558
Need resize: 0 (0.87224)
Need resize: 0 (0.854688)

Expected behavior: layoutSizeChanged is called after widgets rearrangement


Files

wtresize.tar.gz (4.59 KB) wtresize.tar.gz Andrii Zhuk, 04/14/2021 11:15 AM
Actions #1

Updated by Korneel Dumon over 3 years ago

Hi Andrii,

is it possible to make a small example program?

Actions #2

Updated by Andrii Zhuk over 3 years ago

Korneel Dumon wrote in #note-1:

Hi Andrii,

is it possible to make a small example program?

Hi Korneel,
Yeap, I think it is possible.

Actions #3

Updated by Andrii Zhuk over 3 years ago

Korneel Dumon wrote in #note-1:

Hi Andrii,

is it possible to make a small example program?

I have create demo project, see attachment. There is README file inside with build instructions.

Some highlights:
To build (recommended) it with similar environment you need conan > 1.28 and clang 6.0
conan uses wt 4.5.0

pure cmake was not tested and may not work
but you may try with cmake CmakeList.txt

Actions #4

Updated by Andrii Zhuk over 3 years ago

About cmake CmakeList.txt

There is hard stub for usage conan build inside src/CmakeList.txt

option(WITH_CONAN "Switch conan build" ON)

change it to OFF if you want to try

Actions #5

Updated by Korneel Dumon over 3 years ago

  • Status changed from New to Implemented @Emweb

Thanks for the code, it was very helpful. For now, you can work around this using WLayout::setPreferredImplementation(LayoutImplementation::JavaScript)

Actions #6

Updated by Roel Standaert over 3 years ago

  • Status changed from Implemented @Emweb to Resolved
  • Target version set to 4.6.0
Actions #7

Updated by Roel Standaert over 3 years ago

  • Target version changed from 4.6.0 to 4.5.1
Actions #8

Updated by Roel Standaert over 3 years ago

  • % Done changed from 0 to 100
Actions #9

Updated by Roel Standaert about 3 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF