Author Topic: Tool-palette Questions  (Read 4692 times)

0 Members and 1 Guest are viewing this topic.

Offline Reo

  • LV3 Member (Next: 100)
  • ***
  • Posts: 64
  • Rating: +15/-0
    • View Profile
Tool-palette Questions
« 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?

Offline jwalker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 660
  • Rating: +13/-0
  • Almost everything I have released includes a 'WZ'
    • View Profile
Re: Tool-palette Questions
« Reply #1 on: December 19, 2011, 11:39:20 pm »
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
<a href="http://www.nerdtests.com/ft_cg.php?im">
<img src="http://www.nerdtests.com/images/ft/cg.php?val=9612" alt="My computer geek score is greater than 41% of all people in the world! How do you compare? Click here to find out!"> </a>

Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Tool-palette Questions
« Reply #2 on: December 19, 2011, 11:48:02 pm »
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.

Offline Nick

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1166
  • Rating: +161/-3
  • You just got omnom'd
    • View Profile
    • Nick Steen
Re: Tool-palette Questions
« Reply #3 on: December 20, 2011, 01:37:52 am »
Code: [Select]
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..

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: Tool-palette Questions
« Reply #4 on: December 20, 2011, 02:25:30 am »
No, it isn't possible to but an image as icon.
You could however create your own menu system which supports that :)

Offline Adriweb

  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1708
  • Rating: +229/-17
    • View Profile
    • TI-Planet.org
Re: Tool-palette Questions
« Reply #5 on: December 20, 2011, 06:34:18 am »
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

Here's the code directly :

Code: [Select]
-----------------------------
-- 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 :



My calculator programs
TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation