Merge pull request #198 from chrox/page_button

add page up/down buttons in menus that have more than one pages
pull/201/merge
{Qingping,Dave} Hou 11 years ago
commit 68af46f495

@ -1,10 +1,12 @@
require "ui/widget/image"
require "ui/widget/container"
--[[
a button widget
a button widget that shows text or a icon and handles callback when tapped
--]]
Button = InputContainer:new{
text = nil, -- mandatory
icon = nil,
preselect = false,
callback = nil,
enabled = true,
@ -19,15 +21,22 @@ Button = InputContainer:new{
}
function Button:init()
self.text_widget = TextWidget:new{
text = self.text,
bgcolor = 0.0,
fgcolor = self.enabled and 1.0 or 0.5,
face = Font:getFace(self.text_font_face, self.text_font_size)
}
local text_size = self.text_widget:getSize()
if self.text then
self.label_widget = TextWidget:new{
text = self.text,
bgcolor = 0.0,
fgcolor = self.enabled and 1.0 or 0.5,
face = Font:getFace(self.text_font_face, self.text_font_size)
}
else
self.label_widget = ImageWidget:new{
file = self.icon,
dim = self.enabled,
}
end
local widget_size = self.label_widget:getSize()
if self.width == nil then
self.width = text_size.w
self.width = widget_size.w
end
-- set FrameContainer content
self[1] = FrameContainer:new{
@ -39,9 +48,9 @@ function Button:init()
CenterContainer:new{
dimen = Geom:new{
w = self.width,
h = text_size.h
h = widget_size.h
},
self.text_widget,
self.label_widget,
}
}
if self.preselect then
@ -75,12 +84,48 @@ end
function Button:enable()
self.enabled = true
self.text_widget.fgcolor = 1.0
if self.text then
self.label_widget.fgcolor = self.enabled and 1.0 or 0.5
else
self.label_widget.dim = not self.enabled
end
end
function Button:disable()
self.enabled = false
self.text_widget.fgcolor = 0.5
if self.text then
self.label_widget.fgcolor = self.enabled and 1.0 or 0.5
else
self.label_widget.dim = not self.enabled
end
end
function Button:enableDisable(enable)
if enable then
self:enable()
else
self:disable()
end
end
function Button:hide()
if self.icon then
self.label_widget.hide = true
end
end
function Button:show()
if self.icon then
self.label_widget.hide = false
end
end
function Button:showHide(show)
if show then
self:show()
else
self:hide()
end
end
function Button:onTapSelect()

@ -6,8 +6,10 @@ require "ui/image"
ImageWidget shows an image from a file
--]]
ImageWidget = Widget:new{
invert = nil,
file = nil,
invert = nil,
dim = nil,
hide = nil,
_bb = nil
}
@ -34,10 +36,14 @@ function ImageWidget:paintTo(bb, x, y)
w = size.w,
h = size.h
}
if self.hide then return end
bb:blitFrom(self._bb, x, y, 0, 0, size.w, size.h)
if self.invert then
bb:invertRect(x, y, size.w, size.h)
end
if self.dim then
bb:dimRect(x, y, size.w, size.h)
end
end
function ImageWidget:free()

@ -1,6 +1,7 @@
require "ui/widget/container"
require "ui/widget/focusmanager"
require "ui/widget/infomessage"
require "ui/widget/button"
require "ui/widget/text"
require "ui/widget/group"
require "ui/widget/span"
@ -287,8 +288,27 @@ function Menu:init()
end
-- group for items
self.item_group = VerticalGroup:new{}
self.page_info = TextWidget:new{
face = self.fface,
-- 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,
}
self.page_info_right_chev = Button:new{
icon = "resources/icons/appbar.chevron.right.png",
callback = function() self:onNextPage() end,
bordersize = 0,
}
self.page_info_left_chev:hide()
self.page_info_right_chev:hide()
self.page_info_text = TextWidget:new{
text = "",
face = self.fface,
}
self.page_info = HorizontalGroup:new{
self.page_info_left_chev,
self.page_info_text,
self.page_info_right_chev
}
-- group for menu layout
local content = VerticalGroup:new{
@ -428,9 +448,13 @@ function Menu:updateItems(select_number)
self.item_group[select_number]:onFocus()
end
-- update page information
self.page_info.text = _("page ")..self.page.."/"..self.page_num
self.page_info_text.text = _("page ")..self.page.."/"..self.page_num
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)
else
self.page_info.text = _("no choices available")
self.page_info_text.text = _("no choices available")
end
-- FIXME: this is a dirty hack to clear previous menus
@ -568,5 +592,3 @@ function Menu:onSwipe(arg, ges_ev)
self:onPrevPage()
end
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 410 B

After

Width:  |  Height:  |  Size: 729 B

Loading…
Cancel
Save