Skip to content

Fix incorrect behavior of minimum size for yoga layout - #814

Merged
a7ul merged 1 commit into
nodegui:masterfrom
apsislabs:bugfix/592-flex-layout
Feb 25, 2021
Merged

a7ul merged 1 commit into
nodegui:masterfrom
apsislabs:bugfix/592-flex-layout

Conversation

@wkirby

@wkirby wkirby commented Feb 25, 2021

Copy link
Copy Markdown
Contributor

This is a prospective fix for #592.

The original buggy behavior can be tracked back to some calls to calculateLayout without properly setting the width of sizeControlled nodes. The fix here:

  1. Takes the provided QRect and sets height and width in Yoga instead of minimum height and width
  2. Updates the minimumSize method to ask Yoga for the minimum height and width instead of the current height and width

These changes, by my testing, fix two bugs:

  1. The jumpy layout as reported in FlexLayout indeterminate behavior #592
  2. An apparently un-reported bug where the initial size of a QMainWindow is artificially treated as its minimum size.

A test application to validate the expected behavior can be found here, slightly modified from the file in #592.

import { QMainWindow, QWidget } from '.';
import { QPushButton } from './lib/QtWidgets/QPushButton';
import { FlexLayout } from './lib/core/FlexLayout';

const win = new QMainWindow();
win.resize(500, 500);
win.setMinimumSize(200, 200);

const centralWidget = new QWidget();
const centralLayout = new FlexLayout();
centralLayout.setFlexNode(centralWidget.getFlexNode());
centralWidget.setLayout(centralLayout);

const outer = new QWidget();
const outerLayout = new FlexLayout();
outerLayout.setFlexNode(outer.getFlexNode());
outer.setLayout(outerLayout);

const inner = new QWidget();
const innerLayout = new FlexLayout();
innerLayout.setFlexNode(inner.getFlexNode());
inner.setLayout(innerLayout);


const button = new QPushButton();
button.addEventListener('clicked', () => {
    button.setText(button.text() === 'Toggle On' ? 'Toggle Off' : 'Toggle On');
});
button.setText('Toggle On');

innerLayout.addWidget(button);
outerLayout.addWidget(inner);
centralLayout.addWidget(outer);

centralWidget.setInlineStyle('background-color: red');
outer.setInlineStyle('background-color: blue');
inner.setInlineStyle('background-color: green');

// Add central to window
win.setCentralWidget(centralWidget);
win.show();
(global as any).win = win;

if (isSizeControlled) {
restoreNodeMinStyle(prevStyleMinWidth, prevStyleMinHeight);
}
QRect calculatedRect = flexutils::getFlexNodeGeometry(this->node);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work!
This is what I have not done before

QRect calculatedRect = flexutils::getFlexNodeGeometry(this->node);

For some reason I thought rect passed into this function is the truth.

@a7ul

a7ul commented Feb 25, 2021

Copy link
Copy Markdown
Collaborator

@allcontributors please add @wkirby for code

@a7ul
a7ul merged commit 3fe8f17 into nodegui:master Feb 25, 2021
@allcontributors

Copy link
Copy Markdown
Contributor

@a7ul

I've put up a pull request to add @wkirby! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants