2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local LeftContainer = require("ui/widget/container/leftcontainer")
|
|
|
|
local RightContainer = require("ui/widget/container/rightcontainer")
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
local HorizontalSpan = require("ui/widget/horizontalspan")
|
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
2014-08-05 02:22:57 +00:00
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
|
|
|
local LineWidget = require("ui/widget/linewidget")
|
2013-10-18 20:38:07 +00:00
|
|
|
local IconButton = require("ui/widget/iconbutton")
|
2014-08-05 02:22:57 +00:00
|
|
|
local GestureRange = require("ui/gesturerange")
|
2014-06-05 12:12:47 +00:00
|
|
|
local Button = require("ui/widget/button")
|
2013-10-18 20:38:07 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Device = require("device")
|
|
|
|
local Screen = require("device").screen
|
2013-10-18 20:38:07 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2014-08-05 02:22:57 +00:00
|
|
|
local Font = require("ui/font")
|
2014-11-19 11:53:03 +00:00
|
|
|
local util = require("ffi/util")
|
2014-06-05 04:58:57 +00:00
|
|
|
local DEBUG = require("dbg")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
2014-10-22 13:34:11 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2013-03-14 05:06:42 +00:00
|
|
|
|
|
|
|
--[[
|
|
|
|
TouchMenuItem widget
|
|
|
|
--]]
|
2013-10-18 20:38:07 +00:00
|
|
|
local TouchMenuItem = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
menu = nil,
|
|
|
|
vertical_align = "center",
|
|
|
|
item = nil,
|
|
|
|
dimen = nil,
|
|
|
|
face = Font:getFace("cfont", 22),
|
|
|
|
show_parent = nil,
|
2013-03-14 05:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function TouchMenuItem:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ges_events = {
|
|
|
|
TapSelect = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = self.dimen,
|
|
|
|
},
|
2014-06-05 06:58:53 +00:00
|
|
|
doc = "Select Menu Item",
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
2014-07-02 14:51:27 +00:00
|
|
|
HoldSelect = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
|
|
|
range = self.dimen,
|
|
|
|
},
|
|
|
|
doc = "Hold Menu Item",
|
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
|
2014-05-01 10:37:12 +00:00
|
|
|
local item_enabled = self.item.enabled
|
|
|
|
if self.item.enabled_func then
|
|
|
|
item_enabled = self.item.enabled_func()
|
|
|
|
end
|
2014-06-05 11:06:35 +00:00
|
|
|
local item_checked = self.item.checked
|
|
|
|
if self.item.checked_func then
|
|
|
|
item_checked = self.item.checked_func()
|
|
|
|
end
|
|
|
|
local checked_widget = TextWidget:new{
|
|
|
|
text = "√ ",
|
|
|
|
face = self.face,
|
|
|
|
}
|
|
|
|
local unchecked_widget = TextWidget:new{
|
|
|
|
text = "",
|
|
|
|
face = self.face,
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
self.item_frame = FrameContainer:new{
|
|
|
|
width = self.dimen.w,
|
|
|
|
bordersize = 0,
|
2014-10-22 13:34:11 +00:00
|
|
|
color = Blitbuffer.COLOR_BLACK,
|
2014-03-13 13:52:43 +00:00
|
|
|
HorizontalGroup:new {
|
|
|
|
align = "center",
|
2014-06-05 11:06:35 +00:00
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{ w = checked_widget:getSize().w },
|
|
|
|
item_checked and checked_widget or unchecked_widget
|
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
TextWidget:new{
|
|
|
|
text = self.item.text or self.item.text_func(),
|
2014-10-22 13:34:11 +00:00
|
|
|
fgcolor = Blitbuffer.gray(item_enabled ~= false and 1.0 or 0.5),
|
2014-03-13 13:52:43 +00:00
|
|
|
face = self.face,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
self[1] = self.item_frame
|
2013-03-14 05:06:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function TouchMenuItem:onTapSelect(arg, ges)
|
2014-05-01 10:37:12 +00:00
|
|
|
local enabled = self.item.enabled
|
|
|
|
if self.item.enabled_func then
|
|
|
|
enabled = self.item.enabled_func()
|
|
|
|
end
|
|
|
|
if enabled == false then return end
|
|
|
|
|
2014-11-14 14:07:14 +00:00
|
|
|
UIManager:scheduleIn(0.0, function()
|
|
|
|
self.item_frame.invert = true
|
2014-11-30 00:12:00 +00:00
|
|
|
UIManager:setDirty(self.show_parent, function()
|
2015-04-26 18:07:17 +00:00
|
|
|
return "ui", self.dimen
|
2014-11-30 00:12:00 +00:00
|
|
|
end)
|
2014-11-14 14:07:14 +00:00
|
|
|
end)
|
2014-11-12 07:39:04 +00:00
|
|
|
UIManager:scheduleIn(0.1, function()
|
|
|
|
self.menu:onMenuSelect(self.item)
|
|
|
|
end)
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:scheduleIn(0.5, function()
|
|
|
|
self.item_frame.invert = false
|
2014-11-30 00:12:00 +00:00
|
|
|
UIManager:setDirty(self.show_parent, function()
|
2015-04-26 18:07:17 +00:00
|
|
|
return "ui", self.dimen
|
2014-11-30 00:12:00 +00:00
|
|
|
end)
|
2014-03-13 13:52:43 +00:00
|
|
|
end)
|
2014-10-30 07:51:31 +00:00
|
|
|
return true
|
2013-03-14 05:06:42 +00:00
|
|
|
end
|
|
|
|
|
2014-07-02 14:51:27 +00:00
|
|
|
function TouchMenuItem:onHoldSelect(arg, ges)
|
|
|
|
local enabled = self.item.enabled
|
|
|
|
if self.item.enabled_func then
|
|
|
|
enabled = self.item.enabled_func()
|
|
|
|
end
|
|
|
|
if enabled == false then return end
|
|
|
|
|
2014-11-14 14:07:14 +00:00
|
|
|
UIManager:scheduleIn(0.0, function()
|
|
|
|
self.item_frame.invert = true
|
2014-11-30 00:12:00 +00:00
|
|
|
UIManager:setDirty(self.show_parent, function()
|
2015-04-26 18:07:17 +00:00
|
|
|
return "ui", self.dimen
|
2014-11-30 00:12:00 +00:00
|
|
|
end)
|
2014-11-14 14:07:14 +00:00
|
|
|
end)
|
2014-11-12 07:39:04 +00:00
|
|
|
UIManager:scheduleIn(0.1, function()
|
|
|
|
self.menu:onMenuHold(self.item)
|
|
|
|
end)
|
2014-07-02 14:51:27 +00:00
|
|
|
UIManager:scheduleIn(0.5, function()
|
|
|
|
self.item_frame.invert = false
|
2014-11-30 00:12:00 +00:00
|
|
|
UIManager:setDirty(self.show_parent, function()
|
2015-04-26 18:07:17 +00:00
|
|
|
return "ui", self.dimen
|
2014-11-30 00:12:00 +00:00
|
|
|
end)
|
2014-07-02 14:51:27 +00:00
|
|
|
end)
|
2014-10-30 07:51:31 +00:00
|
|
|
return true
|
2014-07-02 14:51:27 +00:00
|
|
|
end
|
2013-03-14 05:06:42 +00:00
|
|
|
|
|
|
|
--[[
|
|
|
|
TouchMenuBar widget
|
|
|
|
--]]
|
2013-10-18 20:38:07 +00:00
|
|
|
local TouchMenuBar = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
width = Screen:getWidth(),
|
|
|
|
icons = {},
|
|
|
|
-- touch menu that holds the bar, used for trigger repaint on icons
|
|
|
|
show_parent = nil,
|
|
|
|
menu = nil,
|
2013-03-14 05:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function TouchMenuBar:init()
|
2014-11-20 22:07:39 +00:00
|
|
|
local icon_sep_width = Screen:scaleBySize(2)
|
2014-05-28 12:05:38 +00:00
|
|
|
local icons_sep_width = icon_sep_width * (#self.icons + 1)
|
2014-06-05 04:58:57 +00:00
|
|
|
-- we assume all icons are of the same width
|
|
|
|
local ib = IconButton:new{icon_file = self.icons[1]}
|
|
|
|
local content_width = ib:getSize().w * #self.icons + icons_sep_width
|
|
|
|
local spacing_width = (self.width - content_width)/(#self.icons*2)
|
|
|
|
local spacing = HorizontalSpan:new{
|
2014-11-20 22:07:39 +00:00
|
|
|
width = math.min(spacing_width, Screen:scaleBySize(20))
|
2014-06-05 04:58:57 +00:00
|
|
|
}
|
2014-11-20 22:07:39 +00:00
|
|
|
self.height = ib:getSize().h + Screen:scaleBySize(10)
|
2014-06-05 04:58:57 +00:00
|
|
|
self.show_parent = self.show_parent or self
|
|
|
|
self.bar_icon_group = HorizontalGroup:new{}
|
2014-03-13 13:52:43 +00:00
|
|
|
-- build up image widget for menu icon bar
|
|
|
|
self.icon_widgets = {}
|
2014-05-28 12:05:38 +00:00
|
|
|
-- hold icon seperators
|
|
|
|
self.icon_seps = {}
|
2014-11-11 02:06:17 +00:00
|
|
|
-- hold all icon buttons
|
|
|
|
self.icon_buttons = {}
|
2014-03-13 13:52:43 +00:00
|
|
|
-- the start_seg for first icon_widget should be 0
|
|
|
|
-- we asign negative here to offset it in the loop
|
2014-05-28 12:05:38 +00:00
|
|
|
local start_seg = -icon_sep_width
|
|
|
|
local end_seg = start_seg
|
2014-03-13 13:52:43 +00:00
|
|
|
for k, v in ipairs(self.icons) do
|
|
|
|
local ib = IconButton:new{
|
|
|
|
show_parent = self.show_parent,
|
|
|
|
icon_file = v,
|
|
|
|
callback = nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
table.insert(self.icon_widgets, HorizontalGroup:new{
|
2014-05-28 12:05:38 +00:00
|
|
|
spacing, ib, spacing,
|
2014-03-13 13:52:43 +00:00
|
|
|
})
|
|
|
|
|
2014-11-11 02:06:17 +00:00
|
|
|
table.insert(self.icon_buttons, ib)
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
-- we have to use local variable here for closure callback
|
2014-05-28 12:05:38 +00:00
|
|
|
local _start_seg = end_seg + icon_sep_width
|
2014-03-13 13:52:43 +00:00
|
|
|
local _end_seg = _start_seg + self.icon_widgets[k]:getSize().w
|
|
|
|
|
|
|
|
if k == 1 then
|
|
|
|
self.bar_sep = LineWidget:new{
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
2014-11-20 22:07:39 +00:00
|
|
|
h = Screen:scaleBySize(2),
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
empty_segments = {
|
|
|
|
{
|
|
|
|
s = _start_seg, e = _end_seg
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2014-05-28 12:05:38 +00:00
|
|
|
local icon_sep = LineWidget:new{
|
|
|
|
style = k == 1 and "solid" or "none",
|
|
|
|
dimen = Geom:new{
|
2014-11-20 22:07:39 +00:00
|
|
|
w = Screen:scaleBySize(2),
|
2014-05-28 12:05:38 +00:00
|
|
|
h = self.height,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
table.insert(self.icon_seps, icon_sep)
|
|
|
|
|
|
|
|
-- callback to set visual style
|
2014-03-13 13:52:43 +00:00
|
|
|
ib.callback = function()
|
|
|
|
self.bar_sep.empty_segments = {
|
|
|
|
{
|
|
|
|
s = _start_seg, e = _end_seg
|
|
|
|
}
|
|
|
|
}
|
2014-05-28 12:05:38 +00:00
|
|
|
for i, sep in ipairs(self.icon_seps) do
|
|
|
|
local current_icon = i == k - 1 or i == k
|
|
|
|
self.icon_seps[i].style = current_icon and "solid" or "none"
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
self.menu:switchMenuTab(k)
|
|
|
|
end
|
|
|
|
|
|
|
|
table.insert(self.bar_icon_group, self.icon_widgets[k])
|
|
|
|
table.insert(self.bar_icon_group, icon_sep)
|
|
|
|
|
|
|
|
start_seg = _start_seg
|
|
|
|
end_seg = _end_seg
|
|
|
|
end
|
|
|
|
|
|
|
|
self[1] = FrameContainer:new{
|
|
|
|
bordersize = 0,
|
|
|
|
padding = 0,
|
|
|
|
VerticalGroup:new{
|
|
|
|
align = "left",
|
|
|
|
-- bar icons
|
|
|
|
self.bar_icon_group,
|
2014-05-28 12:05:38 +00:00
|
|
|
-- horizontal separate line
|
2014-03-13 13:52:43 +00:00
|
|
|
self.bar_sep
|
|
|
|
},
|
|
|
|
}
|
2014-06-05 04:58:57 +00:00
|
|
|
self.dimen = Geom:new{ w = self.width, h = self.height }
|
2013-03-14 05:06:42 +00:00
|
|
|
end
|
|
|
|
|
2014-11-11 02:06:17 +00:00
|
|
|
function TouchMenuBar:switchToTab(index)
|
|
|
|
self.icon_buttons[index].callback()
|
|
|
|
end
|
2013-03-14 05:06:42 +00:00
|
|
|
|
|
|
|
--[[
|
2014-06-05 12:12:47 +00:00
|
|
|
TouchMenu widget for hierarchical menus
|
2013-03-14 05:06:42 +00:00
|
|
|
--]]
|
2013-10-18 20:38:07 +00:00
|
|
|
local TouchMenu = InputContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
tab_item_table = {},
|
|
|
|
-- for returnning in multi-level menus
|
|
|
|
item_table_stack = nil,
|
|
|
|
item_table = nil,
|
2014-11-20 22:07:39 +00:00
|
|
|
item_height = Screen:scaleBySize(50),
|
|
|
|
bordersize = Screen:scaleBySize(2),
|
|
|
|
padding = Screen:scaleBySize(5),
|
2014-06-10 13:32:49 +00:00
|
|
|
fface = Font:getFace("ffont", 20),
|
2014-03-13 13:52:43 +00:00
|
|
|
width = nil,
|
|
|
|
height = nil,
|
|
|
|
page = 1,
|
|
|
|
max_per_page = 10,
|
|
|
|
-- for UIManager:setDirty
|
|
|
|
show_parent = nil,
|
|
|
|
cur_tab = -1,
|
|
|
|
close_callback = nil,
|
2013-03-14 05:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function TouchMenu:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.show_parent = self.show_parent or self
|
|
|
|
if not self.close_callback then
|
|
|
|
self.close_callback = function()
|
|
|
|
UIManager:close(self.show_parent)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self.ges_events.TapCloseAllMenus = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = Geom:new{
|
|
|
|
x = 0, y = 0,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = Screen:getHeight(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.ges_events.Swipe = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "swipe",
|
|
|
|
range = self.dimen,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-10 07:57:10 +00:00
|
|
|
self.key_events.Close = { {"Back"}, doc = "close touch menu" }
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
local icons = {}
|
|
|
|
for _,v in ipairs(self.tab_item_table) do
|
|
|
|
table.insert(icons, v.icon)
|
|
|
|
end
|
|
|
|
self.bar = TouchMenuBar:new{
|
|
|
|
width = self.width - self.padding * 2 - self.bordersize * 2,
|
|
|
|
icons = icons,
|
|
|
|
show_parent = self.show_parent,
|
|
|
|
menu = self,
|
|
|
|
}
|
|
|
|
|
|
|
|
self.item_group = VerticalGroup:new{
|
|
|
|
align = "left",
|
|
|
|
}
|
2014-06-05 12:12:47 +00:00
|
|
|
-- group for page info
|
|
|
|
self.page_info_left_chev = Button:new{
|
|
|
|
icon = "resources/icons/appbar.chevron.left.png",
|
|
|
|
callback = function() self:onPrevPage() end,
|
|
|
|
bordersize = 0,
|
|
|
|
show_parent = self,
|
|
|
|
}
|
|
|
|
self.page_info_right_chev = Button:new{
|
|
|
|
icon = "resources/icons/appbar.chevron.right.png",
|
|
|
|
callback = function() self:onNextPage() end,
|
|
|
|
bordersize = 0,
|
|
|
|
show_parent = self,
|
|
|
|
}
|
|
|
|
self.page_info_left_chev:hide()
|
|
|
|
self.page_info_right_chev:hide()
|
|
|
|
self.page_info_text = TextWidget:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
text = "",
|
2014-06-05 12:12:47 +00:00
|
|
|
face = self.fface,
|
|
|
|
}
|
|
|
|
self.page_info = HorizontalGroup:new{
|
|
|
|
self.page_info_left_chev,
|
|
|
|
self.page_info_text,
|
|
|
|
self.page_info_right_chev
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2014-09-14 14:05:28 +00:00
|
|
|
--group for device info
|
2014-03-13 13:52:43 +00:00
|
|
|
self.time_info = TextWidget:new{
|
|
|
|
text = "",
|
2014-06-05 12:12:47 +00:00
|
|
|
face = self.fface,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2014-11-11 04:12:34 +00:00
|
|
|
self.device_info = HorizontalGroup:new{
|
|
|
|
self.time_info,
|
|
|
|
}
|
2014-11-20 10:02:28 +00:00
|
|
|
local up_button = IconButton:new{
|
|
|
|
icon_file = "resources/icons/appbar.chevron.up.png",
|
|
|
|
show_parent = self.show_parent,
|
|
|
|
callback = function()
|
|
|
|
self:backToUpperMenu()
|
|
|
|
end,
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
local footer_width = self.width - self.padding*2 - self.bordersize*2
|
2014-11-20 22:07:39 +00:00
|
|
|
local footer_height = up_button:getSize().h + Screen:scaleBySize(2)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.footer = HorizontalGroup:new{
|
|
|
|
LeftContainer:new{
|
2014-11-20 10:02:28 +00:00
|
|
|
dimen = Geom:new{ w = footer_width*0.33, h = footer_height},
|
|
|
|
up_button,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
CenterContainer:new{
|
2014-11-20 10:02:28 +00:00
|
|
|
dimen = Geom:new{ w = footer_width*0.33, h = footer_height},
|
2014-06-05 12:12:47 +00:00
|
|
|
self.page_info,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
RightContainer:new{
|
2014-11-20 10:02:28 +00:00
|
|
|
dimen = Geom:new{ w = footer_width*0.33, h = footer_height},
|
2014-09-14 14:05:28 +00:00
|
|
|
self.device_info,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self[1] = FrameContainer:new{
|
|
|
|
padding = self.padding,
|
|
|
|
bordersize = self.bordersize,
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2014-03-13 13:52:43 +00:00
|
|
|
-- menubar and footer will be inserted in
|
|
|
|
-- item_group in updateItems
|
|
|
|
self.item_group,
|
|
|
|
}
|
|
|
|
|
2014-11-11 02:06:17 +00:00
|
|
|
self.bar:switchToTab(self.last_index or 1)
|
2014-03-13 13:52:43 +00:00
|
|
|
self:updateItems()
|
2013-03-14 05:06:42 +00:00
|
|
|
end
|
|
|
|
|
2014-12-01 16:21:42 +00:00
|
|
|
function TouchMenu:onCloseWidget()
|
|
|
|
UIManager:setDirty(nil, "partial", self.dimen)
|
|
|
|
end
|
|
|
|
|
2013-03-14 05:06:42 +00:00
|
|
|
function TouchMenu:_recalculateDimen()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.dimen.w = self.width
|
|
|
|
|
|
|
|
-- if height not given, dynamically calculate it
|
|
|
|
if not self.height then
|
|
|
|
self.dimen.h = (#self.item_table + 2) * self.item_height
|
|
|
|
+ self.bar:getSize().h
|
|
|
|
else
|
|
|
|
self.dimen.h = self.height
|
|
|
|
end
|
|
|
|
-- make sure self.dimen.h does not overflow screen height
|
|
|
|
if self.dimen.h > Screen:getHeight() then
|
|
|
|
self.dimen.h = Screen:getHeight() - self.bar:getSize().h
|
|
|
|
end
|
|
|
|
|
|
|
|
self.perpage = math.floor(self.dimen.h / self.item_height) - 2
|
|
|
|
if self.perpage > self.max_per_page then
|
|
|
|
self.perpage = self.max_per_page
|
|
|
|
end
|
|
|
|
|
|
|
|
self.page_num = math.ceil(#self.item_table / self.perpage)
|
2013-03-14 05:06:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function TouchMenu:updateItems()
|
2014-11-30 12:04:33 +00:00
|
|
|
local old_dimen = self.dimen and self.dimen:copy()
|
2014-03-13 13:52:43 +00:00
|
|
|
self:_recalculateDimen()
|
|
|
|
self.item_group:clear()
|
|
|
|
table.insert(self.item_group, self.bar)
|
|
|
|
|
|
|
|
local item_width = self.dimen.w - self.padding*2 - self.bordersize*2
|
|
|
|
|
|
|
|
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_tmp = TouchMenuItem:new{
|
|
|
|
item = self.item_table[i],
|
|
|
|
menu = self,
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = item_width,
|
|
|
|
h = self.item_height,
|
|
|
|
},
|
|
|
|
show_parent = self.show_parent,
|
|
|
|
}
|
|
|
|
table.insert(self.item_group, item_tmp)
|
|
|
|
-- insert split line
|
|
|
|
if c ~= self.perpage then
|
|
|
|
table.insert(self.item_group, HorizontalGroup:new{
|
|
|
|
-- pad with 10 pixel to align with the up arrow in footer
|
|
|
|
HorizontalSpan:new{width = 10},
|
|
|
|
LineWidget:new{
|
|
|
|
style = "dashed",
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = item_width - 20,
|
|
|
|
h = 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- item not enough to fill the whole page, break out of loop
|
|
|
|
--table.insert(self.item_group,
|
|
|
|
--VerticalSpan:new{
|
|
|
|
--width = self.item_height
|
|
|
|
--})
|
|
|
|
--break
|
|
|
|
end -- if i <= self.items
|
|
|
|
end -- for c=1, self.perpage
|
|
|
|
|
2014-11-20 22:07:39 +00:00
|
|
|
table.insert(self.item_group, VerticalSpan:new{width = Screen:scaleBySize(2)})
|
2014-03-13 13:52:43 +00:00
|
|
|
table.insert(self.item_group, self.footer)
|
2014-11-19 11:23:37 +00:00
|
|
|
self.page_info_text.text = util.template(_("Page %1 of %2"), self.page, self.page_num)
|
2014-06-05 12:12:47 +00:00
|
|
|
self.page_info_left_chev:showHide(self.page_num > 1)
|
|
|
|
self.page_info_right_chev:showHide(self.page_num > 1)
|
|
|
|
self.page_info_left_chev:enableDisable(self.page > 1)
|
|
|
|
self.page_info_right_chev:enableDisable(self.page < self.page_num)
|
2014-07-07 03:37:16 +00:00
|
|
|
self.time_info.text = os.date("%H:%M").." @ "..Device:getPowerDevice():getCapacity().."%"
|
2014-11-30 12:04:33 +00:00
|
|
|
|
|
|
|
UIManager:setDirty("all", function()
|
|
|
|
local refresh_dimen =
|
|
|
|
old_dimen and old_dimen:combine(self.dimen)
|
|
|
|
or self.dimen
|
2015-04-26 18:10:18 +00:00
|
|
|
return "ui", refresh_dimen
|
2014-11-30 12:04:33 +00:00
|
|
|
end)
|
2013-03-14 05:06:42 +00:00
|
|
|
end
|
2014-09-14 14:05:28 +00:00
|
|
|
|
2013-03-14 05:06:42 +00:00
|
|
|
function TouchMenu:switchMenuTab(tab_num)
|
2014-11-11 02:06:17 +00:00
|
|
|
if self.tab_item_table[tab_num].remember ~= false then
|
|
|
|
self.last_index = tab_num
|
|
|
|
end
|
2014-11-05 04:15:07 +00:00
|
|
|
if self.touch_menu_callback then
|
|
|
|
self.touch_menu_callback()
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.tab_item_table[tab_num].callback then
|
|
|
|
self.tab_item_table[tab_num].callback()
|
|
|
|
end
|
|
|
|
if self.cur_tab ~= tab_num then
|
|
|
|
-- it's like getting a new menu everytime we switch tab!
|
|
|
|
self.page = 1
|
|
|
|
-- clear item table stack
|
|
|
|
self.item_table_stack = {}
|
|
|
|
self.cur_tab = tab_num
|
|
|
|
self.item_table = self.tab_item_table[tab_num]
|
|
|
|
self:updateItems()
|
|
|
|
end
|
2013-03-15 09:18:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function TouchMenu:backToUpperMenu()
|
2014-03-13 13:52:43 +00:00
|
|
|
if #self.item_table_stack ~= 0 then
|
|
|
|
self.item_table = table.remove(self.item_table_stack)
|
|
|
|
self.page = 1
|
|
|
|
self:updateItems()
|
2014-11-30 12:04:33 +00:00
|
|
|
else
|
|
|
|
self:closeMenu()
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2013-03-14 05:06:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function TouchMenu:closeMenu()
|
2014-03-13 13:52:43 +00:00
|
|
|
self.close_callback()
|
2013-03-14 05:06:42 +00:00
|
|
|
end
|
|
|
|
|
2013-03-16 00:30:42 +00:00
|
|
|
function TouchMenu:onNextPage()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.page < self.page_num then
|
|
|
|
self.page = self.page + 1
|
|
|
|
self:updateItems()
|
|
|
|
end
|
|
|
|
return true
|
2013-03-16 00:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function TouchMenu:onPrevPage()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.page > 1 then
|
|
|
|
self.page = self.page - 1
|
|
|
|
self:updateItems()
|
|
|
|
end
|
|
|
|
return true
|
2013-03-16 00:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function TouchMenu:onSwipe(arg, ges_ev)
|
2014-03-13 13:52:43 +00:00
|
|
|
if ges_ev.direction == "west" or ges_ev.direction == "north" then
|
|
|
|
self:onNextPage()
|
|
|
|
elseif ges_ev.direction == "east" or ges_ev.direction == "south" then
|
|
|
|
self:onPrevPage()
|
|
|
|
end
|
2013-03-16 00:30:42 +00:00
|
|
|
end
|
|
|
|
|
2013-03-14 05:06:42 +00:00
|
|
|
function TouchMenu:onMenuSelect(item)
|
2014-11-05 04:15:07 +00:00
|
|
|
if self.touch_menu_callback then
|
|
|
|
self.touch_menu_callback()
|
|
|
|
end
|
2014-08-05 02:22:57 +00:00
|
|
|
if item.tap_input then
|
|
|
|
self:closeMenu()
|
2015-04-13 06:45:02 +00:00
|
|
|
self:onInput(item.tap_input)
|
2014-08-05 02:22:57 +00:00
|
|
|
else
|
|
|
|
local sub_item_table = item.sub_item_table
|
|
|
|
if item.sub_item_table_func then
|
|
|
|
sub_item_table = item.sub_item_table_func()
|
|
|
|
end
|
|
|
|
if sub_item_table == nil then
|
2015-03-12 06:19:10 +00:00
|
|
|
-- keep menu opened if this item is a check option
|
|
|
|
local callback, refresh = item.callback, item.checked or item.checked_func
|
2014-08-05 02:22:57 +00:00
|
|
|
if item.callback_func then
|
|
|
|
callback = item.callback_func()
|
|
|
|
end
|
|
|
|
if callback then
|
2014-11-14 14:07:14 +00:00
|
|
|
-- put stuff in scheduler so we can see
|
2014-08-05 02:22:57 +00:00
|
|
|
-- the effect of inverted menu item
|
|
|
|
UIManager:scheduleIn(0.1, function()
|
|
|
|
callback()
|
2015-03-12 06:19:10 +00:00
|
|
|
if refresh then
|
|
|
|
self:updateItems()
|
|
|
|
else
|
|
|
|
self:closeMenu()
|
|
|
|
end
|
2014-08-05 02:22:57 +00:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
table.insert(self.item_table_stack, self.item_table)
|
|
|
|
self.item_table = sub_item_table
|
|
|
|
self:updateItems()
|
|
|
|
end
|
2014-05-01 10:37:12 +00:00
|
|
|
end
|
2014-08-05 02:22:57 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function TouchMenu:onMenuHold(item)
|
2014-11-05 04:15:07 +00:00
|
|
|
if self.touch_menu_callback then
|
|
|
|
self.touch_menu_callback()
|
|
|
|
end
|
2014-08-05 02:22:57 +00:00
|
|
|
if item.hold_input then
|
|
|
|
self:closeMenu()
|
2015-04-13 06:45:02 +00:00
|
|
|
self:onInput(item.hold_input)
|
2014-08-05 02:22:57 +00:00
|
|
|
else
|
|
|
|
local callback = item.hold_callback
|
|
|
|
if item.hold_callback_func then
|
|
|
|
callback = item.hold_callback_func()
|
2014-05-01 10:37:12 +00:00
|
|
|
end
|
|
|
|
if callback then
|
2014-03-13 13:52:43 +00:00
|
|
|
UIManager:scheduleIn(0.1, function()
|
|
|
|
self:closeMenu()
|
2014-05-01 10:37:12 +00:00
|
|
|
callback()
|
2014-03-13 13:52:43 +00:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return true
|
2013-03-14 05:06:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function TouchMenu:onTapCloseAllMenus(arg, ges_ev)
|
2014-03-13 13:52:43 +00:00
|
|
|
if ges_ev.pos:notIntersectWith(self.dimen) then
|
|
|
|
self:closeMenu()
|
|
|
|
end
|
2013-03-14 05:06:42 +00:00
|
|
|
end
|
|
|
|
|
2014-06-10 07:57:10 +00:00
|
|
|
function TouchMenu:onClose()
|
|
|
|
self:closeMenu()
|
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return TouchMenu
|