style: clean up statuswidget a bit

pull/1804/head
Qingping Hou 8 years ago
parent e4a9b60277
commit b8ee33871f

@ -1,7 +1,6 @@
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local FrameContainer = require("ui/widget/container/framecontainer") local FrameContainer = require("ui/widget/container/framecontainer")
local CenterContainer = require("ui/widget/container/centercontainer") local CenterContainer = require("ui/widget/container/centercontainer")
local RightContainer = require("ui/widget/container/rightcontainer")
local LeftContainer = require("ui/widget/container/leftcontainer") local LeftContainer = require("ui/widget/container/leftcontainer")
local HorizontalGroup = require("ui/widget/horizontalgroup") local HorizontalGroup = require("ui/widget/horizontalgroup")
local VerticalGroup = require("ui/widget/verticalgroup") local VerticalGroup = require("ui/widget/verticalgroup")
@ -27,8 +26,6 @@ local Font = require("ui/font")
local TimeVal = require("ui/timeval") local TimeVal = require("ui/timeval")
local RenderText = require("ui/rendertext") local RenderText = require("ui/rendertext")
local DocSettings = require("docsettings")
local DEBUG = require("dbg")
local util = require("util") local util = require("util")
local _ = require("gettext") local _ = require("gettext")
@ -40,7 +37,7 @@ local _ = require("gettext")
["status"] = "Reading" ["status"] = "Reading"
["modified"] = "24.01.2016" ["modified"] = "24.01.2016"
},]] },]]
local StatusWidget = InputContainer:new { local StatusWidget = InputContainer:new{
settings = nil, settings = nil,
thumbnail = nil, thumbnail = nil,
props = nil, props = nil,
@ -69,7 +66,7 @@ function StatusWidget:init()
self.medium_font_face = Font:getFace("ffont", 20) self.medium_font_face = Font:getFace("ffont", 20)
self.large_font_face = Font:getFace("ffont", 25) self.large_font_face = Font:getFace("ffont", 25)
self.star = Button:new { self.star = Button:new{
icon = "resources/icons/stats.star.empty.png", icon = "resources/icons/stats.star.empty.png",
bordersize = 0, bordersize = 0,
radius = 0, radius = 0,
@ -78,7 +75,7 @@ function StatusWidget:init()
show_parent = self, show_parent = self,
} }
local statusContainer = FrameContainer:new { local statusContainer = FrameContainer:new{
dimen = Screen:getSize(), dimen = Screen:getSize(),
background = Blitbuffer.COLOR_WHITE, background = Blitbuffer.COLOR_WHITE,
bordersize = 0, bordersize = 0,
@ -89,7 +86,7 @@ function StatusWidget:init()
end end
function StatusWidget:showStatus() function StatusWidget:showStatus()
local main_group = VerticalGroup:new { align = "left" } local main_group = VerticalGroup:new{ align = "left" }
local img_width = Screen:scaleBySize(132 * 1.5) local img_width = Screen:scaleBySize(132 * 1.5)
local img_height = Screen:scaleBySize(184 * 1.5) local img_height = Screen:scaleBySize(184 * 1.5)
@ -101,7 +98,7 @@ function StatusWidget:showStatus()
local thumb = nil local thumb = nil
if self.thumbnail then if self.thumbnail then
thumb = ImageWidget:new { thumb = ImageWidget:new{
image = self.thumbnail, image = self.thumbnail,
width = img_width, width = img_width,
height = img_height, height = img_height,
@ -111,13 +108,13 @@ function StatusWidget:showStatus()
local screen_width = Screen:getWidth() local screen_width = Screen:getWidth()
local cover_with_title_and_author_container = CenterContainer:new { local cover_with_title_and_author_container = CenterContainer:new{
dimen = Geom:new { w = screen_width, h = img_height }, dimen = Geom:new{ w = screen_width, h = img_height },
} }
local cover_with_title_and_author_group = HorizontalGroup:new { align = "top" } local cover_with_title_and_author_group = HorizontalGroup:new{ align = "top" }
local span = HorizontalSpan:new { width = screen_width * 0.05 } local span = HorizontalSpan:new{ width = screen_width * 0.05 }
table.insert(cover_with_title_and_author_group, span) table.insert(cover_with_title_and_author_group, span)
@ -145,10 +142,10 @@ function StatusWidget:showStatus()
statusHeight = Screen:scaleBySize(60) statusHeight = Screen:scaleBySize(60)
end end
local header_group = HorizontalGroup:new { local header_group = HorizontalGroup:new{
align = "center", align = "center",
self:addHeader(screen_width * 0.95, Screen:scaleBySize(15), _("Progress")), self:addHeader(screen_width * 0.95, Screen:scaleBySize(15), _("Progress")),
CloseButton:new { window = self } CloseButton:new{ window = self }
} }
table.insert(main_group, header_group) table.insert(main_group, header_group)
@ -193,14 +190,14 @@ function StatusWidget:getReadPages(stats)
end end
function StatusWidget:addHeader(width, height, title) function StatusWidget:addHeader(width, height, title)
local group = HorizontalGroup:new { local group = HorizontalGroup:new{
align = "center", align = "center",
bordersize = 0 bordersize = 0,
} }
local bold = false local bold = false
local titleWidget = TextWidget:new { local titleWidget = TextWidget:new{
text = title, text = title,
face = self.large_font_face, face = self.large_font_face,
bold = bold, bold = bold,
@ -208,19 +205,19 @@ function StatusWidget:addHeader(width, height, title)
local titleSize = RenderText:sizeUtf8Text(0, Screen:getWidth(), self.large_font_face, title, true, bold) local titleSize = RenderText:sizeUtf8Text(0, Screen:getWidth(), self.large_font_face, title, true, bold)
local lineWidth = ((width - titleSize.x) * 0.5) local lineWidth = ((width - titleSize.x) * 0.5)
local line_container = LeftContainer:new { local line_container = LeftContainer:new{
dimen = Geom:new { w = lineWidth, h = height }, dimen = Geom:new{ w = lineWidth, h = height },
LineWidget:new { LineWidget:new{
background = Blitbuffer.gray(0.2), background = Blitbuffer.gray(0.2),
dimen = Geom:new { dimen = Geom:new{
w = lineWidth, w = lineWidth,
h = 2, h = 2,
} }
} }
} }
local text_container = CenterContainer:new { local text_container = CenterContainer:new{
dimen = Geom:new { w = titleSize.x, h = height }, dimen = Geom:new{ w = titleSize.x, h = height },
titleWidget, titleWidget,
} }
@ -231,8 +228,8 @@ function StatusWidget:addHeader(width, height, title)
end end
function StatusWidget:generateSwitchGroup(width, height, book_status) function StatusWidget:generateSwitchGroup(width, height, book_status)
local switch_container = CenterContainer:new { local switch_container = CenterContainer:new{
dimen = Geom:new { w = width, h = height }, dimen = Geom:new{ w = width, h = height },
} }
local args = { local args = {
@ -268,7 +265,7 @@ function StatusWidget:generateSwitchGroup(width, height, book_status)
enabled = true, enabled = true,
} }
local switch = ToggleSwitch:new { local switch = ToggleSwitch:new{
width = width * 0.6, width = width * 0.6,
default_value = config.default_value, default_value = config.default_value,
name = config.name, name = config.name,
@ -321,7 +318,7 @@ end
function StatusWidget:generateSummaryGroup(width, height, text) function StatusWidget:generateSummaryGroup(width, height, text)
self.input_note = InputText:new { self.input_note = InputText:new{
text = text, text = text,
face = self.medium_font_face, face = self.medium_font_face,
width = width * 0.95, width = width * 0.95,
@ -334,16 +331,16 @@ function StatusWidget:generateSummaryGroup(width, height, text)
hint = _("A few words about the book"), hint = _("A few words about the book"),
} }
local note_container = CenterContainer:new { local note_container = CenterContainer:new{
dimen = Geom:new { w = width, h = height }, dimen = Geom:new{ w = width, h = height },
self.input_note self.input_note
} }
return note_container return note_container
end end
function StatusWidget:generateRateGroup(width, height, rating) function StatusWidget:generateRateGroup(width, height, rating)
self.stars_container = CenterContainer:new { self.stars_container = CenterContainer:new{
dimen = Geom:new { w = width, h = height }, dimen = Geom:new{ w = width, h = height },
} }
self:setStar(rating) self:setStar(rating)
@ -354,20 +351,23 @@ function StatusWidget:setStar(num)
--clear previous data --clear previous data
self.stars_container:clear() self.stars_container:clear()
local stars_group = HorizontalGroup:new { align = "center" } local stars_group = HorizontalGroup:new{ align = "center" }
if num then if num then
self.summary.rating = num self.summary.rating = num
self:saveSummary() self:saveSummary()
for i = 1, num do for i = 1, num do
table.insert(stars_group, self.star:new { icon = "resources/icons/stats.star.full.png", callback = function() self:setStar(i) end }) table.insert(stars_group, self.star:new{
icon = "resources/icons/stats.star.full.png",
callback = function() self:setStar(i) end
})
end end
else else
num = 0 num = 0
end end
for i = num + 1, 5 do for i = num + 1, 5 do
table.insert(stars_group, self.star:new { callback = function() self:setStar(i) end }) table.insert(stars_group, self.star:new{ callback = function() self:setStar(i) end })
end end
table.insert(self.stars_container, stars_group) table.insert(self.stars_container, stars_group)
@ -377,34 +377,34 @@ function StatusWidget:setStar(num)
end end
function StatusWidget:generateStatisticsGroup(width, height, days, average, pages) function StatusWidget:generateStatisticsGroup(width, height, days, average, pages)
local statistics_container = CenterContainer:new { local statistics_container = CenterContainer:new{
dimen = Geom:new { w = width, h = height }, dimen = Geom:new{ w = width, h = height },
} }
local statistics_group = VerticalGroup:new { align = "left" } local statistics_group = VerticalGroup:new{ align = "left" }
local tile_width = width / 3 local tile_width = width / 3
local tile_height = height / 2 local tile_height = height / 2
local titles_group = HorizontalGroup:new { local titles_group = HorizontalGroup:new{
align = "center", align = "center",
CenterContainer:new { CenterContainer:new{
dimen = Geom:new { w = tile_width, h = tile_height }, dimen = Geom:new{ w = tile_width, h = tile_height },
TextWidget:new { TextWidget:new{
text = _("Days"), text = _("Days"),
face = self.small_font_face, face = self.small_font_face,
}, },
}, },
CenterContainer:new { CenterContainer:new{
dimen = Geom:new { w = tile_width, h = tile_height }, dimen = Geom:new{ w = tile_width, h = tile_height },
TextWidget:new { TextWidget:new{
text = _("Time"), text = _("Time"),
face = self.small_font_face, face = self.small_font_face,
}, },
}, },
CenterContainer:new { CenterContainer:new{
dimen = Geom:new { w = tile_width, h = tile_height }, dimen = Geom:new{ w = tile_width, h = tile_height },
TextWidget:new { TextWidget:new{
text = _("Read pages"), text = _("Read pages"),
face = self.small_font_face, face = self.small_font_face,
} }
@ -412,25 +412,25 @@ function StatusWidget:generateStatisticsGroup(width, height, days, average, page
} }
local data_group = HorizontalGroup:new { local data_group = HorizontalGroup:new{
align = "center", align = "center",
CenterContainer:new { CenterContainer:new{
dimen = Geom:new { w = tile_width, h = tile_height }, dimen = Geom:new{ w = tile_width, h = tile_height },
TextWidget:new { TextWidget:new{
text = days, text = days,
face = self.medium_font_face, face = self.medium_font_face,
}, },
}, },
CenterContainer:new { CenterContainer:new{
dimen = Geom:new { w = tile_width, h = tile_height }, dimen = Geom:new{ w = tile_width, h = tile_height },
TextWidget:new { TextWidget:new{
text = average, text = average,
face = self.medium_font_face, face = self.medium_font_face,
}, },
}, },
CenterContainer:new { CenterContainer:new{
dimen = Geom:new { w = tile_width, h = tile_height }, dimen = Geom:new{ w = tile_width, h = tile_height },
TextWidget:new { TextWidget:new{
text = pages, text = pages,
face = self.medium_font_face, face = self.medium_font_face,
} }
@ -446,34 +446,34 @@ end
function StatusWidget:generateTitleAuthorProgressGroup(width, height, title, authors, current_page, total_pages) function StatusWidget:generateTitleAuthorProgressGroup(width, height, title, authors, current_page, total_pages)
local title_author_container = CenterContainer:new { local title_author_container = CenterContainer:new{
dimen = Geom:new { w = width, h = height }, dimen = Geom:new{ w = width, h = height },
} }
local title_author_progressbar_group = VerticalGroup:new { local title_author_progressbar_group = VerticalGroup:new{
align = "center", align = "center",
VerticalSpan:new { width = height * 0.2 }, VerticalSpan:new{ width = height * 0.2 },
TextBoxWidget:new { TextBoxWidget:new{
text = title, text = title,
width = width, width = width,
face = self.medium_font_face, face = self.medium_font_face,
alignment = "center", alignment = "center",
} }
} }
local text_author = TextWidget:new { local text_author = TextWidget:new{
text = authors, text = authors,
face = self.small_font_face, face = self.small_font_face,
padding = 2, padding = 2,
} }
local author_container = CenterContainer:new { local author_container = CenterContainer:new{
dimen = Geom:new { w = width, h = text_author:getSize().h }, dimen = Geom:new{ w = width, h = text_author:getSize().h },
text_author text_author
} }
table.insert(title_author_progressbar_group, author_container) table.insert(title_author_progressbar_group, author_container)
local progressWidget = ProgressWidget:new { local progressWidget = ProgressWidget:new{
width = width * 0.7, width = width * 0.7,
height = Screen:scaleBySize(10), height = Screen:scaleBySize(10),
percentage = current_page / total_pages, percentage = current_page / total_pages,
@ -482,19 +482,19 @@ function StatusWidget:generateTitleAuthorProgressGroup(width, height, title, aut
last = total_pages, last = total_pages,
} }
local progress_bar_container = CenterContainer:new { local progress_bar_container = CenterContainer:new{
dimen = Geom:new { w = width, h = progressWidget:getSize().h }, dimen = Geom:new{ w = width, h = progressWidget:getSize().h },
progressWidget progressWidget
} }
table.insert(title_author_progressbar_group, progress_bar_container) table.insert(title_author_progressbar_group, progress_bar_container)
local text_complete = TextWidget:new { local text_complete = TextWidget:new{
text = string.format("%1.f", progressWidget.percentage * 100) .. "% " .. _("Completed"), text = string.format("%1.f", progressWidget.percentage * 100) .. "% " .. _("Completed"),
face = self.small_font_face, face = self.small_font_face,
} }
local progress_bar_text_container = CenterContainer:new { local progress_bar_text_container = CenterContainer:new{
dimen = Geom:new { w = width, h = text_complete:getSize().h }, dimen = Geom:new{ w = width, h = text_complete:getSize().h },
text_complete text_complete
} }
@ -529,7 +529,7 @@ end
function StatusWidget:onSwitchFocus(inputbox) function StatusWidget:onSwitchFocus(inputbox)
self.note_dialog = InputDialog:new { self.note_dialog = InputDialog:new{
title = "Note", title = "Note",
input = self.input_note:getText(), input = self.input_note:getText(),
input_hint = "", input_hint = "",

Loading…
Cancel
Save