customPlus —— 自定义项目例程

光庆 3小时前 35

import win.ui;
import fonts.fontAwesome
import godking.customPlus;
/*DSG{{*/
var winform = win.form(text="aardio form";right=567;bottom=447)
winform.add(
plus={cls="plus";left=8;top=8;right=560;bottom=440;bgcolor=0xC0DCC0;db=1;dl=1;dr=1;dt=1;notify=1;z=1}
)
/*}}*/

var itemModel = {
    // 1. 卡片背景(最底层)
    {
        type="rect";
        rectf={x=3; y=3; width=-3; height=-3};
        round=8;
        width=1;
        color=0xFFE8E8E8;
        fillcolor=0xFFFFF8EC;
        itemhoveredfillcolor=0xFFF5F0FF;
    };
    // 2. 类型大图标(左侧 FontAwesome)
    {
        name="typeIcon";
        type="text";
        rectf={x=12; y=10; width=40; height=42};
        font={name='FontAwesome'; h=22; color=0xFF3A3A3A};
        align=1; 
        valign=1; 
        smooth=true;
        text='\uF085';
    };
    // 3. 服务名称
    {
        name="svcName";
        type="text";
        rectf={x=56; y=10; width=-8; height=24};
        font={name='Tahoma'; h=14; weight=600; color=0xFF111111};
        align=0; 
        valign=1; 
        smooth=true;
    };
    // 4. 状态图标(FontAwesome,底部左侧)
    {
        name="statusIcon";
        type="text";
        rectf={x=56; y=36; width=20; height=24};
        font={name='FontAwesome'; h=14; color=0xFF107C10};
        align=1; 
        valign=1; 
        smooth=true;
        text='\uF111';
    };
    // 5. 状态文字标签(底部)
    {
        name="statusLabel";
        type="text";
        rectf={x=76; y=36; width=-136; height=24};
        font={name='Tahoma'; h=12; color=0xFF107C10};
        align=0; 
        valign=1; 
    };
    // 6. 停止按钮背景
    {
        name="btnStopBg";
        type="rect";
        rectf={x=-128; y=36; width=-68; height=24};
        round=4; 
        width=1;
        color=0xAAC42B1A; 
        fillcolor=0xFFFF4500;
        hoveredfillcolor=0xFFFF0000;
        hover=true; 
        cursor=32649/*_IDC_HAND*/; 
        click=true;
    };
    // 7. 停止按钮文字
    {
        name="btnStopText";
        type="text";
        rectf={x=-128; y=36; width=-68; height=24};
        font={name='FontAwesome'; h=12; color=0xFFFFFFFF};
        align=1; 
        valign=1; 
        text='\uF28D 停止';
    };
    // 8. 重启按钮背景
    {
        name="btnRestartBg";
        type="rect";
        rectf={x=-64; y=36; width=-8; height=24};
        round=4; 
        width=1;
        color=0xAA876400; 
        fillcolor=0x00FFFFFF;
        hoveredfillcolor=0xFFFFCCAC;
        hover=true; 
        cursor=32649; 
        click=true;
        
    };
    // 9. 重启按钮文字
    {
        name="btnRestartText";
        type="text";
        rectf={x=-64; y=36; width=-8; height=24};
        font={name='FontAwesome'; h=12; color=0xFF876400};
        align=1; 
        valign=1; 
        text='\uF1DA 重启';
    };
    // 10. 启动/操作按钮背景
    {
        name="btnStartBg";
        type="rect";
        rectf={x=-128; y=36; width=-8; height=24};
        round=4; 
        width=1;
        color=0xAA107C10; 
        fillcolor=0xFF90EE90;
        hoveredfillcolor=0xFF7CFC00;
        hover=true; 
        cursor=32649; 
        click=true;
    };
    // 11. 启动/操作按钮文字
    {
        name="btnStartText";
        type="text";
        rectf={x=-128; y=36; width=-8; height=24};
        font={name='FontAwesome'; h=12; color=0xFF000000};
        align=1; 
        valign=1;
        text='\uF061 启动';
    };
 };

itemList = {
	{typeIcon='\uF085'; statusLabel=string.random("运行中","已停止"); svcName="Print Spooler";};
	{typeIcon='\uF084'; statusLabel=string.random("运行中","已停止"); svcName="Windows Firewall";};
	{typeIcon='\uF075'; statusLabel=string.random("运行中","已停止"); svcName="DNS Client";};
	{typeIcon='\uF074'; statusLabel=string.random("运行中","已停止"); svcName="Windows Update";};
	{typeIcon='\uF073'; statusLabel=string.random("运行中","已停止"); svcName="hosts 文件";};
	{typeIcon='\uF072'; statusLabel=string.random("运行中","已停止"); svcName="DNS Client";};
	{typeIcon='\uF071'; statusLabel=string.random("运行中","已停止"); svcName="calc.exe";}
}

var p = godking.customPlus(winform.plus/*plus*/,itemModel,itemList,{
        itemWidth=250,    /*项目宽度*/
        itemHeight=70,    /*项目高度*/
        autoSizeWidth=true,    /*自动根据项目列数及plus宽度调整项目宽度*/
        autoSizeHeight=false,    /*自动根据项目行数及plus高度调整项目高度*/
        colnum=0,     /*项目列数,为0则根据项目宽度和plus宽度自动计算*/
        rownum=0,     /*项目行数,为0则根据项目高度和plus高度自动计算*/
        padLeft=5,    /*plus左边空白距离*/
        padTop=5,    /*plus顶边空白距离*/
        padRight=5,    /*plus右边空白距离*/
        padBottom=5    /*plus底边空白距离*/
})

p.onClick = function(itemIndex/*项目索引*/,elemIndex/*元素索引*/,elemID/*元素id*/,elemName/*元素name*/,pageIndex/*当前页项目索引*/,x/*鼠标X坐标*/,y/*鼠标Y坐标*/,disabled/*项目是否禁用*/,itemRect/*项目区域*/,elemRect/*元素区域*/){
    /*鼠标左键单击非隐藏项目时触发该事件。当项目禁用或没有可点击元素时,默认不触发该事件。可设 allClickEvent=true 启用触发。*/
    if elemName=="btnStartBg" {
    	p.itemList[itemIndex].statusLabel="运行中";
    }
    if elemName=="btnStopBg" {
    	p.itemList[itemIndex].statusLabel="停止";
    }
    if elemName=="btnRestartBg" {
    	win.msgbox("重启完毕");
    }
    p.update(itemIndex);
}

//预设红色字体
var redFont = {name='Tahoma'; h=14; weight=600; color=0xFFFF0000};
p.onDrawElement = function(itemIndex/*项目索引*/,elemIndex/*元素索引*/,elemName/*元素name*/,eleValue/*元素值*/){
	//设置各按钮的隐藏状态
	if elemName=="btnRestartBg" or elemName=="btnRestartText" or elemName=="btnStopBg" or elemName=="btnStopText"  {
		return { hide = p.itemList[itemIndex].statusLabel!="运行中" },true; 
	}
	if elemName=="btnStartBg" or elemName=="btnStartText" {
		return { hide = p.itemList[itemIndex].statusLabel=="运行中" },true; 
	}
	//设置运行时显示图标
	if elemName=="statusIcon" {
		return p.itemList[itemIndex].statusLabel=="运行中"?'\uF01D':'\uF04C'; 
	}
	//运行中的svcName设置为红色
	if elemName=="svcName" and p.itemList[itemIndex].statusLabel=="运行中" {
		return { text=eleValue; font=redFont }; 
	}
}

winform.show();
win.loopMessage();


最新回复 (5)
  • 我高兴 2小时前
    0 2
    oh my god
  • nanyi 2小时前
    0 3
    光大处处有惊喜,十分强大,想着可以用到哪里呢?
  • nanyi 2小时前
    0 4
    提示:需要更新下最新的godking.customPlus
  • yuantian 2小时前
    0 5
    真的棒👍,效果超级好
  • playboyeve 37分钟前
    0 6
    漂亮
返回