mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
progresswidget(fix): ignore nil self.last
This commit is contained in:
@@ -14,7 +14,7 @@ Configurable attributes:
|
|||||||
* rectcolor -- infill color
|
* rectcolor -- infill color
|
||||||
* ticks (list) -- default to nil, use this if you want to insert markers
|
* ticks (list) -- default to nil, use this if you want to insert markers
|
||||||
* tick_width
|
* tick_width
|
||||||
* last -- maximum tick
|
* last -- maximum tick, used with ticks
|
||||||
|
|
||||||
Example:
|
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),
|
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),
|
math.ceil((my_size.w-2*self.margin_h)*self.percentage),
|
||||||
my_size.h-2*(self.margin_v+self.bordersize), self.rectcolor)
|
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
|
for i=1, #self.ticks do
|
||||||
bb:paintRect(
|
bb:paintRect(
|
||||||
x + (my_size.w-2*self.margin_h)*(self.ticks[i]/self.last),
|
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()
|
it("should goto portrait screen mode", function()
|
||||||
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
|
readerui:handleEvent(Event:new("ChangeScreenMode", "portrait"))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("should goto certain page", function()
|
it("should goto certain page", function()
|
||||||
for i = 1, 10, 5 do
|
for i = 1, 10, 5 do
|
||||||
rolling:onGotoPage(i)
|
rolling:onGotoPage(i)
|
||||||
assert.are.same(i, rolling.current_page)
|
assert.are.same(i, rolling.current_page)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("should goto relative page", function()
|
it("should goto relative page", function()
|
||||||
for i = 20, 40, 5 do
|
for i = 20, 40, 5 do
|
||||||
rolling:onGotoPage(i)
|
rolling:onGotoPage(i)
|
||||||
@@ -35,6 +37,7 @@ describe("Readerrolling module", function()
|
|||||||
assert.are.same(i, rolling.current_page)
|
assert.are.same(i, rolling.current_page)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("should goto next chapter", function()
|
it("should goto next chapter", function()
|
||||||
local toc = readerui.toc
|
local toc = readerui.toc
|
||||||
for i = 30, 50, 5 do
|
for i = 30, 50, 5 do
|
||||||
@@ -43,6 +46,7 @@ describe("Readerrolling module", function()
|
|||||||
assert.are.same(toc:getNextChapter(i, 0), rolling.current_page)
|
assert.are.same(toc:getNextChapter(i, 0), rolling.current_page)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("should goto previous chapter", function()
|
it("should goto previous chapter", function()
|
||||||
local toc = readerui.toc
|
local toc = readerui.toc
|
||||||
for i = 60, 80, 5 do
|
for i = 60, 80, 5 do
|
||||||
@@ -51,6 +55,7 @@ describe("Readerrolling module", function()
|
|||||||
assert.are.same(toc:getPreviousChapter(i, 0), rolling.current_page)
|
assert.are.same(toc:getPreviousChapter(i, 0), rolling.current_page)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("should emit EndOfBook event at the end of sample epub", function()
|
it("should emit EndOfBook event at the end of sample epub", function()
|
||||||
local called = false
|
local called = false
|
||||||
readerui.onEndOfBook = function()
|
readerui.onEndOfBook = function()
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
require("commonrequire")
|
|
||||||
local Menu = require("ui/widget/menu")
|
|
||||||
local DEBUG = require("dbg")
|
|
||||||
|
|
||||||
describe("Menu widget", function()
|
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()
|
it("should convert item table from touch menu properly", function()
|
||||||
local cb1 = function() end
|
local cb1 = function() end
|
||||||
local cb2 = function() end
|
local cb2 = function() end
|
||||||
|
|||||||
18
spec/unit/widget_progresswidget_spec.lua
Normal file
18
spec/unit/widget_progresswidget_spec.lua
Normal file
@@ -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)
|
||||||
Reference in New Issue
Block a user