aardio - 用customPlus库写个漂亮的数独界面

本文展示了如何利用customPlus库创建一个简单的数独界面。代码简洁,主要涉及元素布局和编辑框的交互,当点击数独单元格时,编辑框显示数字,用户输入后验证并更新界面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文演示如何用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();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

卢光庆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值