duilib 自定义属性列表

好久没动duilib 了==

duilib 自带的默认属性,思想是不错的,但都知道比较难用,一不小心就所有替换,还来个莫名其妙。

<?xml version="1.0" encoding="utf-8"?>
<Window size="800,572" sizebox="4,4,6,6" roundcorner="5,5" caption="0,0,0,90" mininfo="800,570">
  <Default name="VScrollBar" value="..."/>
  <Default name="HScrollBar" value="..."/>

  <VerticalLayout bkcolor="#FFD1E8F5" bkcolor2="#FFC6E0F1" bordercolor="#FF768D9B" bordersize="1" borderround="5,5">
    <TitleCfg height="24"/> <!--标题栏-->
    <HorizontalLayout bkcolor="0xFF00FF00" hscrollbar="true" vscrollbar="true">
        <Button name="my_btn"  pos="40,40,0, 0"  text="my_btn" />
        <Button name="my_btn2" pos="40,80,0, 0"  text="my_btn2" />
        <Button name="my_btn3" pos="40,120,0, 0" text="my_btn3"/>
        <Button name="my_btn4" pos="40,160,0, 0" text="my_btn4"/>       
    </HorizontalLayout>
  </VerticalLayout>
 </Window>

效果是这样的
这里写图片描述

但是我想要整体效果,这么多button,就用Default吧,在xml添加如下

<Default name="Button" value="float=&quot;true&quot; height=&quot;25&quot; width=&quot;60&quot; bkcolor=&quot;#FFF0F0F0&quot; borderround=&quot;5,5&quot; normalimage=&quot;button_nor.bmp&quot; hotimage=&quot;button_down.bmp&quot; focusedimage=&quot;button_over.bmp&quot; "/>

但是看到的效果是
这里写图片描述

影响到了 标题栏 button 出现异常,收到default 影响,
于是就想,为啥不搞的自由点?

哈哈,,,

自己定义个属性列表属性

<?xml version="1.0" encoding="utf-8"?>
<Window size="800,572" sizebox="4,4,6,6" roundcorner="5,5" caption="0,0,0,90" mininfo="800,570">
  <Default name="VScrollBar" value="..."/>
  <Default name="HScrollBar" value="..."/>
  <AttributeList name="Button_default" value="..."/>

  <VerticalLayout bkcolor="#FFD1E8F5" bkcolor2="#FFC6E0F1" bordercolor="#FF768D9B" bordersize="1" borderround="5,5">
    <TitleCfg height="24"/> 
    <HorizontalLayout bkcolor="0xFF00FF00" hscrollbar="true" vscrollbar="true">
        <Button name="my_btn"  pos="40,40,0, 0"  text="my_btn"  AttributeList="Button_default"/>
        <Button name="my_btn2" pos="40,80,0, 0"  text="my_btn2" AttributeList="Button_default" />
        <Button name="my_btn3" pos="40,120,0, 0" text="my_btn3" AttributeList="Button_default"/>
        <Button name="my_btn4" pos="40,160,0, 0" text="my_btn4" AttributeList="Button_default"/>    
    </HorizontalLayout>
  </VerticalLayout>
 </Window>

对应的在每个 Button 添加属性 AttributeList=”Button_default” 就可以使用上面的 ,
剩下的搞定 代码就ok。

1、在解析Default的地方 添加一个 解析AttributeList的默认属性

else if (_tcsicmp(pstrClass, _T("AttributeList")) == 0) {
                nAttributes = node.GetAttributeCount();
                LPCTSTR pControlName = NULL;
                LPCTSTR pControlValue = NULL;
                bool shared = false;
                for (int i = 0; i < nAttributes; i++) {
                    pstrName = node.GetAttributeName(i);
                    pstrValue = node.GetAttributeValue(i);
                    if (_tcsicmp(pstrName, _T("name")) == 0) {
                        pControlName = pstrValue;
                    }
                    else if (_tcsicmp(pstrName, _T("value")) == 0) {
                        pControlValue = pstrValue;
                    }
                    else if (_tcsicmp(pstrName, _T("shared")) == 0) {
                        shared = (_tcsicmp(pstrValue, _T("true")) == 0);
                    }
                }
                if (pControlName) {
                    pManager->AddDefaultAttributeList(pControlName, pControlValue, shared);
                }
            }

2、防止再次解析

CControlUI* CDialogBuilder::_Parse(CMarkupNode* pRoot, CControlUI* pParent, CPaintManagerUI* pManager)
{
    IContainerUI* pContainer = NULL;
    CControlUI* pReturn = NULL;
    for( CMarkupNode node = pRoot->GetChild() ; node.IsValid(); node = node.GetSibling() ) {
        LPCTSTR pstrClass = node.GetName();
        if( _tcsicmp(pstrClass, _T("Image")) == 0 || _tcsicmp(pstrClass, _T("Font")) == 0 \
            || _tcsicmp(pstrClass, _T("Default")) == 0 
            || _tcsicmp(pstrClass, _T("MultiLanguage")) == 0
            || _tcsicmp(pstrClass, _T("AttributeList")) == 0) continue;

3、在控件设置 属性的时候,添加获取解析 这个 AtrributeList就OK了

     // Process attributes
        if( node.HasAttributes() ) {
            // Set ordinary attributes
            int nAttributes = node.GetAttributeCount();
            for( int i = 0; i < nAttributes; i++ ) {
                const CDuiString attribute_name = node.GetAttributeName(i);
                if (attribute_name == _T("AttributeList"))
                {
                    LPCTSTR pDefaultAttributes = pManager->GetDefaultAttributeList(node.GetAttributeValue(i));
                    if (pDefaultAttributes)
                    {
                        pControl->SetAttributeList(pDefaultAttributes);
                    }
                }
                else
                {
                    pControl->SetAttribute(attribute_name, node.GetAttributeValue(i));
                }
            }
        }

看下效果
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值