虚表 —— 使用ownerDrawCustom列类型制作一个单元格内多按钮

光庆 3天前 261

优化了一下 _vlistEx_ColType_OwnerDrawCustom 列类型的使用方法,更简单易用了。

可以省略 ownerDrawCustom() 函数,仅使用 itemModel 列表内定义的内容即可。

可以直接输入 mainForm.vlist.itemModel 使用IDE的自动补全功能,自动创建一个包含所有元素类型和属性的 itemModel 列表。

请更新到最新版虚表(不低于v18.8)。


import win.ui;
import godking.vlistEx;
/*DSG{{*/
mainForm = win.form(text="vlistEx";right=454;bottom=578)
mainForm.add({
vlist={cls="vlistEx";left=10;top=10;right=445;bottom=565;db=1;dl=1;dr=1;dt=1;edge=1;transparent=1;z=1}
})
/*}}*/

var t = { fields={"序号","操作"} };
for(i=1;100;1){
    ..table.push(t,{序号="[@rowindex]"});
}

var itemModel = {
      { /* 按钮1背景 */
        type="rect",
        hover=true,
        rectf={x=80;y=1;width=36;height=20},
        fillcolor=0xFFe7e5e4,
        hoverfillcolor = 0xFF1E90FF,
        width=0,
        round=10,
        smooth=true,
    },
    {   /* 按钮1文本 */
        type="text",
        rectf={x=80;y=1;width=36;height=20},
        name="title1",
        text="应用",
        hover = true;
        font={name="宋体",h=12,color=0xFF555555}, 
        hoverfont={name="宋体",h=12,color=0xFFFFFFFF},
        valign=1,
        align=1,
        smooth=false,
        ellipsion=false;
    },
    {   /* 按钮2背景 */
        type="rect",
        hover=true,
        rectf={x=126;y=1;width=36;height=20},
        fillcolor=0xFFe7e5e4,
        hoverfillcolor = 0xFF1E90FF,
        width=0,
        round=10,
        smooth=true,
    },
     {  /* 按钮2文本 */
        type="text",
        rectf={x=126;y=1;width=36;height=20},
        name="title2",
        text="下载",
        hover = true;
        font={name="宋体",h=12,color=0xFF555555}, 
        hoverfont={name="宋体",h=12,color=0xFFFFFFFF},
        valign=1,
        align=1,
        smooth=false,
        ellipsion=false;
    }
}

mainForm.vlist.setTable(t,,{80,260},1);
mainForm.vlist.setColumnType(2/*列号*/,7/*_vlistEx_ColType_OwnerDrawCustom*/,itemModel);

mainForm.vlist.onClick = function(row/*行*/,col/*列*/,x,y,buttonIndex/*按钮区域序号*/){
	if row and col and buttonIndex {
		if buttonIndex===2 win.msgbox("点击了第"++row++"行的应用");
		if buttonIndex===4 win.msgbox("点击了第"++row++"行的下载");
	}
}

mainForm.show();
win.loopMessage();


最新回复 (4)
  • kio 3天前
    0 引用 2

  • 近我者赤 3天前
    0 引用 3
    mainForm.vlist.setColumnType(2/*列号*/,7/*_vlistEx_ColType_OwnerDrawCustom*/,itemModel); 能设置列的模式,能否弄个支持设置指定单元格的模式的功能??
  • 光庆 2天前
    0 引用 4
    近我者赤 mainForm.vlist.setColumnType(2/*列号*/,7/*_vlistEx_ColType_OwnerDrawCustom*/,itemModel); 能设置列的模式,能否弄个 ...
    技术上来说是没问题的。但是逻辑太复杂,相关数据较多,处理起来可能会影响速度。用列作为单位,就是为了减少内存分配和提升处理速度。
  • 近我者赤 2天前
    0 引用 5
    光庆 技术上来说是没问题的。但是逻辑太复杂,相关数据较多,处理起来可能会影响速度。用列作为单位,就是为了减少内存分配和提升处理速度。
    明白了
返回