2
0
mirror of https://github.com/koreader/koreader synced 2024-11-13 19:11:25 +00:00
koreader/frontend/ui/widget/container/underlinecontainer.lua

48 lines
1.4 KiB
Lua
Raw Normal View History

2017-04-26 14:21:36 +00:00
--[[--
An UnderlineContainer is a WidgetContainer that is able to paint
a line under its child node.
2013-10-18 20:38:07 +00:00
--]]
2017-04-26 14:21:36 +00:00
local Blitbuffer = require("ffi/blitbuffer")
local Geom = require("ui/geometry")
2017-09-13 14:56:20 +00:00
local Size = require("ui/size")
2017-04-26 14:21:36 +00:00
local WidgetContainer = require("ui/widget/container/widgetcontainer")
2013-10-18 20:38:07 +00:00
local UnderlineContainer = WidgetContainer:new{
2017-09-13 14:56:20 +00:00
linesize = Size.line.thick,
padding = Size.padding.tiny,
--- @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
local contentSize = self[1]:getSize()
return Geom:new{
w = contentSize.w,
2017-09-13 14:56:20 +00:00
h = contentSize.h + self.linesize + 2*self.padding
2014-03-13 13:52:43 +00:00
}
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()
2014-12-02 12:30:55 +00:00
self.dimen = Geom:new{
x = x, y = y,
w = container_size.w,
h = container_size.h
}
local content_size = self[1]:getSize()
2014-03-13 13:52:43 +00:00
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