2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00
koreader/frontend/ui/widget/container/underlinecontainer.lua

45 lines
1.3 KiB
Lua
Raw Normal View History

2013-10-18 20:38:07 +00:00
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local Geom = require("ui/geometry")
local Blitbuffer = require("ffi/blitbuffer")
2013-10-18 20:38:07 +00:00
--[[
an UnderlineContainer is a WidgetContainer that is able to paint
a line under its child node
--]]
local UnderlineContainer = WidgetContainer:new{
2014-03-13 13:52:43 +00:00
linesize = 2,
padding = 1,
-- TODO: shouldn't this default to black instead?
color = Blitbuffer.COLOR_WHITE,
2014-03-13 13:52:43 +00:00
vertical_align = "top",
2013-10-18 20:38:07 +00:00
}
function UnderlineContainer:getSize()
2014-03-13 13:52:43 +00:00
return self:getContentSize()
2013-10-18 20:38:07 +00:00
end
function UnderlineContainer:getContentSize()
2014-03-13 13:52:43 +00:00
local contentSize = self[1]:getSize()
return Geom:new{
w = contentSize.w,
h = contentSize.h + self.linesize + self.padding
}
2013-10-18 20:38:07 +00:00
end
function UnderlineContainer:paintTo(bb, x, y)
2014-03-13 13:52:43 +00:00
local container_size = self:getSize()
local content_size = self:getContentSize()
local p_y = y
if self.vertical_align == "center" then
p_y = math.floor((container_size.h - content_size.h) / 2) + y
elseif self.vertical_align == "bottom" then
p_y = (container_size.h - content_size.h) + y
end
self[1]:paintTo(bb, x, p_y)
bb:paintRect(x, y + container_size.h - self.linesize,
container_size.w, self.linesize, self.color)
2013-10-18 20:38:07 +00:00
end
return UnderlineContainer