Duilib ListContain 扩展

源码下载地址:https://share.weiyun.com/5TSf5mJ

通过对listContain扩展,使list可以插入任意控件到Item里面去,方便对list操作

操作完了之后记得调用SetPos让Contain计算内部控件位置
 m_pList->SetPos(rtList);

 

class UILIB_API CListContainerElementUIEx:public CListContainerElementUI
{
public:
	CListContainerElementUIEx(){};
	virtual void SetPos(RECT rc);
};

 

void CListContainerElementUIEx::SetPos( RECT rc )
{
	CDuiString xx =this->GetParent()->GetParent()->GetName();

	CContainerUI::SetPos(rc);
	rc = m_rcItem;  
	rc.left += m_rcInset.left;  
	rc.top += m_rcInset.top;  
	rc.right -= m_rcInset.right;  
	rc.bottom -= m_rcInset.bottom;  

	TListInfoUI *plistinfo = GetOwner()->GetListInfo(); 
	SIZE szAvailable = { rc.right - rc.left, rc.bottom - rc.top }; 
	CListUI  *pList=(CListUI*)this->GetParent()->GetParent();
	CListHeaderUI* pH = pList->GetHeader();
	for( int it2 = 0; it2 < m_items.GetSize(); it2++ )  
	{   
		CControlUI* pControl = static_cast(m_items[it2]);  
		CListHeaderItemUI* pHItem1= (CListHeaderItemUI* )pH->GetItemAt(it2);
		if(pHItem1->IsVisible()!=pControl->IsVisible())
		{
			pControl->SetVisible(pHItem1->IsVisible());
		}
		if( !pControl->IsVisible() )   
			continue;  

		if( pControl->IsFloat() )   
		{  
			SetFloatPos(it2);  
			continue;  
		}  
		RECT rcPadding = pControl->GetPadding();
		SIZE sz = pControl->EstimateSize(szAvailable);  
		if( sz.cx == 0 )   
		{  
			if( sz.cx < pControl->GetMinWidth() )   
				sz.cx = pControl->GetMinWidth();  
			if( sz.cx > pControl->GetMaxWidth() )   
				sz.cx = pControl->GetMaxWidth();  
		}  
		else   
		{  
			if( sz.cx < pControl->GetMinWidth() )   
				sz.cx = pControl->GetMinWidth();  
			if( sz.cx > pControl->GetMaxWidth() )  
				sz.cx = pControl->GetMaxWidth();  
		}  

		sz.cy = pControl->GetFixedHeight();  
		if( sz.cy == 0 )   
			sz.cy = rc.bottom - rc.top - rcPadding.top - rcPadding.bottom;  
		if( sz.cy < 0 )   
			sz.cy = 0;  
		if( sz.cy < pControl->GetMinHeight() )   
			sz.cy = pControl->GetMinHeight();  
		if( sz.cy > pControl->GetMaxHeight() )   
			sz.cy = pControl->GetMaxHeight();  

		//RECT rcCtrl = { iPosX + rcPadding.left, rc.top + rcPadding.top, iPosX + sz.cx + rcPadding.left , rc.top + rcPadding.top + sz.cy};
		RECT rcCtrl = { 
			plistinfo->rcColumn[it2].left + rcPadding.left,  
			rc.top + rcPadding.top,  
			plistinfo->rcColumn[it2].right + rcPadding.left,   
			rc.top + sz.cy + rcPadding.top + rcPadding.bottom };  
			pControl->SetPos(rcCtrl);
	}
}


效果图:Duilib ListContain 扩展_第1张图片

 

 

 

你可能感兴趣的:(Duilib)