本文演示如何用customPlus库写个漂亮的数独界面。
得益于customPlus库的特性,所以本例代码简单,只需要定义元素位置即可,不需要为复杂的逻辑烦恼。
效果如下:
代码如下:
import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=329;bottom=329)
winform.add(
plus={cls="plus";left=10;top=10;right=320;bottom=320;notify=1;z=1}
)
/*}}*/
winform.show();
winform.plus.addCtrl(edit={cls="edit";hide=1;text="0";left=460;top=330;right=487;bottom=357;align="center";autohscroll=false;autovscroll=false;bgcolor=65535;font=LOGFONT(h=-14);hidesel=1;num=1;z=2};)
import gdi
var getfontcolor = λ() ..gdi.ARGB(..math.random(200,250),..math.random(200,250),..math.random(200,250));
var getbkcolor = λ() ..gdi.ARGB(..math.random(0,200),..math.random(0,200),..math.random(0,200));
var itemModel = {
{
type="rect", // 类型:rect
rectf={x=3;y=3;width=-3;height=-3},
color=getbkcolor(),
fillcolor=getbkcolor(),
}
}
for(x=1;3;1){
for(y=1;3;1){
..table.push(itemModel,{
type="rect",
rectf={x=6+(y-1)*30;y=6+(x-1)*30;width=27;height=27},
color= getbkcolor(),
fillcolor=getbkcolor()
});
..table.push(itemModel,{
type = "text",
click = true,
name = "ele"++((x-1)*3+y),
id = ((x-1)*3+y);
rectf={x=6+(y-1)*30;y=6+(x-1)*30;width=27;height=27},
font={name="Tahoma",point=11,color= getfontcolor()},
align =1;
valign = 1;
});
}
}
var itemList ={}
var item ={}
for(i=1;9;1){ item["ele"++i] = tostring(i) };
for(i=1;9;1){ ..table.push(itemList,..table.clone(item)) };
import godking.customPlus
var cp = godking.customPlus(winform.plus,itemModel,itemList,{
itemWidth=100, /*项目最小宽度,为0时根据colnum自动计算,所以不能与colnum同时=0*/
itemHeight=100, /*项目最小高度,为0时根据rownum自动计算,所以不能与rownum同时=0*/
rownum=3, /*项目行数,为0时根据itemHeight自动计算,所以不能与itemHeight同时=0*/
colnum=3, /*项目列数,为0时根据itemWidth自动计算,所以不能与itemWidth同时=0*/
bkcolor=0xFFFFFFFF, /*背景颜色*/
padLeft=5, /*plus左边空白距离*/
padTop=5, /*plus顶边空白距离*/
padRight=5, /*plus右边空白距离*/
padBottom=5 /*plus底边空白距离*/
})
var curitem,curelem;
cp.onClick = function(itemIndex/*项目索引*/,elemIndex/*元素索引*/,elemID/*元素id*/,elemName/*元素name*/,pageIndex/*当前页项目索引*/,x/*鼠标X坐标*/,y/*鼠标Y坐标*/,disabled/*项目是否禁用*/,itemRect/*项目区域*/,elemRect/*元素区域*/){
curitem,curelem = itemIndex,elemName;
winform.plus.edit.text = itemList[itemIndex][elemName];
winform.plus.edit.setPos(elemRect.x,elemRect.y);
winform.plus.edit.hide=0;
}
winform.plus.edit.onOk = function(){
if curitem and curelem {
if tonumber(owner.text)>0 and tonumber(owner.text)<10 {
for(i=1;9;1){
if itemList[curitem]["ele"++i] == owner.text {
itemList[curitem]["ele"++i]="";
}
}
itemList[curitem][curelem] = owner.text;
owner.hide = 1;
cp.update();
curitem = null;
curelem = null;
} else {
..win.msgbox("请输入1-9")
}
}
return true;
}
win.loopMessage();