fix: stop self.dimen polution for inputcontainers

Without this fix, self.dimen is shared among all inputcontainers
intances, which breaks some of the UI rendering. All widget should
set/initialize their own self.dimen in self:init() method.
pull/1635/head
Qingping Hou 9 years ago
parent cdd17906f6
commit 63e88baf33

@ -13,6 +13,7 @@ local ReaderConfig = InputContainer:new{
} }
function ReaderConfig:init() function ReaderConfig:init()
if not self.dimen then self.dimen = Geom:new{} end
if Device:hasKeyboard() then if Device:hasKeyboard() then
self.key_events = { self.key_events = {
ShowConfigMenu = { { "AA" }, doc = "show config dialog" }, ShowConfigMenu = { { "AA" }, doc = "show config dialog" },

@ -48,13 +48,12 @@ function InputContainer:_init()
end end
end end
self.ges_events = new_ges_events self.ges_events = new_ges_events
if not self.dimen then
self.dimen = Geom:new{}
end
end end
function InputContainer:paintTo(bb, x, y) function InputContainer:paintTo(bb, x, y)
if not self.dimen then
self.dimen = self[1]:getSize()
end
self.dimen.x = x self.dimen.x = x
self.dimen.y = y self.dimen.y = y
if self[1] then if self[1] then

@ -7,14 +7,13 @@ WidgetContainer is a container for another Widget
local WidgetContainer = Widget:new() local WidgetContainer = Widget:new()
function WidgetContainer:init() function WidgetContainer:init()
if not self.dimen then if self.dimen then
self.dimen = Geom:new{} if not self.dimen.w then
end self.dimen.w = self[1].getSize().w
if not self.dimen.w then end
self.dimen.w = self[1].getSize().w if not self.dimen.h then
end self.dimen.h = self[1].getSize().h
if not self.dimen.h then end
self.dimen.h = self[1].getSize().h
end end
end end

@ -274,6 +274,7 @@ local TouchMenu = InputContainer:new{
} }
function TouchMenu:init() function TouchMenu:init()
if not self.dimen then self.dimen = Geom:new{} end
self.show_parent = self.show_parent or self self.show_parent = self.show_parent or self
if not self.close_callback then if not self.close_callback then
self.close_callback = function() self.close_callback = function()

@ -31,8 +31,8 @@ definition.
--]] --]]
function Widget:new(o) function Widget:new(o)
o = self:extend(o) o = self:extend(o)
-- Both o._init and o.init are called on object create. But o._init is used -- Both o._init and o.init are called on object creation. But o._init is
-- for base widget initialization (basic component used to build other -- used for base widget initialization (basic component used to build other
-- widgets). While o.init is for higher level widgets, for example Menu -- widgets). While o.init is for higher level widgets, for example Menu
-- Widget -- Widget
if o._init then o:_init() end if o._init then o:_init() end

Loading…
Cancel
Save