Omnimaga
Calculator Community => TI Calculators => Lua => Topic started by: Reo on December 19, 2011, 09:19:00 pm
-
1. I'm using the tool-palette function to make a menu. Most of the time when I go to open the menu on my calculator (it's always fine on the PC) it just doesn't open. Is this anything I can fix, or does it just work like that because it's an undocumented feature?
2. Is there any way to get a TI.image as an "icon" in the menu?
3. How likely is it that this feature will be taken out of the next firmware update?
-
ok i can answer at least one of your questions.
1. i tried it on onclua and after you register the menu you have to enable it.
if your menu structure is called "menu" and you have a menu called "Structures" then you have to se this function:
toolpalette.enable("menu", "Structures", true)
2. i dont think you can
-
Reo, the next firmware update shouldn't concern you unless it adds features or fixes deadly bugs (of which there are currently 0, deadly ones, that is). You can totally ignore them otherwise. The community's concern is accidental upgrades or new calcs coming with them.
-
function option1()
--Write the commands here
end
function option2()
--Write the commands here
end
menu = {
{"Options Menu",
{"option 1", option1},
{"option 2", option2}
}
}
toolpalette.register(menu)
this should work..
-
No, it isn't possible to but an image as icon.
You could however create your own menu system which supports that :)
-
You're all right about these questions.
Somethin I want to add, with Jimbauwens' remark is that Levak already implemented his own menu system withcomplete recursive-ness and image/icon support.
You can find some info here :
http://levak.free.fr/ftp/nspire/Make3D/Menu.lua (http://levak.free.fr/ftp/nspire/Make3D/Menu.lua)
Here's the code directly :
-----------------------------
-- Levak ©2011 --------------
-- http://levak.free.fr/ ----
-- [email protected] --------
-----------------------------
------ Menu
Menu = class(Screen())
function Menu:init(items, convert)
if convert then -- the given format is a non-recursive toopalette, convert it
self.items = {}
local Btype2 = 1
for j, button in ipairs(items) do
local subitems, pic = {}, nil
if #button > 1 then
local Btype = 1
for i=2, #button do
if type(button[i]) == "table" then
table.insert(subitems, Button(0, 0, 0, 1.5, normal, button[i][2], button[i][1], button[i][3] or nullButton, nil, Btype))
if not pic and #button[i] > 2 then
pic = button[i][3]
end
if Btype < 3 then
Btype = 3
end
else
Btype = 1
end
end
subitems[#subitems].Btype = subitems[#subitems].Btype and subitems[#subitems].Btype == 1 and 0 or 2
end
self.items[j] = Button(0, 0, 0, 1.5, normal, function() end, button[1], pic or nullButton, Menu(subitems), Btype2)
Btype2 = 3
end
self.items[#self.items].Btype = 2
else
self.items = items
end
self.depth = 1
self.selectedIndex = 0
self.active = true
end
function Menu:format()
local i, xmax, ymax = 1, 0, 0
local gc = platform.gc()
gc:begin()
gc:setFont("sansserif", "r", fxxsmall)
-- Get the maximum width
for _, button in ipairs(self.items) do
if type(button.text) ~= "string" or button.text == "" then
button.active = false
else
button.active = true
ymax = ymax + button.h + button.s
button.text = (i < 10 and tostring(i) or string.uchar(55 + i))..":"..button.text
if gc:getStringWidth(button.text) + button.h + 5 + 10 > xmax then
xmax = gc:getStringWidth(button.text) + button.h + 10 + (button.h+normal)/3
end
i = i + 1
end
end
if #self.items > 0 then
local firstX = self.items[1].x
local firstY = self.items[1].y + self.items[1].s
if firstY + ymax > platform.window:height() then
firstY = platform.window:height() - ymax
end
for i, button in ipairs(self.items) do
button.x = firstX
button.y = firstY
button.w = xmax
if button.child then
if #button.child.items < 1 then
button.active = false
else
button.child.items[1].x = button.x + button.w + button.s + 1
button.child.items[1].y = button.y - button.h - button.s/2
button.child.depth = self.depth + 1
button.child:format()
end
end
firstY = firstY + button.h + button.s
end
end
self.selectedIndex = self:escapeNullElement(1)
gc:finish()
end
function Menu:paint(gc)
for i,button in ipairs(self.items) do
button:paint(gc, i == self.selectedIndex)
end
end
function Menu:charIn(ch)
if ch >= "1" and ch <= "9" then
if self.items[tonumber(ch)] and self.items[tonumber(ch)].active then
self.selectedIndex = tonumber(ch)
self:enterKey()
end
elseif ch >= "a" and ch <= "z" then
local i = string.byte(ch) - 87
if self.items[i] and self.items[i].active then
self.selectedIndex = i
self:enterKey()
end
end
platform.window:invalidate()
end
function Menu:enterKey()
if self.items[self.selectedIndex].child then
local submenu = self.items[self.selectedIndex].child
PushScreen(submenu)
else
for i = 1, self.depth do
PullScreen()
end
self.items[self.selectedIndex].fun()
end
end
function Menu:escapeKey()
PullScreen()
end
function Menu:containsValidItem()
for i, button in ipairs(self.items) do
if button.active then
return true
end
end
return false
end
function Menu:escapeNullElement(n)
local i = (self.selectedIndex + n - 1) % #self.items + 1
-- Is the next item invalid and can we iter anyways ?
if self.items[i].active then
return i
elseif self:containsValidItem() then
self.selectedIndex = i
return self:escapeNullElement(n)
else
return self.selectedIndex
end
end
function Menu:arrowKey(key)
if key == "up" then
self.selectedIndex = self:escapeNullElement(-1)
elseif key == "down" then
self.selectedIndex = self:escapeNullElement(1)
elseif key == "left" then
self:escapeKey()
elseif key == "right" then
if self.items[self.selectedIndex].child then
local submenu = self.items[self.selectedIndex].child
PushScreen(submenu)
end
end
platform.window:invalidate()
end
function Menu:mouseDown(x, y)
local push = false
for i, button in ipairs(self.items) do
if button:isActive(x, y) and button.text ~= "" then
self.selectedIndex = i
self:enterKey()
push = true
end
end
if not push then
PullScreen()
on.mouseDown(x, y)
end
platform.window:invalidate()
end
function Menu:mouseMove(x, y)
for i, button in ipairs(self.items) do
if button:isActive(x, y) and button.text ~= "" then
self.selectedIndex = i
end
end
platform.window:invalidate()
end
-- non used events
function Menu:tabKey() end
function Menu:backtabKey() end
function Menu:contextMenu() end
function Menu:help() end
function Menu:mouseUp() end
Some screenshots :
(http://levak.free.fr/ftp/nspire/Make3D/screens/newMenus_nspire_computer_software.jpg)
(http://levak.free.fr/ftp/nspire/Make3D/screens/newMenus_comparaison_OS.jpg)
(http://levak.free.fr/ftp/nspire/Make3D/screens/newMenus.jpg)