上個教程說到了TreeView的文字不能垂直居中的問題,而咱們用LabelUI實際上是能夠垂直居中的,爲何不說是TreeView的bug,而說是Label控件的bug呢?由於影響TreeView垂直居中的就是Label,能夠發現LabelUI的【屬性列表.XML】裏有valign屬性,而代碼裏卻找不到,是由於valign屬性被合併到align屬性裏去了,只要設置align="center"就能夠水平垂直都居中,可是想要垂直居中,水平左對齊啥的,就犯難了,所以這裏須要將兩個屬性分開,valign管垂直,align管水平,這樣想要怎麼組合都OK啦。css
將CLabelUI::SetAttribute函數裏if( _tcscmp(pstrName, _T("align")) == 0 ) 那一段代碼改爲下面這樣便可。(記得從新編譯duilib哦~)函數
if( _tcscmp(pstrName, _T("align")) == 0 ) { if( _tcsstr(pstrValue, _T("left")) != NULL ) { m_uTextStyle &= ~(DT_CENTER | DT_RIGHT | DT_SINGLELINE); m_uTextStyle |= DT_LEFT; } if( _tcsstr(pstrValue, _T("center")) != NULL ) { m_uTextStyle &= ~(DT_LEFT | DT_RIGHT ); m_uTextStyle |= DT_CENTER; } if( _tcsstr(pstrValue, _T("right")) != NULL ) { m_uTextStyle &= ~(DT_LEFT | DT_CENTER | DT_SINGLELINE); m_uTextStyle |= DT_RIGHT; } } else if( _tcscmp(pstrName, _T("valign")) == 0 ) { if( _tcsstr(pstrValue, _T("top")) != NULL ) { m_uTextStyle &= ~(DT_BOTTOM | DT_VCENTER); m_uTextStyle |= (DT_TOP | DT_SINGLELINE); } if( _tcsstr(pstrValue, _T("vcenter")) != NULL ) { m_uTextStyle &= ~(DT_TOP | DT_BOTTOM ); m_uTextStyle |= (DT_VCENTER | DT_SINGLELINE); } if( _tcsstr(pstrValue, _T("bottom")) != NULL ) { m_uTextStyle &= ~(DT_TOP | DT_VCENTER); m_uTextStyle |= (DT_BOTTOM | DT_SINGLELINE); } }
嗯,實現了垂直居中的效果後,如今貌似和迅雷如出一轍啦?ui
NO,NO,NO,下一節將會繼續介紹~O(∩_∩)O~spa