forked from quickshell/quickshell
		
	widgets/wrapper: update child geometry when implicit size changes
The implicit size update from a child item of a MarginWrapper component triggers an implicit size update of the wrapper component, but this does not necessarily result in the actual size of the wrapper changing (e.g. when it is positioned by a layout).
This commit is contained in:
		
							parent
							
								
									cb05e9a327
								
							
						
					
					
						commit
						af14a416c1
					
				
					 2 changed files with 14 additions and 6 deletions
				
			
		| 
						 | 
					@ -27,14 +27,14 @@ void MarginWrapperManager::componentComplete() {
 | 
				
			||||||
		    this->mWrapper,
 | 
							    this->mWrapper,
 | 
				
			||||||
		    &QQuickItem::widthChanged,
 | 
							    &QQuickItem::widthChanged,
 | 
				
			||||||
		    this,
 | 
							    this,
 | 
				
			||||||
		    &MarginWrapperManager::onWrapperWidthChanged
 | 
							    &MarginWrapperManager::updateChildX
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		QObject::connect(
 | 
							QObject::connect(
 | 
				
			||||||
		    this->mWrapper,
 | 
							    this->mWrapper,
 | 
				
			||||||
		    &QQuickItem::heightChanged,
 | 
							    &QQuickItem::heightChanged,
 | 
				
			||||||
		    this,
 | 
							    this,
 | 
				
			||||||
		    &MarginWrapperManager::onWrapperHeightChanged
 | 
							    &MarginWrapperManager::updateChildY
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -112,13 +112,13 @@ qreal MarginWrapperManager::targetChildY() const {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MarginWrapperManager::onWrapperWidthChanged() {
 | 
					void MarginWrapperManager::updateChildX() {
 | 
				
			||||||
	if (!this->mChild || !this->mWrapper) return;
 | 
						if (!this->mChild || !this->mWrapper) return;
 | 
				
			||||||
	this->mChild->setX(this->targetChildX());
 | 
						this->mChild->setX(this->targetChildX());
 | 
				
			||||||
	this->mChild->setWidth(this->targetChildWidth());
 | 
						this->mChild->setWidth(this->targetChildWidth());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MarginWrapperManager::onWrapperHeightChanged() {
 | 
					void MarginWrapperManager::updateChildY() {
 | 
				
			||||||
	if (!this->mChild || !this->mWrapper) return;
 | 
						if (!this->mChild || !this->mWrapper) return;
 | 
				
			||||||
	this->mChild->setY(this->targetChildY());
 | 
						this->mChild->setY(this->targetChildY());
 | 
				
			||||||
	this->mChild->setHeight(this->targetChildHeight());
 | 
						this->mChild->setHeight(this->targetChildHeight());
 | 
				
			||||||
| 
						 | 
					@ -127,11 +127,19 @@ void MarginWrapperManager::onWrapperHeightChanged() {
 | 
				
			||||||
void MarginWrapperManager::onChildImplicitWidthChanged() {
 | 
					void MarginWrapperManager::onChildImplicitWidthChanged() {
 | 
				
			||||||
	if (!this->mChild || !this->mWrapper) return;
 | 
						if (!this->mChild || !this->mWrapper) return;
 | 
				
			||||||
	this->mWrapper->setImplicitWidth(this->mChild->implicitWidth() + this->mMargin * 2);
 | 
						this->mWrapper->setImplicitWidth(this->mChild->implicitWidth() + this->mMargin * 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// If the implicit width change does not result in an actual width change,
 | 
				
			||||||
 | 
						// this will not be called anywhere else.
 | 
				
			||||||
 | 
						this->updateChildX();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MarginWrapperManager::onChildImplicitHeightChanged() {
 | 
					void MarginWrapperManager::onChildImplicitHeightChanged() {
 | 
				
			||||||
	if (!this->mChild || !this->mWrapper) return;
 | 
						if (!this->mChild || !this->mWrapper) return;
 | 
				
			||||||
	this->mWrapper->setImplicitHeight(this->mChild->implicitHeight() + this->mMargin * 2);
 | 
						this->mWrapper->setImplicitHeight(this->mChild->implicitHeight() + this->mMargin * 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// If the implicit height change does not result in an actual height change,
 | 
				
			||||||
 | 
						// this will not be called anywhere else.
 | 
				
			||||||
 | 
						this->updateChildY();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MarginWrapperManager::updateGeometry() {
 | 
					void MarginWrapperManager::updateGeometry() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,8 +55,8 @@ signals:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private slots:
 | 
					private slots:
 | 
				
			||||||
	void onChildChanged();
 | 
						void onChildChanged();
 | 
				
			||||||
	void onWrapperWidthChanged();
 | 
						void updateChildX();
 | 
				
			||||||
	void onWrapperHeightChanged();
 | 
						void updateChildY();
 | 
				
			||||||
	void onChildImplicitWidthChanged();
 | 
						void onChildImplicitWidthChanged();
 | 
				
			||||||
	void onChildImplicitHeightChanged();
 | 
						void onChildImplicitHeightChanged();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue