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

68 lines
2.0 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
--[[
A FrameContainer is some graphics content (1 widget) that is surrounded by a
frame
--]]
local FrameContainer = WidgetContainer:new{
2014-03-13 13:52:43 +00:00
background = nil,
color = Blitbuffer.COLOR_BLACK,
2014-03-13 13:52:43 +00:00
margin = 0,
radius = 0,
bordersize = 2,
padding = 5,
width = nil,
height = nil,
invert = false,
2013-10-18 20:38:07 +00:00
}
function FrameContainer:getSize()
2014-03-13 13:52:43 +00:00
local content_size = self[1]:getSize()
return Geom:new{
w = content_size.w + ( self.margin + self.bordersize + self.padding ) * 2,
h = content_size.h + ( self.margin + self.bordersize + self.padding ) * 2
}
2013-10-18 20:38:07 +00:00
end
function FrameContainer:paintTo(bb, x, y)
2014-03-13 13:52:43 +00:00
local my_size = self:getSize()
self.dimen = Geom:new{
x = x, y = y,
w = my_size.w,
h = my_size.h
2014-03-13 13:52:43 +00:00
}
local container_width = self.width or my_size.w
local container_height = self.height or my_size.h
2013-10-18 20:38:07 +00:00
2014-03-13 13:52:43 +00:00
--@TODO get rid of margin here? 13.03 2013 (houqp)
if self.background then
bb:paintRoundedRect(x, y, container_width, container_height,
self.background, self.radius)
end
if self.bordersize > 0 then
bb:paintBorder(x + self.margin, y + self.margin,
container_width - self.margin * 2,
container_height - self.margin * 2,
self.bordersize, self.color, self.radius)
end
if self[1] then
self[1]:paintTo(bb,
x + self.margin + self.bordersize + self.padding,
y + self.margin + self.bordersize + self.padding)
end
if self.invert then
bb:invertRect(x + self.bordersize, y + self.bordersize,
container_width - 2*self.bordersize,
container_height - 2*self.bordersize)
end
if self.dim then
bb:dimRect(x + self.bordersize, y + self.bordersize,
container_width - 2*self.bordersize,
container_height - 2*self.bordersize)
end
2013-10-18 20:38:07 +00:00
end
return FrameContainer