2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00
koreader/frontend/ui/widget/verticalscrollbar.lua
Hans-Werner Hilse 5982e24d57 unify color specification
colors were a mixture of 4bpp integers (0=white, 15=black) and
fractional blackness levels (0=white, 1.0=black) before. This is
now unified to use the color specification of the Blitbuffer API.
2014-10-24 13:48:42 +02:00

40 lines
1.0 KiB
Lua

local Widget = require("ui/widget/widget")
local Geom = require("ui/geometry")
local Blitbuffer = require("ffi/blitbuffer")
local VerticalScrollBar = Widget:new{
enable = true,
low = 0,
high = 1,
width = 6,
height = 50,
bordersize = 1,
bordercolor = Blitbuffer.COLOR_BLACK,
radius = 0,
rectcolor = Blitbuffer.COLOR_BLACK,
}
function VerticalScrollBar:getSize()
return Geom:new{
w = self.width,
h = self.height
}
end
function VerticalScrollBar:set(low, high)
self.low = low > 0 and low or 0
self.high = high < 1 and high or 1
end
function VerticalScrollBar:paintTo(bb, x, y)
if not self.enable then return end
bb:paintBorder(x, y, self.width, self.height,
self.bordersize, self.bordercolor, self.radius)
bb:paintRect(x + self.bordersize, y + self.bordersize + self.low*self.height,
self.width - 2*self.bordersize,
self.height * (self.high - self.low), self.rectcolor)
end
return VerticalScrollBar