progresswidget(fix): ignore nil self.last

pull/1983/head
Qingping Hou 8 years ago
parent 984c994192
commit d7b1b403c1

@ -14,7 +14,7 @@ Configurable attributes:
* rectcolor -- infill color
* ticks (list) -- default to nil, use this if you want to insert markers
* tick_width
* last -- maximum tick
* last -- maximum tick, used with ticks
Example:
@ -68,7 +68,7 @@ function ProgressWidget:paintTo(bb, x, y)
bb:paintRect(x+self.margin_h, math.ceil(y+self.margin_v+self.bordersize),
math.ceil((my_size.w-2*self.margin_h)*self.percentage),
my_size.h-2*(self.margin_v+self.bordersize), self.rectcolor)
if self.ticks then
if self.ticks and self.last then
for i=1, #self.ticks do
bb:paintRect(
x + (my_size.w-2*self.margin_h)*(self.ticks[i]/self.last),

@ -20,12 +20,14 @@ describe("Readerrolling module", function()
it("should goto portrait screen mode", function()
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
end)
it("should goto certain page", function()
for i = 1, 10, 5 do
rolling:onGotoPage(i)
assert.are.same(i, rolling.current_page)
end
end)
it("should goto relative page", function()
for i = 20, 40, 5 do
rolling:onGotoPage(i)
@ -35,6 +37,7 @@ describe("Readerrolling module", function()
assert.are.same(i, rolling.current_page)
end
end)
it("should goto next chapter", function()
local toc = readerui.toc
for i = 30, 50, 5 do
@ -43,6 +46,7 @@ describe("Readerrolling module", function()
assert.are.same(toc:getNextChapter(i, 0), rolling.current_page)
end
end)
it("should goto previous chapter", function()
local toc = readerui.toc
for i = 60, 80, 5 do
@ -51,6 +55,7 @@ describe("Readerrolling module", function()
assert.are.same(toc:getPreviousChapter(i, 0), rolling.current_page)
end
end)
it("should emit EndOfBook event at the end of sample epub", function()
local called = false
readerui.onEndOfBook = function()

@ -1,8 +1,11 @@
require("commonrequire")
local Menu = require("ui/widget/menu")
local DEBUG = require("dbg")
describe("Menu widget", function()
local Menu, dbg
setup(function()
require("commonrequire")
Menu = require("ui/widget/menu")
dbg = require("dbg")
end)
it("should convert item table from touch menu properly", function()
local cb1 = function() end
local cb2 = function() end

@ -0,0 +1,18 @@
describe("ProgressWidget widget", function()
local ProgressWidget, Screen
setup(function()
require("commonrequire")
ProgressWidget = require("ui/widget/progresswidget")
Screen = require("device").screen
end)
it("should not crash with nil self.last #ok", function()
local progress = ProgressWidget:new{
width = 100,
height = 50,
percentage = 5/100,
ticks = {1},
}
progress:paintTo(Screen.bb, 0, 0)
end)
end)
Loading…
Cancel
Save