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,
 | 
			
		||||
		    &QQuickItem::widthChanged,
 | 
			
		||||
		    this,
 | 
			
		||||
		    &MarginWrapperManager::onWrapperWidthChanged
 | 
			
		||||
		    &MarginWrapperManager::updateChildX
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		QObject::connect(
 | 
			
		||||
		    this->mWrapper,
 | 
			
		||||
		    &QQuickItem::heightChanged,
 | 
			
		||||
		    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;
 | 
			
		||||
	this->mChild->setX(this->targetChildX());
 | 
			
		||||
	this->mChild->setWidth(this->targetChildWidth());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MarginWrapperManager::onWrapperHeightChanged() {
 | 
			
		||||
void MarginWrapperManager::updateChildY() {
 | 
			
		||||
	if (!this->mChild || !this->mWrapper) return;
 | 
			
		||||
	this->mChild->setY(this->targetChildY());
 | 
			
		||||
	this->mChild->setHeight(this->targetChildHeight());
 | 
			
		||||
| 
						 | 
				
			
			@ -127,11 +127,19 @@ void MarginWrapperManager::onWrapperHeightChanged() {
 | 
			
		|||
void MarginWrapperManager::onChildImplicitWidthChanged() {
 | 
			
		||||
	if (!this->mChild || !this->mWrapper) return;
 | 
			
		||||
	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() {
 | 
			
		||||
	if (!this->mChild || !this->mWrapper) return;
 | 
			
		||||
	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() {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -55,8 +55,8 @@ signals:
 | 
			
		|||
 | 
			
		||||
private slots:
 | 
			
		||||
	void onChildChanged();
 | 
			
		||||
	void onWrapperWidthChanged();
 | 
			
		||||
	void onWrapperHeightChanged();
 | 
			
		||||
	void updateChildX();
 | 
			
		||||
	void updateChildY();
 | 
			
		||||
	void onChildImplicitWidthChanged();
 | 
			
		||||
	void onChildImplicitHeightChanged();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue