2017-04-26 14:21:36 +00:00
|
|
|
--[[--
|
|
|
|
A FrameContainer is some graphics content (1 widget) that is surrounded by a
|
|
|
|
frame
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
local frame
|
|
|
|
frame = FrameContainer:new{
|
2017-09-13 14:56:20 +00:00
|
|
|
radius = Size.radius.window,
|
|
|
|
bordersize = Size.border.window,
|
2017-04-26 14:21:36 +00:00
|
|
|
padding = 0,
|
|
|
|
margin = 0,
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
VerticalGroup:new{
|
|
|
|
-- etc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
--]]
|
|
|
|
|
2019-12-06 21:55:37 +00:00
|
|
|
local BD = require("ui/bidi")
|
2014-10-22 13:34:11 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2017-09-11 18:54:27 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2017-09-13 14:56:20 +00:00
|
|
|
local Size = require("ui/size")
|
2017-09-11 18:54:27 +00:00
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
local FrameContainer = WidgetContainer:new{
|
2014-03-13 13:52:43 +00:00
|
|
|
background = nil,
|
2014-10-22 13:34:11 +00:00
|
|
|
color = Blitbuffer.COLOR_BLACK,
|
2014-03-13 13:52:43 +00:00
|
|
|
margin = 0,
|
2020-12-24 23:39:13 +00:00
|
|
|
radius = nil,
|
2019-03-12 19:00:06 +00:00
|
|
|
inner_bordersize = 0,
|
2017-09-13 14:56:20 +00:00
|
|
|
bordersize = Size.border.window,
|
|
|
|
padding = Size.padding.default,
|
2017-10-08 15:53:25 +00:00
|
|
|
padding_top = nil,
|
|
|
|
padding_right = nil,
|
|
|
|
padding_bottom = nil,
|
|
|
|
padding_left = nil,
|
2014-03-13 13:52:43 +00:00
|
|
|
width = nil,
|
|
|
|
height = nil,
|
|
|
|
invert = false,
|
2019-12-06 21:55:37 +00:00
|
|
|
allow_mirroring = true,
|
|
|
|
_mirroredUI = BD.mirroredUILayout(),
|
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()
|
2017-10-08 15:53:25 +00:00
|
|
|
self._padding_top = self.padding_top or self.padding
|
|
|
|
self._padding_right = self.padding_right or self.padding
|
|
|
|
self._padding_bottom = self.padding_bottom or self.padding
|
|
|
|
self._padding_left = self.padding_left or self.padding
|
2019-12-06 21:55:37 +00:00
|
|
|
if self._mirroredUI and self.allow_mirroring then
|
|
|
|
self._padding_left, self._padding_right = self._padding_right, self._padding_left
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
return Geom:new{
|
2017-10-08 15:53:25 +00:00
|
|
|
w = content_size.w + ( self.margin + self.bordersize ) * 2 + self._padding_left + self._padding_right,
|
|
|
|
h = content_size.h + ( self.margin + self.bordersize ) * 2 + self._padding_top + self._padding_bottom
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
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,
|
2014-09-14 03:42:12 +00:00
|
|
|
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
|
|
|
|
2019-12-06 21:55:37 +00:00
|
|
|
local shift_x = 0
|
|
|
|
if self._mirroredUI and self.allow_mirroring then
|
|
|
|
shift_x = container_width - my_size.w
|
|
|
|
end
|
|
|
|
|
2019-08-26 13:49:50 +00:00
|
|
|
--- @todo get rid of margin here? 13.03 2013 (houqp)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.background then
|
2017-04-11 09:44:58 +00:00
|
|
|
bb:paintRoundedRect(x, y,
|
|
|
|
container_width, container_height,
|
|
|
|
self.background, self.radius)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2019-03-12 19:00:06 +00:00
|
|
|
if self.inner_bordersize > 0 then
|
2019-08-26 13:49:50 +00:00
|
|
|
--- @warning This doesn't actually support radius, it'll always be a square.
|
2019-03-12 19:00:06 +00:00
|
|
|
bb:paintInnerBorder(x + self.margin, y + self.margin,
|
|
|
|
container_width - self.margin * 2,
|
|
|
|
container_height - self.margin * 2,
|
|
|
|
self.inner_bordersize, self.color, self.radius)
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
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,
|
2019-12-06 21:55:37 +00:00
|
|
|
x + self.margin + self.bordersize + self._padding_left + shift_x,
|
2017-10-08 15:53:25 +00:00
|
|
|
y + self.margin + self.bordersize + self._padding_top)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
if self.invert then
|
|
|
|
bb:invertRect(x + self.bordersize, y + self.bordersize,
|
|
|
|
container_width - 2*self.bordersize,
|
|
|
|
container_height - 2*self.bordersize)
|
|
|
|
end
|
2015-03-16 13:49:53 +00:00
|
|
|
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
|