|
|
|
@ -204,7 +204,11 @@ Menu = FocusManager:new{
|
|
|
|
|
sface = Font:getFace("scfont", 20),
|
|
|
|
|
|
|
|
|
|
title = "No Title",
|
|
|
|
|
dimen = Geom:new{ w = 500, h = 500 },
|
|
|
|
|
-- default width and height
|
|
|
|
|
width = 500,
|
|
|
|
|
-- height will be calculated according to item number if not given
|
|
|
|
|
height = nil,
|
|
|
|
|
dimen = Geom:new{},
|
|
|
|
|
item_table = {},
|
|
|
|
|
item_shortcuts = {
|
|
|
|
|
"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P",
|
|
|
|
@ -222,17 +226,33 @@ Menu = FocusManager:new{
|
|
|
|
|
|
|
|
|
|
-- set this to true to not paint as popup menu
|
|
|
|
|
is_borderless = false,
|
|
|
|
|
-- close_callback is a function, which is executed when menu is closed
|
|
|
|
|
-- it is usually set by the widget which creates the menu
|
|
|
|
|
close_callback = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Menu:init()
|
|
|
|
|
function Menu:_recalculateDimen()
|
|
|
|
|
self.dimen.w = self.width
|
|
|
|
|
-- if height not given, dynamically calculate it
|
|
|
|
|
self.dimen.h = self.height or (#self.item_table + 2) * 36
|
|
|
|
|
if self.dimen.h > Screen:getHeight() then
|
|
|
|
|
self.dimen.h = Screen:getHeight()
|
|
|
|
|
end
|
|
|
|
|
self.item_dimen = Geom:new{
|
|
|
|
|
w = self.dimen.w,
|
|
|
|
|
h = 36, -- hardcoded for now
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if not self.is_borderless then
|
|
|
|
|
-- we need to substract border, margin and padding
|
|
|
|
|
self.item_dimen.w = self.item_dimen.w - 14
|
|
|
|
|
end
|
|
|
|
|
self.perpage = math.floor(self.dimen.h / self.item_dimen.h) - 2
|
|
|
|
|
self.page = 1
|
|
|
|
|
self.page_num = math.ceil(#self.item_table / self.perpage)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Menu:init()
|
|
|
|
|
self:_recalculateDimen()
|
|
|
|
|
self.page = 1
|
|
|
|
|
|
|
|
|
|
-----------------------------------
|
|
|
|
|
-- start to set up widget layout --
|
|
|
|
@ -262,16 +282,12 @@ function Menu:init()
|
|
|
|
|
self.content_group = content
|
|
|
|
|
|
|
|
|
|
if not self.is_borderless then
|
|
|
|
|
self[1] = CenterContainer:new{
|
|
|
|
|
FrameContainer:new{
|
|
|
|
|
self[1] = FrameContainer:new{
|
|
|
|
|
dimen = self.dimen,
|
|
|
|
|
background = 0,
|
|
|
|
|
radius = math.floor(self.dimen.w/20),
|
|
|
|
|
content
|
|
|
|
|
},
|
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
|
}
|
|
|
|
|
-- we need to substract border, margin and padding
|
|
|
|
|
self.item_dimen.w = self.item_dimen.w - 14
|
|
|
|
|
else
|
|
|
|
|
-- no border for the menu
|
|
|
|
|
self[1] = FrameContainer:new{
|
|
|
|
@ -279,7 +295,7 @@ function Menu:init()
|
|
|
|
|
bordersize = 0,
|
|
|
|
|
padding = 0,
|
|
|
|
|
margin = 0,
|
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
|
dimen = self.dimen,
|
|
|
|
|
content
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
@ -292,6 +308,16 @@ function Menu:init()
|
|
|
|
|
MenuCloseButton:new{
|
|
|
|
|
menu = self,
|
|
|
|
|
})
|
|
|
|
|
self.ges_events.TapCloseAllMenus = {
|
|
|
|
|
GestureRange:new{
|
|
|
|
|
ges = "tap",
|
|
|
|
|
range = Geom:new{
|
|
|
|
|
x = 0, y = 0,
|
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
-- set up keyboard events
|
|
|
|
|
self.key_events.Close = { {"Back"}, doc = "close menu" }
|
|
|
|
@ -323,8 +349,10 @@ function Menu:updateItems(select_number)
|
|
|
|
|
self.layout = {}
|
|
|
|
|
self.item_group:clear()
|
|
|
|
|
self.content_group:resetLayout()
|
|
|
|
|
self:_recalculateDimen()
|
|
|
|
|
|
|
|
|
|
for c = 1, self.perpage do
|
|
|
|
|
-- calculate index in item_table
|
|
|
|
|
local i = (self.page - 1) * self.perpage + c
|
|
|
|
|
if i <= #self.item_table then
|
|
|
|
|
local item_shortcut = nil
|
|
|
|
@ -351,7 +379,15 @@ function Menu:updateItems(select_number)
|
|
|
|
|
menu = self,
|
|
|
|
|
}
|
|
|
|
|
table.insert(self.item_group, item_tmp)
|
|
|
|
|
-- this is for focus manager
|
|
|
|
|
table.insert(self.layout, {item_tmp})
|
|
|
|
|
else
|
|
|
|
|
-- item not enough to fill the whole page, break out of loop
|
|
|
|
|
table.insert(self.item_group,
|
|
|
|
|
VerticalSpan:new{
|
|
|
|
|
width = (self.item_dimen.h * (self.perpage - c + 1))
|
|
|
|
|
})
|
|
|
|
|
break
|
|
|
|
|
end -- if i <= self.items
|
|
|
|
|
end -- for c=1, self.perpage
|
|
|
|
|
if self.item_group[1] then
|
|
|
|
@ -365,7 +401,7 @@ function Menu:updateItems(select_number)
|
|
|
|
|
self.page_info.text = "no choices available"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- FIXME: this is a dirty hack to clear the previous menu
|
|
|
|
|
-- FIXME: this is a dirty hack to clear previous menus
|
|
|
|
|
UIManager.repaint_all = true
|
|
|
|
|
--UIManager:setDirty(self)
|
|
|
|
|
end
|
|
|
|
@ -465,7 +501,7 @@ end
|
|
|
|
|
function Menu:onClose()
|
|
|
|
|
local table_length = #self.item_table_stack
|
|
|
|
|
if table_length == 0 then
|
|
|
|
|
UIManager:close(self)
|
|
|
|
|
self:onCloseAllMenus()
|
|
|
|
|
else
|
|
|
|
|
-- back to parent menu
|
|
|
|
|
parent_item_table = table.remove(self.item_table_stack, table_length)
|
|
|
|
@ -474,3 +510,19 @@ function Menu:onClose()
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Menu:onCloseAllMenus()
|
|
|
|
|
UIManager:close(self)
|
|
|
|
|
if self.close_callback then
|
|
|
|
|
self.close_callback()
|
|
|
|
|
end
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Menu:onTapCloseAllMenus(arg, ges_ev)
|
|
|
|
|
if ges_ev.pos:notIntersectWith(self.dimen) then
|
|
|
|
|
self:onCloseAllMenus()
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|