第三方框架改为仓内子集并完善构建忽略规则

完整 NIM_Duilib_Framework 仓库移至父目录,third_party 仅保留实际使用的 base、duilib、bin/resources 与许可证;.gitignore 覆盖 MSBuild 与打包产物。
This commit is contained in:
tongtong committed 2026-11-15 08:54:17 +08:00
1 parent 249e8548de
commit e1e26acc49
391 files changed
+342850

No files matched your search

@@ -0,0 +1,45 @@
#include "stdafx.h"
#include "ChildBox.h"
namespace ui
{
ChildBox::ChildBox()
{
}
void ChildBox::Init()
{
if (!m_strXMLFile.empty())
{
Box* pChildWindow = static_cast<Box*>(GlobalManager::CreateBoxWithCache(m_strXMLFile.c_str(), CreateControlCallback()));
if (pChildWindow) {
this->Add(pChildWindow);
}
else {
ASSERT(FALSE);
this->RemoveAll();
}
}
}
void ChildBox::SetAttribute( const::std::wstring& strName, const std::wstring& strValue )
{
if( strName == _T("xmlfile") )
SetChildLayoutXML(strValue);
else
Box::SetAttribute(strName,strValue);
}
void ChildBox::SetChildLayoutXML( std::wstring strXML )
{
m_strXMLFile = strXML;
}
std::wstring ChildBox::GetChildLayoutXML()
{
return m_strXMLFile;
}
} // namespace ui
+36
View File
@@ -0,0 +1,36 @@
#ifndef UI_CORE_CHILDBOX_H_
#define UI_CORE_CHILDBOX_H_
#pragma once
namespace ui
{
class UILIB_API ChildBox : public Box
{
public:
ChildBox();
/// 重写父类方法,提供个性化功能,请参考父类声明
virtual void Init() override;
virtual void SetAttribute(const std::wstring& strName, const std::wstring& strValue) override;
/**
* @brief 设置 ChildBox 关联的 XML 文件
* @param[in] strXML XML 文件路径
* @return 无
*/
void SetChildLayoutXML(std::wstring strXML);
/**
* @brief 获取 ChildBox 关联的 XML 文件
* @return 返回 ChildBox 关联的 XML 文件
*/
std::wstring GetChildLayoutXML();
private:
std::wstring m_strXMLFile;
};
} // namespace ui
#endif // UI_CORE_CHILDBOX_H_
+146
View File
@@ -0,0 +1,146 @@
#include "stdafx.h"
#include "HBox.h"
namespace ui
{
HLayout::HLayout()
{
}
CSize HLayout::ArrangeChild(const std::vector<Control*>& items, UiRect rc)
{
// Determine the width of elements that are sizeable
CSize szAvailable(rc.right - rc.left, rc.bottom - rc.top);
int nAdjustables = 0;
int cxFixed = 0;
int nEstimateNum = 0;
for( auto it = items.begin(); it != items.end(); it++ ) {
auto pControl = *it;
if( !pControl->IsVisible() ) continue;
if( pControl->IsFloat() ) continue;
CSize sz = pControl->EstimateSize(szAvailable);
if( sz.cx == DUI_LENGTH_STRETCH ) {
nAdjustables++;
cxFixed += pControl->GetMargin().left + pControl->GetMargin().right;
}
else {
if( sz.cx < pControl->GetMinWidth() ) sz.cx = pControl->GetMinWidth();
if( pControl->GetMaxWidth() >= 0 && sz.cx > pControl->GetMaxWidth() ) sz.cx = pControl->GetMaxWidth();
cxFixed += sz.cx + pControl->GetMargin().left + pControl->GetMargin().right;
}
nEstimateNum++;
}
cxFixed += (nEstimateNum - 1) * m_iChildMargin;
int cxExpand = 0;
int cxNeeded = 0;
if( nAdjustables > 0 ) cxExpand = MAX(0, (szAvailable.cx - cxFixed) / nAdjustables);
int deviation = szAvailable.cx - cxFixed - cxExpand * nAdjustables;
// Position the elements
CSize szRemaining = szAvailable;
int iPosX = rc.left;
int iPosTop = rc.top;
int iPosBottom = rc.bottom;
int iAdjustable = 0;
int max_height = 0;
for( auto it = items.begin(); it != items.end(); it++ ) {
auto pControl = *it;
if( !pControl->IsVisible() ) continue;
if( pControl->IsFloat() ) {
SetFloatPos(pControl, rc);
continue;
}
UiRect rcMargin = pControl->GetMargin();
szRemaining.cx -= rcMargin.left;
CSize sz = pControl->EstimateSize(szRemaining);
if( sz.cx == DUI_LENGTH_STRETCH ) {
iAdjustable++;
sz.cx = cxExpand;
if (deviation > 0) {
sz.cx += 1;
deviation--;
}
}
if( sz.cx < pControl->GetMinWidth() ) sz.cx = pControl->GetMinWidth();
if( pControl->GetMaxWidth() >= 0 && sz.cx > pControl->GetMaxWidth() ) sz.cx = pControl->GetMaxWidth();
if( sz.cy == DUI_LENGTH_STRETCH ) sz.cy = szAvailable.cy - rcMargin.top - rcMargin.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();
int childTop = 0;
int childBottm = 0;
VerAlignType verAlignType = pControl->GetVerAlignType();
if (verAlignType == kVerAlignTop) {
childTop = iPosTop + rcMargin.top;
childBottm = childTop + sz.cy;
}
else if (verAlignType == kVerAlignBottom) {
childBottm = iPosBottom - rcMargin.bottom;
childTop = childBottm - sz.cy;
}
else if (verAlignType == kVerAlignCenter) {
childTop = iPosTop + (iPosBottom - iPosTop + rcMargin.top - rcMargin.bottom - sz.cy) / 2;
childBottm = childTop + sz.cy;
}
UiRect rcChildPos(iPosX + rcMargin.left, childTop, iPosX + rcMargin.left + sz.cx, childBottm);
max_height = MAX(max_height, rcChildPos.GetHeight());
pControl->SetPos(rcChildPos);
iPosX += sz.cx + m_iChildMargin + rcMargin.left + rcMargin.right;
cxNeeded += sz.cx + rcMargin.left + rcMargin.right;
szRemaining.cx -= sz.cx + m_iChildMargin + rcMargin.right;
}
cxNeeded += (nEstimateNum - 1) * m_iChildMargin;
CSize size(cxNeeded, max_height);
return size;
}
CSize HLayout::AjustSizeByChild(const std::vector<Control*>& items, CSize szAvailable)
{
CSize totalSize;
CSize itemSize;
Control* pChildControl = NULL;
int count = (int)items.size();
int estimateChildCount = 0;
for(int it = 0; it < count; it++)
{
pChildControl = (Control*)items[it];
if (!pChildControl->IsVisible() || pChildControl->IsFloat()){
continue;
}
estimateChildCount++;
itemSize = pChildControl->EstimateSize(szAvailable);
if( itemSize.cx < pChildControl->GetMinWidth() ) itemSize.cx = pChildControl->GetMinWidth();
if( pChildControl->GetMaxWidth() >= 0 && itemSize.cx > pChildControl->GetMaxWidth() ) itemSize.cx = pChildControl->GetMaxWidth();
if( itemSize.cy < pChildControl->GetMinHeight() ) itemSize.cy = pChildControl->GetMinHeight();
if( itemSize.cy > pChildControl->GetMaxHeight() ) itemSize.cy = pChildControl->GetMaxHeight();
totalSize.cx += itemSize.cx + pChildControl->GetMargin().left + pChildControl->GetMargin().right;
totalSize.cy = MAX(itemSize.cy + pChildControl->GetMargin().top + pChildControl->GetMargin().bottom, totalSize.cy);
}
if (estimateChildCount - 1 > 0) {
totalSize.cx += (estimateChildCount - 1) * m_iChildMargin;
}
totalSize.cx += m_rcPadding.left + m_rcPadding.right;
totalSize.cy += m_rcPadding.top + m_rcPadding.bottom;
return totalSize;
}
HBox::HBox() : Box(new HLayout())
{
}
}
+26
View File
@@ -0,0 +1,26 @@
#ifndef UI_CORE_HBOX_H_
#define UI_CORE_HBOX_H_
#pragma once
namespace ui
{
class UILIB_API HLayout : public Layout
{
public:
HLayout();
/// 重写父类方法,提供个性化功能,请参考父类声明
virtual CSize ArrangeChild(const std::vector<Control*>& items, UiRect rc) override;
virtual CSize AjustSizeByChild(const std::vector<Control*>& items, CSize szAvailable) override;
};
class UILIB_API HBox : public Box
{
public:
HBox();
};
}
#endif // UI_CORE_HBOX_H_
+236
View File
@@ -0,0 +1,236 @@
#include "stdafx.h"
#include "TabBox.h"
namespace ui
{
TabBox::TabBox(Layout* pLayout) : Box(pLayout), m_iCurSel(-1), m_bFadeSwith(false)
{
}
bool TabBox::Add(Control* pControl)
{
bool ret = Box::Add(pControl);
if( !ret ) return ret;
if(m_iCurSel == -1 && pControl->IsVisible()) {
m_iCurSel = GetItemIndex(pControl);
}
if (m_iCurSel != GetItemIndex(pControl) || !pControl->IsVisible())
{
if (!IsFadeSwitch()) {
pControl->SetVisible(false);
}
pControl->SetMouseEnabled(false);
if (Box* box = dynamic_cast<Box*>(pControl)) {
box->SetMouseChildEnabled(false);
}
pControl->SetAlpha(0);
}
return ret;
}
bool TabBox::AddAt(Control* pControl, std::size_t iIndex)
{
bool ret = Box::AddAt(pControl, iIndex);
if(!ret)
return ret;
if(m_iCurSel == -1 && pControl->IsVisible()) {
m_iCurSel = GetItemIndex(pControl);
}
else if( m_iCurSel != -1 && iIndex <= (std::size_t)m_iCurSel ) {
m_iCurSel += 1;
}
else {
if (!IsFadeSwitch()) {
pControl->SetVisible(false);
}
pControl->SetMouseEnabled(false);
if (Box* box = dynamic_cast<Box*>(pControl)) {
box->SetMouseChildEnabled(false);
}
pControl->SetAlpha(0);
}
return ret;
}
bool TabBox::Remove(Control* pControl)
{
if( pControl == NULL) return false;
int index = GetItemIndex(pControl);
bool ret = Box::Remove(pControl);
if( !ret ) return false;
if( m_iCurSel == index) {
if( GetCount() > 0 ) {
m_iCurSel=0;
if (!IsFadeSwitch()) {
GetItemAt(m_iCurSel)->SetVisible(true);
}
pControl->SetMouseEnabled(true);
if (Box* box = dynamic_cast<Box*>(pControl)) {
box->SetMouseChildEnabled(true);
}
pControl->SetAlpha(255);
}
else
m_iCurSel=-1;
ArrangeAncestor();
}
else if( m_iCurSel > index ) {
m_iCurSel -= 1;
}
return ret;
}
bool TabBox::RemoveAt(std::size_t iIndex)
{
Control* pControl = GetItemAt(iIndex);
if (pControl == NULL) return false;
return Remove(pControl);
}
void TabBox::RemoveAll()
{
m_iCurSel = -1;
Box::RemoveAll();
ArrangeAncestor();
}
int TabBox::GetCurSel() const
{
return m_iCurSel;
}
bool TabBox::SelectItem(int iIndex)
{
if( iIndex < 0 || (std::size_t)iIndex >= m_items.size() ) return false;
if( iIndex == m_iCurSel ) return true;
int iOldSel = m_iCurSel;
m_iCurSel = iIndex;
for( std::size_t it = 0; it < m_items.size(); it++ ){
if( (int)it == iIndex ) {
ShowTabItem(it);
if (!IsFadeSwitch()) {
m_items[it]->SetVisible();
}
else {
int startValue = 0;
int endValue = 0;
if (m_iCurSel < iOldSel) {
startValue = GetPos().GetWidth();
endValue = 0;
}
else {
startValue = -GetPos().GetWidth();
endValue = 0;
}
auto player = m_items[it]->GetAnimationManager().SetFadeInOutX(true, true);
player->SetStartValue(startValue);
player->SetEndValue(endValue);
player->SetSpeedUpfactorA(0.015);
player->SetCompleteCallback(CompleteCallback());
player->Start();
}
}
else {
if ((int)it != iOldSel) {
HideTabItem(it);
if (!IsFadeSwitch()) {
m_items[it]->SetVisible(false);
}
}
else {
if (!IsFadeSwitch()) {
HideTabItem(it);
m_items[it]->SetVisible(false);
}
else {
int startValue = 0;
int endValue = 0;
if (m_iCurSel < iOldSel) {
startValue = 0;
endValue = -GetPos().GetWidth();
}
else {
startValue = 0;
endValue = GetPos().GetWidth();
}
auto player = m_items[it]->GetAnimationManager().SetFadeInOutX(true, true);
player->SetStartValue(startValue);
player->SetEndValue(endValue);
player->SetSpeedUpfactorA(0.015);
CompleteCallback compelteCallback = nbase::Bind(&TabBox::HideTabItem, this, it);
player->SetCompleteCallback(compelteCallback);
player->Start();
}
}
}
}
if( m_pWindow != NULL ) {
m_pWindow->SetNextTabControl();
m_pWindow->SendNotify(this, kEventSelect, m_iCurSel, iOldSel);
}
return true;
}
void TabBox::HideTabItem(std::size_t it)
{
m_items[it]->SetMouseEnabled(false);
if (Box* box = dynamic_cast<Box*>(this->m_items[it])) {
box->SetMouseChildEnabled(false);
}
m_items[it]->SetAlpha(0);
}
void TabBox::ShowTabItem(std::size_t it)
{
m_items[it]->SetMouseEnabled(true);
if (Box* box = dynamic_cast<Box*>(this->m_items[it])) {
box->SetMouseChildEnabled(true);
}
m_items[it]->SetAlpha(255);
}
bool TabBox::SelectItem( Control* pControl )
{
int iIndex = GetItemIndex(pControl);
if (iIndex==-1)
return false;
else
return SelectItem(iIndex);
}
bool TabBox::SelectItem(const std::wstring& pControlName)
{
Control* pControl = FindSubControl(pControlName);
ASSERT(pControl);
return SelectItem(pControl);
}
void TabBox::SetAttribute(const std::wstring& strName, const std::wstring& strValue)
{
if (strName == _T("selectedid")) m_iCurSel = _ttoi(strValue.c_str());
else if( strName == _T("fadeswitch") ) SetFadeSwitch(strValue == _T("true"));
else Box::SetAttribute(strName, strValue);
}
void TabBox::SetFadeSwitch(bool bFadeSwitch)
{
m_bFadeSwith = bFadeSwitch;
}
}
+83
View File
@@ -0,0 +1,83 @@
#ifndef UI_CORE_TABBOX_H_
#define UI_CORE_TABBOX_H_
#pragma once
namespace ui
{
class UILIB_API TabBox : public Box
{
public:
TabBox(Layout* pLayout = new Layout());
/// 重写父类方法,提供个性化功能,请参考父类声明
virtual bool Add(Control* pControl) override;
virtual bool AddAt(Control* pControl, std::size_t iIndex) override;
virtual bool Remove(Control* pControl) override;
virtual bool RemoveAt(std::size_t iIndex) override;
virtual void RemoveAll() override;
virtual void SetAttribute(const std::wstring& strName, const std::wstring& strValue) override;
/**
* @brief 获取当前选择项
* @return 返回当前选择项索引
*/
int GetCurSel() const;
/**
* @brief 根据控件索引选择一个子项
* @param[in] iIndex 要选择的子项索引
* @return 成功返回 true,否则返回 false
*/
bool SelectItem(int iIndex);
/**
* @brief 根据控件指针选择一个子项
* @param[in] pControl 要选择的子项指针
* @return 成功返回 true,否则返回 false
*/
bool SelectItem(Control* pControl);
/**
* @brief 根据控件名称选择一个子项
* @param[in] pControlName 要选择的控件名称
* @return 成功返回 true,否则返回 false
*/
bool SelectItem(const std::wstring& pControlName);
/**
* @brief 设置是否显示动画效果
* @param[in] bFadeSwitch 设置为 true 则显示,false 为不显示动画
* @return 无
*/
void SetFadeSwitch(bool bFadeSwitch);
/**
* @brief 判断是否需要显示动画效果
* @return 返回 true 显示动画,false 为不显示动画效果
*/
bool IsFadeSwitch() { return m_bFadeSwith; }
protected:
/**
* @brief 显示一个 TAB 项
* @param[in] it TAB 项索引
* @return 无
*/
void ShowTabItem(std::size_t it);
/**
* @brief 隐藏一个 TAB 项
* @param[in] it TAB 项索引
* @return 无
*/
void HideTabItem(std::size_t it);
protected:
int m_iCurSel;
bool m_bFadeSwith;
};
}
#endif // UI_CORE_TABBOX_H_
+194
View File
@@ -0,0 +1,194 @@
#include "stdafx.h"
#include "TileBox.h"
namespace ui
{
TileLayout::TileLayout() : m_nColumns(1), m_szItem(0, 0)
{
}
CSize TileLayout::ArrangeChild(const std::vector<Control*>& items, UiRect rc)
{
// Position the elements
if( m_szItem.cx > 0 ) m_nColumns = (rc.right - rc.left) / m_szItem.cx;
if( m_nColumns == 0 ) m_nColumns = 1;
int cyNeeded = 0;
int cxWidth = rc.GetWidth() / m_nColumns;
int deviation = rc.GetWidth() - cxWidth * m_nColumns;
int tmpDeviation = deviation;
int cyHeight = 0;
int iCount = 0;
CPoint ptTile(rc.left, rc.top);
int iPosX = rc.left;
for( auto it = items.begin(); it != items.end(); it++ ) {
auto pControl = *it;
if( !pControl->IsVisible() ) continue;
if( pControl->IsFloat() ) {
SetFloatPos(pControl, rc);
continue;
}
// Determine size
UiRect rcTile(ptTile.x, ptTile.y, ptTile.x + cxWidth, ptTile.y);
if (tmpDeviation > 0) {
rcTile.right += 1;
tmpDeviation--;
}
if( (iCount % m_nColumns) == 0 )
{
int iIndex = iCount;
for (auto it2 = it; it2 != items.end(); it2++) {
auto pLineControl = *it2;
if( !pLineControl->IsVisible() ) continue;
if( pLineControl->IsFloat() ) continue;
UiRect rcMargin = pLineControl->GetMargin();
CSize szAvailable(rcTile.right - rcTile.left - rcMargin.left - rcMargin.right, 9999);
if( iIndex == iCount || (iIndex + 1) % m_nColumns == 0 ) {
szAvailable.cx -= m_iChildMargin / 2;
}
else {
szAvailable.cx -= m_iChildMargin;
}
if( szAvailable.cx < pControl->GetMinWidth() ) szAvailable.cx = pControl->GetMinWidth();
if( pControl->GetMaxWidth() >= 0 && szAvailable.cx > pControl->GetMaxWidth() ) szAvailable.cx = pControl->GetMaxWidth();
CSize szTile = pLineControl->EstimateSize(szAvailable);
if( szTile.cx < pControl->GetMinWidth() ) szTile.cx = pControl->GetMinWidth();
if( pControl->GetMaxWidth() >= 0 && szTile.cx > pControl->GetMaxWidth() ) szTile.cx = pControl->GetMaxWidth();
if( szTile.cy < pControl->GetMinHeight() ) szTile.cy = pControl->GetMinHeight();
if( szTile.cy > pControl->GetMaxHeight() ) szTile.cy = pControl->GetMaxHeight();
cyHeight = MAX(cyHeight, szTile.cy + rcMargin.top + rcMargin.bottom);
if( (++iIndex % m_nColumns) == 0) break;
}
}
UiRect rcMargin = pControl->GetMargin();
UiRect newRcTile = rcTile;
newRcTile.left += rcMargin.left + m_iChildMargin / 2;
newRcTile.right -= rcMargin.right + m_iChildMargin / 2;
// Set position
newRcTile.top = ptTile.y + rcMargin.top;
newRcTile.bottom = ptTile.y + cyHeight;
CSize szAvailable(newRcTile.right - newRcTile.left, newRcTile.bottom - newRcTile.top);
CSize szTile = pControl->EstimateSize(szAvailable);
if( szTile.cx == DUI_LENGTH_STRETCH ) szTile.cx = szAvailable.cx;
if( szTile.cy == DUI_LENGTH_STRETCH ) szTile.cy = szAvailable.cy;
if( szTile.cx < pControl->GetMinWidth() ) szTile.cx = pControl->GetMinWidth();
if( pControl->GetMaxWidth() >= 0 && szTile.cx > pControl->GetMaxWidth() ) szTile.cx = pControl->GetMaxWidth();
if( szTile.cy < pControl->GetMinHeight() ) szTile.cy = pControl->GetMinHeight();
if( szTile.cy > pControl->GetMaxHeight() ) szTile.cy = pControl->GetMaxHeight();
UiRect rcPos((newRcTile.left + newRcTile.right - szTile.cx) / 2, (newRcTile.top + newRcTile.bottom - szTile.cy) / 2,
(newRcTile.left + newRcTile.right - szTile.cx) / 2 + szTile.cx, (newRcTile.top + newRcTile.bottom - szTile.cy) / 2 + szTile.cy);
pControl->SetPos(rcPos);
if( (++iCount % m_nColumns) == 0 ) {
ptTile.x = iPosX;
ptTile.y += cyHeight + m_iChildMargin;
cyHeight = 0;
tmpDeviation = deviation;
}
else {
ptTile.x += rcTile.GetWidth();
}
cyNeeded = newRcTile.bottom - rc.top;
}
CSize size(rc.right - rc.left, cyNeeded);
return size;
}
CSize TileLayout::AjustSizeByChild(const std::vector<Control*>& items, CSize szAvailable)
{
CSize size = m_pOwner->Control::EstimateSize(szAvailable);
size.cy = 0;
if( m_szItem.cx > 0 ) m_nColumns = m_pOwner->GetFixedWidth() / m_szItem.cx;
if( m_nColumns == 0 ) m_nColumns = 1;
int visibleCount = (int)items.size();
for (auto it = items.begin(); it != items.end(); it++) {
if (!(*it)->IsVisible()) {
visibleCount--;
}
}
int rows = visibleCount / m_nColumns;
if (visibleCount % m_nColumns != 0) {
rows += 1;
}
if (visibleCount > 0) {
int childMarginTotal;
if (visibleCount % m_nColumns == 0) {
childMarginTotal = (visibleCount / m_nColumns - 1) * m_iChildMargin;
}
else {
childMarginTotal = (visibleCount / m_nColumns) * m_iChildMargin;
}
Control* pControl = static_cast<Control*>(items[0]);
size.cy += pControl->GetFixedHeight() * rows + m_rcPadding.top + m_rcPadding.bottom + childMarginTotal;
}
return size;
}
bool TileLayout::SetAttribute(const std::wstring& strName, const std::wstring& strValue)
{
bool hasAttribute = true;
if( strName == _T("itemsize") ) {
CSize szItem;
LPTSTR pstr = NULL;
szItem.cx = _tcstol(strValue.c_str(), &pstr, 10); ASSERT(pstr);
szItem.cy = _tcstol(pstr + 1, &pstr, 10); ASSERT(pstr);
SetItemSize(szItem);
}
else if( strName == _T("columns"))
{
SetColumns(_ttoi(strValue.c_str()));
}
else
{
hasAttribute = Layout::SetAttribute(strName, strValue);
}
return hasAttribute;
}
CSize TileLayout::GetItemSize() const
{
return m_szItem;
}
void TileLayout::SetItemSize(CSize szItem)
{
DpiManager::GetInstance()->ScaleSize(szItem);
if( m_szItem.cx != szItem.cx || m_szItem.cy != szItem.cy ) {
m_szItem = szItem;
m_pOwner->Arrange();
}
}
int TileLayout::GetColumns() const
{
return m_nColumns;
}
void TileLayout::SetColumns(int nCols)
{
if( nCols <= 0 ) return;
m_nColumns = nCols;
m_pOwner->Arrange();
}
TileBox::TileBox() : Box(new TileLayout())
{
}
}
+57
View File
@@ -0,0 +1,57 @@
#ifndef UI_CORE_TILEBOX_H_
#define UI_CORE_TILEBOX_H_
#pragma once
namespace ui
{
class UILIB_API TileLayout : public Layout
{
public:
TileLayout();
/// 重写父类方法,提供个性化功能,请参考父类声明
virtual CSize ArrangeChild(const std::vector<Control*>& items, UiRect rc) override;
virtual CSize AjustSizeByChild(const std::vector<Control*>& items, CSize szAvailable) override;
virtual bool SetAttribute(const std::wstring& strName, const std::wstring& strValue) override;
/**
* @brief 获取子项大小
* @return 返回子项大小
*/
CSize GetItemSize() const;
/**
* @brief 设置子项大小
* @param[in] szItem 子项大小数据
* @return 无
*/
void SetItemSize(CSize szItem);
/**
* @brief 获取列数量
* @return 返回列数量
*/
int GetColumns() const;
/**
* @brief 设置显示几列数据
* @param[in] nCols 要设置显示几列的数值
* @return 无
*/
void SetColumns(int nCols);
protected:
int m_nColumns;
CSize m_szItem;
};
class UILIB_API TileBox : public Box
{
public:
TileBox();
};
}
#endif // UI_CORE_TILEBOX_H_
+146
View File
@@ -0,0 +1,146 @@
#include "stdafx.h"
#include "VBox.h"
namespace ui
{
VLayout::VLayout()
{
}
CSize VLayout::ArrangeChild(const std::vector<Control*>& items, UiRect rc)
{
// Determine the minimum size
CSize szAvailable(rc.right - rc.left, rc.bottom - rc.top);
int nAdjustables = 0;
int cyFixed = 0;
int nEstimateNum = 0;
for( auto it = items.begin(); it != items.end(); it++ ) {
auto pControl = *it;
if( !pControl->IsVisible() ) continue;
if( pControl->IsFloat() ) continue;
CSize sz = pControl->EstimateSize(szAvailable);
if( sz.cy == DUI_LENGTH_STRETCH ) {
nAdjustables++;
cyFixed += pControl->GetMargin().top + pControl->GetMargin().bottom;
}
else {
if( sz.cy < pControl->GetMinHeight() ) sz.cy = pControl->GetMinHeight();
if( sz.cy > pControl->GetMaxHeight() ) sz.cy = pControl->GetMaxHeight();
cyFixed += sz.cy + pControl->GetMargin().top + pControl->GetMargin().bottom;
}
nEstimateNum++;
}
cyFixed += (nEstimateNum - 1) * m_iChildMargin;
// Place elements
int cyNeeded = 0;
int cyExpand = 0;
if( nAdjustables > 0 ) cyExpand = MAX(0, (szAvailable.cy - cyFixed) / nAdjustables);
int deviation = szAvailable.cy - cyFixed - cyExpand * nAdjustables;
// Position the elements
CSize szRemaining = szAvailable;
int iPosLeft = rc.left;
int iPosRight = rc.right;
int iPosY = rc.top;
int iAdjustable = 0;
int max_width = 0;
for( auto it = items.begin(); it != items.end(); it++ ) {
auto pControl = *it;
if( !pControl->IsVisible() ) continue;
if( pControl->IsFloat() ) {
SetFloatPos(pControl, rc);
continue;
}
UiRect rcMargin = pControl->GetMargin();
szRemaining.cy -= rcMargin.top;
CSize sz = pControl->EstimateSize(szRemaining);
if( sz.cy == DUI_LENGTH_STRETCH ) {
iAdjustable++;
sz.cy = cyExpand;
if (deviation > 0) {
sz.cy += 1;
deviation--;
}
}
if (sz.cy < pControl->GetMinHeight()) sz.cy = pControl->GetMinHeight();
if (sz.cy > pControl->GetMaxHeight()) sz.cy = pControl->GetMaxHeight();
if( sz.cx == DUI_LENGTH_STRETCH ) sz.cx = szAvailable.cx - rcMargin.left - rcMargin.right;
if( sz.cx < 0 ) sz.cx = 0;
if( sz.cx < pControl->GetMinWidth() ) sz.cx = pControl->GetMinWidth();
if( pControl->GetMaxWidth() >= 0 && sz.cx > pControl->GetMaxWidth() ) sz.cx = pControl->GetMaxWidth();
int childLeft = 0;
int childRight = 0;
HorAlignType horAlignType = pControl->GetHorAlignType();
if (horAlignType == kHorAlignLeft) {
childLeft = iPosLeft + rcMargin.left;
childRight = childLeft + sz.cx;
}
else if (horAlignType == kHorAlignRight) {
childRight = iPosRight - rcMargin.right;
childLeft = childRight - sz.cx;
}
else if (horAlignType == kHorAlignCenter) {
childLeft = iPosLeft + (iPosRight - iPosLeft + rcMargin.left - rcMargin.right - sz.cx) / 2;
childRight = childLeft + sz.cx;
}
UiRect rcCtrl(childLeft, iPosY + rcMargin.top, childRight, iPosY + rcMargin.top + sz.cy);
max_width = MAX(max_width, rcCtrl.GetWidth());
pControl->SetPos(rcCtrl);
iPosY += sz.cy + m_iChildMargin + rcMargin.top + rcMargin.bottom;
cyNeeded += sz.cy + rcMargin.top + rcMargin.bottom;
szRemaining.cy -= sz.cy + m_iChildMargin + rcMargin.bottom;
}
cyNeeded += (nEstimateNum - 1) * m_iChildMargin;
CSize size(max_width, cyNeeded);
return size;
}
CSize VLayout::AjustSizeByChild(const std::vector<Control*>& items, CSize szAvailable)
{
CSize totalSize;
CSize itemSize;
Control* pChildControl = NULL;
int count = (int)items.size();
int estimateChildCount = 0;
for(int it = 0; it < count; it++)
{
pChildControl = (Control*)items[it];
if (!pChildControl->IsVisible() || pChildControl->IsFloat()) {
continue;
}
estimateChildCount++;
itemSize = pChildControl->EstimateSize(szAvailable);
if( itemSize.cx < pChildControl->GetMinWidth() ) itemSize.cx = pChildControl->GetMinWidth();
if( pChildControl->GetMaxWidth() >= 0 && itemSize.cx > pChildControl->GetMaxWidth() ) itemSize.cx = pChildControl->GetMaxWidth();
if( itemSize.cy < pChildControl->GetMinHeight() ) itemSize.cy = pChildControl->GetMinHeight();
if( itemSize.cy > pChildControl->GetMaxHeight() ) itemSize.cy = pChildControl->GetMaxHeight();
totalSize.cx = MAX(itemSize.cx + pChildControl->GetMargin().left + pChildControl->GetMargin().right, totalSize.cx);
totalSize.cy += itemSize.cy + pChildControl->GetMargin().top + pChildControl->GetMargin().bottom;
}
if (estimateChildCount - 1 > 0) {
totalSize.cy += (estimateChildCount - 1) * m_iChildMargin;
}
totalSize.cx += m_rcPadding.left + m_rcPadding.right;
totalSize.cy += m_rcPadding.top + m_rcPadding.bottom;
return totalSize;
}
VBox::VBox() : Box(new VLayout())
{
}
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef UI_CORE_VBOX_H_
#define UI_CORE_VBOX_H_
#pragma once
namespace ui
{
class UILIB_API VLayout : public Layout
{
public:
VLayout();
/// 重写父类方法,提供个性化功能,请参考父类声明
virtual CSize ArrangeChild(const std::vector<Control*>& items, UiRect rc) override;
virtual CSize AjustSizeByChild(const std::vector<Control*>& items, CSize szAvailable) override;
};
class UILIB_API VBox : public Box
{
public:
VBox();
};
}
#endif // UI_CORE_VBOX_H_