Merge pull request #401 from chrox/master

append page number in toc entry
This commit is contained in:
Qingping Hou
2013-12-19 18:43:20 -08:00
6 changed files with 57 additions and 15 deletions

View File

@@ -38,6 +38,10 @@ DSHOWOVERLAP = false
-- default to false
DSHOWHIDDENFILES = false
-- show file size in filemanager
-- default to false
DSHOWFILESIZE = false
-- customizable tap zones(rectangles)
-- x: x coordinate of top left corner in proportion of screen width
-- y: y coordinate of top left corner in proportion of screen height

View File

@@ -2,6 +2,7 @@ local InputContainer = require("ui/widget/container/inputcontainer")
local FrameContainer = require("ui/widget/container/framecontainer")
local TextWidget = require("ui/widget/textwidget")
local FileChooser = require("ui/widget/filechooser")
local VerticalSpan = require("ui/widget/verticalspan")
local VerticalGroup = require("ui/widget/verticalgroup")
local Font = require("ui/font")
local Screen = require("ui/screen")
@@ -28,13 +29,12 @@ function FileManager:init()
self.show_parent = self.show_parent or self
self.banner = FrameContainer:new{
padding = 0,
bordersize = 0,
self.banner = VerticalGroup:new{
TextWidget:new{
face = Font:getFace("tfont", 24),
text = self.title,
}
},
VerticalSpan:new{ width = Screen:scaleByDPI(10) }
}
local file_chooser = FileChooser:new{

View File

@@ -83,6 +83,7 @@ function ReaderToc:onShowToc()
if #self.toc > 0 and not self.toc[1].text then
for _,v in ipairs(self.toc) do
v.text = (" "):rep(v.depth-1)..self:cleanUpTocTitle(v.title)
v.mandatory = v.page
end
end

View File

@@ -10,6 +10,12 @@ function WidgetContainer:init()
if not self.dimen then
self.dimen = Geom:new{}
end
if not self.dimen.w then
self.dimen.w = self[1].getSize().w
end
if not self.dimen.h then
self.dimen.h = self[1].getSize().h
end
end
function WidgetContainer:getSize()

View File

@@ -10,6 +10,7 @@ local FileChooser = Menu:extend{
path = lfs.currentdir(),
parent = nil,
show_hidden = DSHOWHIDDENFILES,
show_filesize = DSHOWFILESIZE,
filter = function(filename) return true end,
}
@@ -46,7 +47,13 @@ function FileChooser:genItemTableFromPath(path)
table.insert(item_table, { text = dir.."/", path = self.path.."/"..dir })
end
for _, file in ipairs(files) do
table.insert(item_table, { text = file, path = self.path.."/"..file })
local full_path = self.path.."/"..file
if self.show_filesize then
local sstr = string.format("%4.1fM",lfs.attributes(full_path, "size")/1024/1024)
table.insert(item_table, { text = file, mandatory = sstr, path = full_path })
else
table.insert(item_table, { text = file, path = full_path })
end
end
return item_table

View File

@@ -1,5 +1,7 @@
local InputContainer = require("ui/widget/container/inputcontainer")
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local LeftContainer = require("ui/widget/container/leftcontainer")
local RightContainer = require("ui/widget/container/rightcontainer")
local FrameContainer = require("ui/widget/container/framecontainer")
local CenterContainer = require("ui/widget/container/centercontainer")
local BottomContainer = require("ui/widget/container/bottomcontainer")
@@ -8,6 +10,7 @@ local HorizontalSpan = require("ui/widget/horizontalspan")
local FocusManager = require("ui/widget/focusmanager")
local TextWidget = require("ui/widget/textwidget")
local OverlapGroup = require("ui/widget/overlapgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local VerticalGroup = require("ui/widget/verticalgroup")
local HorizontalGroup = require("ui/widget/horizontalgroup")
local Button = require("ui/widget/button")
@@ -111,7 +114,8 @@ local MenuItem = InputContainer:new{
text = nil,
show_parent = nil,
detail = nil,
face = Font:getFace("cfont", 22),
face = Font:getFace("cfont", 30),
info_face = Font:getFace("infont", 15),
dimen = nil,
shortcut = nil,
shortcut_style = "square",
@@ -147,32 +151,51 @@ function MenuItem:init()
}
end
local mandatory = self.mandatory and ""..self.mandatory.." " or ""
local mandatory_w = RenderText:sizeUtf8Text(0, self.dimen.w, self.info_face, ""..mandatory, true).x
w = RenderText:sizeUtf8Text(0, self.dimen.w, self.face, self.text, true).x
if w >= self.content_width then
if w + mandatory_w >= self.content_width then
if Device:isTouchDevice() then
else
self.active_key_events.ShowItemDetail = {
{"Right"}, doc = "show item detail"
}
end
indicator = " >>"
indicator_w = RenderText:sizeUtf8Text(0, self.dimen.w, self.face, indicator, true).x
local indicator = " >> "
local indicator_w = RenderText:sizeUtf8Text(0, self.dimen.w, self.face, indicator, true).x
self.text = RenderText:getSubTextByWidth(self.text, self.face,
self.content_width - indicator_w, true) .. indicator
self.content_width - indicator_w - mandatory_w, true) .. indicator
end
local text_container = LeftContainer:new{
dimen = Geom:new{w = self.content_width},
TextWidget:new{
text = self.text,
face = self.face,
}
}
local mandatory_container = RightContainer:new{
dimen = Geom:new{w = self.content_width},
TextWidget:new{
text = mandatory,
face = self.info_face,
}
}
self._underline_container = UnderlineContainer:new{
dimen = Geom:new{
w = self.content_width,
h = self.dimen.h
},
HorizontalGroup:new {
HorizontalGroup:new{
align = "center",
TextWidget:new{
text = self.text,
face = self.face,
OverlapGroup:new{
text_container,
mandatory_container,
},
},
}
}
self[1] = FrameContainer:new{
@@ -458,6 +481,7 @@ function Menu:updateItems(select_number)
local item_tmp = MenuItem:new{
show_parent = self.show_parent,
text = self.item_table[i].text,
mandatory = self.item_table[i].mandatory,
face = self.cface,
dimen = self.item_dimen:new(),
shortcut = item_shortcut,