some more fixes for menu widget

pull/2/merge
Qingping Hou 12 years ago
parent c9114dabcc
commit 2e3e0d849a

@ -289,29 +289,25 @@ function ItemShortCutIcon:init()
sc_face = Font:getFace("scfont", 22) sc_face = Font:getFace("scfont", 22)
end end
self[1] = HorizontalGroup:new{ self[1] = FrameContainer:new{
HorizontalSpan:new{ width = 5 }, padding = 0,
FrameContainer:new{ bordersize = self.bordersize,
padding = 0, radius = radius,
bordersize = self.bordersize, background = background,
radius = radius, dimen = {
background = background, w = self.width,
h = self.height,
},
CenterContainer:new{
dimen = { dimen = {
w = self.width, w = self.width,
h = self.height, h = self.height,
}, },
CenterContainer:new{ TextWidget:new{
dimen = { text = self.key,
w = self.width, face = sc_face,
h = self.height,
},
TextWidget:new{
text = self.key,
face = sc_face,
},
}, },
}, },
HorizontalSpan:new{ width = 5 },
} }
end end
@ -339,15 +335,19 @@ function MenuItem:init()
end end
self.detail = self.text self.detail = self.text
-- 15 for HorizontalSpan,
self.content_width = self.width - shortcut_icon_w - 15
w = sizeUtf8Text(0, self.width, self.face, self.text, true).x w = sizeUtf8Text(0, self.width, self.face, self.text, true).x
if w >= self.width - shortcut_icon_w then if w >= self.content_width then
indicator = " >>" indicator = " >>"
indicator_w = sizeUtf8Text(0, self.width, self.face, indicator, true).x indicator_w = sizeUtf8Text(0, self.width, self.face, indicator, true).x
self.text = getSubTextByWidth(self.text, self.face, self.text = getSubTextByWidth(self.text, self.face,
self.width - shortcut_icon_w - indicator_w - 4, true) .. indicator self.content_width - indicator_w, true) .. indicator
end end
self[1] = HorizontalGroup:new{ self[1] = HorizontalGroup:new{
HorizontalSpan:new{ width = 5 },
ItemShortCutIcon:new{ ItemShortCutIcon:new{
width = shortcut_icon_w, width = shortcut_icon_w,
height = shortcut_icon_h, height = shortcut_icon_h,
@ -355,10 +355,10 @@ function MenuItem:init()
radius = shortcut_icon_r, radius = shortcut_icon_r,
style = self.shortcut_style, style = self.shortcut_style,
}, },
HorizontalSpan:new{ width = 5 }, HorizontalSpan:new{ width = 10 },
UnderlineContainer:new{ UnderlineContainer:new{
dimen = { dimen = {
w = self.width - 5 - shortcut_icon_w, w = self.content_width,
h = self.height h = self.height
}, },
HorizontalGroup:new { HorizontalGroup:new {
@ -373,12 +373,12 @@ function MenuItem:init()
end end
function MenuItem:onFocus() function MenuItem:onFocus()
self[1][3].color = 10 self[1][4].color = 10
return true return true
end end
function MenuItem:onUnfocus() function MenuItem:onUnfocus()
self[1][3].color = 0 self[1][4].color = 0
return true return true
end end
@ -424,7 +424,7 @@ Menu = FocusManager:new{
function Menu:init() function Menu:init()
self.items = #self.item_table self.items = #self.item_table
self.perpage = math.floor(self.height / self.item_height) self.perpage = math.floor(self.height / self.item_height) - 2
self.page = 1 self.page = 1
self.page_num = math.ceil(self.items / self.perpage) self.page_num = math.ceil(self.items / self.perpage)

Loading…
Cancel
Save