-- toolName = LED Matrix Config -- 触屏 + 滚轮双兼容 | 800×480 -- -- ══════════════════════════════════════════════════ -- 配置区 —— 只看这里,所有 xywh 都是绝对值 -- 文字 = lcd.drawText(x, y, txt) -- 盒子 = lcd.drawRectangle(x, y, w, h) -- ══════════════════════════════════════════════════ local cfg = { -- 标题 title = { x=210, y=12, txt="=== LED 灯光配置页面 ===" }, -- ── 行1:LIGHT MODE ───────────────────────────────── mode_row_y = 74, -- 整行文字顶部 Y mode_box_y = 66, -- 整行盒子顶部 Y mode_box_h = 50, mode_arrow_x = 9, -- ">" 箭头 X mode_label_x = 35, -- "LIGHT MODE:" X mode_btn = { { txt_x=210, txt="多色渐变", box_x=200, box_w=170 }, { txt_x=390, txt="固定颜色", box_x=380, box_w=170 }, }, -- ── 行2:颜色行1 4色 (Red/Yellow/Green/Cyan) ─────── c1_row_y = 139, -- 文字顶部 Y c1_box_y = 136, -- 盒子顶部 Y c1_box_h = 29, c1_arrow_x = 12, c1_label_x = 35, c1_btn = { { txt_x=205, txt="红色", box_x=200, box_w=80 }, { txt_x=295, txt="黄色", box_x=290, box_w=80 }, { txt_x=385, txt="绿色", box_x=380, box_w=80 }, { txt_x=475, txt="Cyan", box_x=470, box_w=80 }, }, -- ── 行3:颜色行2 3色 (Blue/Purple/White) ─────────── c2_row_y = 171, c2_box_y = 168, c2_box_h = 26, c2_arrow_x = 12, c2_btn = { { txt_x=205, txt="蓝色", box_x=200, box_w=80 }, { txt_x=295, txt="Purple", box_x=290, box_w=80 }, { txt_x=385, txt="白色", box_x=380, box_w=80 }, }, -- ── 底部提示 ─────────────────────────────────────── footer = { { x=30, y=290, txt="触摸: 按下切换 | 上/下滑动:切换行" }, { x=30, y=310, txt="滚轮: 左右旋转切换行 | 按下切换方框" }, { x=30, y=330, txt="按压 [RTN] 保存并退出" }, }, } -- ══════════════════════════════════════════════════ -- 配置区结束 -- ══════════════════════════════════════════════════ local curLine = 1 -- 1=模式行, 2=颜色行1, 3=颜色行2 local selMode = 0 -- 0=Rainbow, 1=Fixed local selColor = 0 -- 0..6 local colors = { "Red", "Yellow", "Green", "Cyan", "Blue", "Purple", "White" } local function init() selMode = math.max(0, math.min(1, model.getGlobalVariable(0, 0) or 0)) selColor = math.max(0, math.min(6, model.getGlobalVariable(1, 0) or 0)) curLine = 1 end local function inRect(x, y, rx, ry, rw, rh) return x >= rx and x <= rx + rw and y >= ry and y <= ry + rh end local function handleTouch(event, ts) if not ts then return false end local x, y = ts.x, ts.y if event == EVT_TOUCH_TAP or event == EVT_TOUCH_FIRST then -- 模式行 for i = 0, 1 do local b = cfg.mode_btn[i+1] if inRect(x, y, b.box_x, cfg.mode_box_y, b.box_w, cfg.mode_box_h) then curLine=1; selMode=i; return true end end -- 颜色行1 for i = 0, 3 do local b = cfg.c1_btn[i+1] if inRect(x, y, b.box_x, cfg.c1_box_y, b.box_w, cfg.c1_box_h) then curLine=2; selColor=i; return true end end -- 颜色行2 for i = 4, 6 do local b = cfg.c2_btn[i-3] -- index 1..3 if inRect(x, y, b.box_x, cfg.c2_box_y, b.box_w, cfg.c2_box_h) then curLine=3; selColor=i; return true end end elseif event == EVT_TOUCH_SLIDE then if (ts.slideY and ts.slideY < -15) or ts.swipeUp then curLine = math.max(1, curLine - 1); return true elseif (ts.slideY and ts.slideY > 15) or ts.swipeDown then curLine = math.min(3, curLine + 1); return true end end return false end local function handleKey(event) if event == EVT_VIRTUAL_ENTER then if curLine == 1 then selMode = (selMode + 1) % 2 elseif curLine == 2 then if selColor > 3 then selColor = 0 end selColor = (selColor + 1) % 4 elseif curLine == 3 then if selColor < 4 then selColor = 4 end selColor = selColor + 1 if selColor > 6 then selColor = 4 end end return true elseif event == EVT_VIRTUAL_EXIT then model.setGlobalVariable(0, 0, selMode) model.setGlobalVariable(1, 0, selColor) return true elseif event == EVT_ROT_LEFT then curLine = curLine - 1 if curLine < 1 then curLine = 3 end return true elseif event == EVT_ROT_RIGHT then curLine = curLine + 1 if curLine > 3 then curLine = 1 end return true end return false end local function drawBtn(btn, box_y, box_h, row_y, style, active) if active then lcd.drawRectangle(btn.box_x, box_y, btn.box_w, box_h, SOLID) lcd.drawText(btn.txt_x, row_y, btn.txt, style + INVERS) else lcd.drawRectangle(btn.box_x, box_y, btn.box_w, box_h) lcd.drawText(btn.txt_x, row_y, btn.txt, style) end end local function run(event, touchState) local shouldExit = false if touchState then handleTouch(event, touchState) else if handleKey(event) and (event == EVT_VIRTUAL_EXIT) then shouldExit = true end end lcd.clear() lcd.drawText(cfg.title.x, cfg.title.y, cfg.title.txt, MIDSIZE) if curLine == 1 then lcd.drawText(cfg.mode_arrow_x, cfg.mode_row_y, ">", MIDSIZE) end lcd.drawText(cfg.mode_label_x, cfg.mode_row_y, "LIGHT MODE:", 0) for i = 0, 1 do drawBtn(cfg.mode_btn[i+1], cfg.mode_box_y, cfg.mode_box_h, cfg.mode_row_y, MIDSIZE, selMode == i) end if curLine == 2 then lcd.drawText(cfg.c1_arrow_x, cfg.c1_row_y, ">", MIDSIZE) end lcd.drawText(cfg.c1_label_x, cfg.c1_row_y, "SET COLOR :", 0) for i = 0, 3 do drawBtn(cfg.c1_btn[i+1], cfg.c1_box_y, cfg.c1_box_h, cfg.c1_row_y, 0, selColor == i) end if curLine == 3 then lcd.drawText(cfg.c2_arrow_x, cfg.c2_row_y, ">", MIDSIZE) end for i = 4, 6 do drawBtn(cfg.c2_btn[i-3], cfg.c2_box_y, cfg.c2_box_h, cfg.c2_row_y, 0, selColor == i) end for _, f in ipairs(cfg.footer) do lcd.drawText(f.x, f.y, f.txt, SMLSIZE) end return shouldExit and 1 or 0 end return { run=run, init=init }