我放棄了發現功能,會做我的事,而是讓我自己
下面是函數:
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;
但這種作用是無法完成它不支持滾動,當過多的物品傳遞給這個函數
截圖它的行爲可能奇怪:![enter image description here](https://i.stack.imgur.com/TfRkM.png)
等都需要「OpenTX」標籤。 –
但是沒有這樣的標籤,我沒有創建一個 –
的聲望,你可能想分享你的代碼,你的firmeware版本......也可以考慮在opentx社區詢問這個,因爲這是非常特殊的。你有沒有檢查他們的聊天或郵件列表? – Piglet