我放弃了发现功能,会做我的事,而是让我自己
下面是函数:
local function drawMenu(items, event)
local maxLen = 0;
local itemCount = 0;
for index, action in pairs(items) do
itemCount = itemCount + 1;
if string.len(index) > maxLen then
maxLen = string.len(index);
end
end
local width = maxLen * 5; -- width of the menu frame
local height = (itemCount * 9) + 2; -- height of the menu frame
if event == EVT_EXIT_BREAK then
menu = false;
end
if event == EVT_PLUS_BREAK or event == EVT_ROT_LEFT then
selected = selected + 1;
end
if event == EVT_MINUS_BREAK or event ==EVT_ROT_RIGHT then
selected = selected - 1;
end
count = 0;
actions = {};
lcd.drawFilledRectangle((LCD_W/2) - (width/2), (LCD_H/2) - (height/2), width, height, ERASE);
lcd.drawRectangle((LCD_W/2) - (width/2), (LCD_H/2) - (height/2), width, height, SOLID);
for index, action in pairs(items) do
actions[count] = action;
if count == selected then
lcd.drawText((LCD_W/2) - (width/2) + 3, (LCD_H/2) - (height/2) + (count * 8) + 2, index, 0+ INVERS);
else
lcd.drawText((LCD_W/2) - (width/2) + 3, (LCD_H/2) - (height/2) + (count * 8) + 2, index, 0);
end
count = count + 1;
end
if event == EVT_ROT_BREAK or event == EVT_ENTER_BREAK then
actions[selected]();
menu = false;
end
if selected >= count then
selected = 0;
end
if selected < 0 then
selected = count - 1;
end
end
它接受与字符串索引的功能阵列。索引是菜单中的名称,该功能在用户选择时执行。菜单的大小很差,所以它可能有时太宽。
为了使它工作,你还需要一个全局变量菜单,它应该控制菜单的可见性。您应该打开菜单:
local menu = false;
local function run_func(event)
if event == EVT_MENU_LONG then
menu = true;
end
if menu then
drawMenu(items, event);
end
end
并且还需要选择全局变量。
local selected = 0;
但这种作用是无法完成它不支持滚动,当过多的物品传递给这个函数
截图它的行为可能奇怪:
等都需要“OpenTX”标签。 –
但是没有这样的标签,我没有创建一个 –
的声望,你可能想分享你的代码,你的firmeware版本......也可以考虑在opentx社区询问这个,因为这是非常特殊的。你有没有检查他们的聊天或邮件列表? – Piglet