mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
chore: add test for screen color toggle
This commit is contained in:
committed by
Frans de Jonge
parent
11a38b33f1
commit
080c079d01
@@ -32,12 +32,14 @@ The following key is required for a device object:
|
||||
* getDPI() -> int
|
||||
* getSize() -> Rect
|
||||
* scaleBySize(int) -> int
|
||||
* isColorEnabled() -> boolean
|
||||
]]--
|
||||
function CanvasContext:init(device)
|
||||
self.screen = device.screen
|
||||
self.isAndroid = device.isAndroid
|
||||
self.isKindle = device.isKindle
|
||||
self.should_restrict_JIT = device.should_restrict_JIT
|
||||
self:setColorRenderingEnabled(device.screen.isColorEnabled())
|
||||
|
||||
-- NOTE: Kobo's fb is BGR, not RGB. Handle the conversion in MuPDF if needed.
|
||||
if device:hasBGRFrameBuffer() then
|
||||
|
||||
@@ -10,8 +10,9 @@ return {
|
||||
checked_func = Screen.isColorEnabled,
|
||||
callback = function()
|
||||
local new_val = not Screen.isColorEnabled()
|
||||
CanvasContext:setColorRenderingEnabled(new_val)
|
||||
-- Screen.isColorEnabled reads G_reader_settings :'(
|
||||
G_reader_settings:saveSetting("color_rendering", new_val)
|
||||
CanvasContext:setColorRenderingEnabled(new_val)
|
||||
UIManager:broadcastEvent(Event:new("ColorRenderingUpdate"))
|
||||
end
|
||||
}
|
||||
|
||||
@@ -60,11 +60,6 @@ end
|
||||
|
||||
local CanvasContext = require("document/canvascontext")
|
||||
CanvasContext:init(Device)
|
||||
if G_reader_settings:has("color_rendering") then
|
||||
CanvasContext:setColorRenderingEnabled(G_reader_settings:isTrue("color_rendering"))
|
||||
else
|
||||
CanvasContext:setColorRenderingEnabled(Device.screen:isColorScreen())
|
||||
end
|
||||
|
||||
-- option parsing:
|
||||
local longopts = {
|
||||
|
||||
@@ -18,13 +18,13 @@ einkfb.dummy = true --luacheck: ignore
|
||||
|
||||
local Device = require("device")
|
||||
|
||||
local CanvasContext = require("document/canvascontext")
|
||||
CanvasContext:init(Device)
|
||||
|
||||
-- init output device
|
||||
local Screen = Device.screen
|
||||
Screen:init()
|
||||
|
||||
local CanvasContext = require("document/canvascontext")
|
||||
CanvasContext:init(Device)
|
||||
|
||||
-- init input device (do not show SDL window)
|
||||
local Input = Device.input
|
||||
Input.dummy = true
|
||||
|
||||
20
spec/unit/menu_table_screen_color_spec.lua
Normal file
20
spec/unit/menu_table_screen_color_spec.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
describe("menu table screen color module", function()
|
||||
local menu, Screen, CanvasContext
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
menu = require("ui/elements/screen_color_menu_table")
|
||||
Screen = require("device").screen
|
||||
CanvasContext = require("document/canvascontext")
|
||||
end)
|
||||
|
||||
it("should toggle color rendering", function()
|
||||
assert.is.truthy(Screen.isColorEnabled())
|
||||
assert.is.truthy(CanvasContext.is_color_rendering_enabled)
|
||||
menu.callback()
|
||||
assert.is.falsy(Screen.isColorEnabled())
|
||||
assert.is.falsy(CanvasContext.is_color_rendering_enabled)
|
||||
menu.callback()
|
||||
assert.is.truthy(Screen.isColorEnabled())
|
||||
assert.is.truthy(CanvasContext.is_color_rendering_enabled)
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user