Example #1
0
void CAbstractLabel::UpdateBoundingSize()
{
	m_FontSize = Context()->ApplyGuiScale(11);
	int Spacing = 0;
	
	m_BoundingSizeRect.BSNoConstraint();
	
	const CAsset_GuiLabelStyle* pLabelStyle = AssetsManager()->GetAsset<CAsset_GuiLabelStyle>(m_LabelStylePath);
	if(pLabelStyle)
	{
		m_BoundingSizeRect.BSAddSpacing(
			Context()->ApplyGuiScale(pLabelStyle->GetMinWidth()),
			Context()->ApplyGuiScale(pLabelStyle->GetMinHeight())
		);
		
		m_FontSize = Context()->ApplyGuiScale(pLabelStyle->GetFontSize());
		Spacing = Context()->ApplyGuiScale(pLabelStyle->GetSpacing());
	}
	
	CRect ContentRect;
	ContentRect.BSNoConstraint();
	
	const CAsset_Sprite* pSprite = AssetsManager()->GetAsset<CAsset_Sprite>(m_IconPath);
	if(pSprite)
	{
		CRect IconRect;
		IconRect.BSMinimum(
			Context()->ApplyGuiScale(Context()->GetImageScale()*pSprite->GetPixelWidth()),
			Context()->ApplyGuiScale(Context()->GetImageScale()*pSprite->GetPixelHeight())
		);
		ContentRect.BSHorizontalAdd(IconRect);
	}
	
	if(GetText()[0])
	{
		if(pSprite)
			ContentRect.BSAddSpacing(Spacing, 0);
		
		CRect TextRect;
		TextRect.BSMinimum(m_FontSize, m_FontSize);
		ContentRect.BSHorizontalAdd(TextRect);
	}
	
	m_BoundingSizeRect.BSInnerAdd(ContentRect);
	
	if(pLabelStyle)
	{
		m_BoundingSizeRect.BSAddMargin(Context()->ApplyGuiScale(pLabelStyle->GetPadding()));
		m_BoundingSizeRect.BSAddMargin(Context()->ApplyGuiScale(pLabelStyle->GetMargin()));
	}
	
	m_TextCache.SetFontSize(m_FontSize);
}