Merge pull request #62 from lovesnow/development

修复当使用TabBox的RemoteAt方法删除子控件时,选中索引没有重新计算的问题
This commit is contained in:
Dylan 2019-06-28 09:43:18 +08:00 committed by GitHub
commit c2fceb6137
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -16,8 +16,10 @@ bool TabBox::Add(Control* pControl)
if(m_iCurSel == -1 && pControl->IsVisible()) {
m_iCurSel = GetItemIndex(pControl);
}
else {
}
if (m_iCurSel != GetItemIndex(pControl) || !pControl->IsVisible())
{
if (!IsFadeSwitch()) {
pControl->SetVisible(false);
}
@ -27,7 +29,6 @@ bool TabBox::Add(Control* pControl)
}
pControl->SetAlpha(0);
}
return ret;
}
@ -90,6 +91,13 @@ bool TabBox::Remove(Control* pControl)
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;
@ -214,7 +222,7 @@ bool TabBox::SelectItem(const std::wstring& pControlName)
void TabBox::SetAttribute(const std::wstring& strName, const std::wstring& strValue)
{
if( strName == _T("selectedid") ) SelectItem(_ttoi(strValue.c_str()));
if (strName == _T("selectedid")) m_iCurSel = _ttoi(strValue.c_str());
else if( strName == _T("fadeswitch") ) SetFadeSwitch(strValue == _T("true"));
else Box::SetAttribute(strName, strValue);
}

View File

@ -15,6 +15,7 @@ public:
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;