From 352e0ee84a3c47ea8c83465511f3f8a39faad0dc Mon Sep 17 00:00:00 2001 From: Atul R Date: Wed, 4 Dec 2019 19:58:17 +0100 Subject: [PATCH] Bugfix/layout (#247) * Adds a bit more performance fix for qlayout * remove linter warning --- src/cpp/lib/core/FlexLayout/flexlayout.cpp | 2 +- src/demo.ts | 97 ++++++++++------------ src/lib/QtWidgets/QStackedWidget.ts | 2 +- 3 files changed, 47 insertions(+), 54 deletions(-) diff --git a/src/cpp/lib/core/FlexLayout/flexlayout.cpp b/src/cpp/lib/core/FlexLayout/flexlayout.cpp index 37db58b9a..49156d4e9 100644 --- a/src/cpp/lib/core/FlexLayout/flexlayout.cpp +++ b/src/cpp/lib/core/FlexLayout/flexlayout.cpp @@ -152,10 +152,10 @@ void FlexLayout::setGeometry(const QRect& rect) { } if (!rect.isValid() || rect != geometry()) { bool isSizeControlled = flexutils::isFlexNodeSizeControlled(this->node); - YGNodeMarkDirtyAndPropogateToDescendants(this->node); YGValue prevStyleMinWidth = YGNodeStyleGetMinWidth(this->node); YGValue prevStyleMinHeight = YGNodeStyleGetMinHeight(this->node); if (isSizeControlled) { + YGNodeMarkDirtyAndPropogateToDescendants(this->node); YGNodeStyleSetMinHeight(this->node, rect.height()); YGNodeStyleSetMinWidth(this->node, rect.width()); } diff --git a/src/demo.ts b/src/demo.ts index 08642c797..14d44d5ec 100644 --- a/src/demo.ts +++ b/src/demo.ts @@ -1,59 +1,52 @@ -import { QWidget, QMainWindow, QLabel, QBoxLayout, QPushButton } from './index'; -import { Direction } from './lib/QtEnums'; +import { QWidget, QScrollArea, FlexLayout, QPushButton } from './index'; +import { QLabel } from './lib/QtWidgets/QLabel'; +import { QMainWindow } from './lib/QtWidgets/QMainWindow'; const win = new QMainWindow(); -const center = new QWidget(); -const btn1 = new QPushButton(); -const btn2 = new QPushButton(); -const boxLayout = new QBoxLayout(Direction.LeftToRight); -btn1.setText(` -😱😱😱😱😱😱😱😱😱😱😱😱😱😱😱😱😱😱😱 - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - Hellloooooo - `); -btn2.setText(` - Helllo2 -`); +const scroll = new QScrollArea(); +const top = new QWidget(); +top.setLayout(new FlexLayout()); -center.setInlineStyle(`border: 3px solid blue`); -btn1.setInlineStyle(`padding: 10;font-family: "Sans serif";`); -btn2.setInlineStyle(`padding: 10;font-family: "Sans serif";`); -center.setLayout(boxLayout); -boxLayout.addWidget(btn1); -boxLayout.addWidget(btn2); -const box2 = new QBoxLayout(Direction.BottomToTop); -const lbl1 = new QLabel(); -const lbl2 = new QLabel(); -lbl1.setText('lbl1'); -lbl2.setText('lbl2'); -lbl1.setInlineStyle(`border: 2px solid blue;`); -lbl2.setInlineStyle(`border: 2px solid green;`); -box2.addWidget(lbl1); -box2.addWidget(lbl2); -btn1.addEventListener('clicked', () => { - console.log('direction', boxLayout.direction()); - boxLayout.addLayout(box2, 2); +const center = new QWidget(); +center.setLayout(new FlexLayout()); + +const btn = new QPushButton(); +btn.setText('helloo'); + +const text = new QLabel(); +text.setText('1 oncererer'); +btn.addEventListener('clicked', () => { + text.setText(` + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + Yoloooooooooo + `); }); -btn2.addEventListener('clicked', () => { - boxLayout.addSpacing(20); -}); -win.setCentralWidget(center); + +center.layout?.addWidget(btn); +center.layout?.addWidget(text); +scroll.setWidgetResizable(true); +center.setInlineStyle(`border: 3px solid blue; align-items:'center'; justify-content:'center';flex:1;`); +scroll.setWidget(top); +top.layout?.addWidget(center); +top.setInlineStyle(`border: 1px solid yellow;`); +win.setCentralWidget(scroll); win.show(); (global as any).win = win; diff --git a/src/lib/QtWidgets/QStackedWidget.ts b/src/lib/QtWidgets/QStackedWidget.ts index 52b284aba..2402be25b 100644 --- a/src/lib/QtWidgets/QStackedWidget.ts +++ b/src/lib/QtWidgets/QStackedWidget.ts @@ -1,5 +1,5 @@ import addon from '../utils/addon'; -import { NodeWidget, QWidget } from './QWidget'; +import { NodeWidget } from './QWidget'; import { BaseWidgetEvents } from '../core/EventWidget'; import { NativeElement } from '../core/Component';