From 63e88baf334ec92daecff201fe4c0a01339df9a1 Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Sun, 13 Sep 2015 01:06:22 -0700 Subject: [PATCH] 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. --- frontend/apps/reader/modules/readerconfig.lua | 1 + frontend/ui/widget/container/inputcontainer.lua | 7 +++---- frontend/ui/widget/container/widgetcontainer.lua | 15 +++++++-------- frontend/ui/widget/touchmenu.lua | 1 + frontend/ui/widget/widget.lua | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/frontend/apps/reader/modules/readerconfig.lua b/frontend/apps/reader/modules/readerconfig.lua index 10c4c281a..6dd0d0ffe 100644 --- a/frontend/apps/reader/modules/readerconfig.lua +++ b/frontend/apps/reader/modules/readerconfig.lua @@ -13,6 +13,7 @@ local ReaderConfig = InputContainer:new{ } function ReaderConfig:init() + if not self.dimen then self.dimen = Geom:new{} end if Device:hasKeyboard() then self.key_events = { ShowConfigMenu = { { "AA" }, doc = "show config dialog" }, diff --git a/frontend/ui/widget/container/inputcontainer.lua b/frontend/ui/widget/container/inputcontainer.lua index 8b00dc99f..95aa9727d 100644 --- a/frontend/ui/widget/container/inputcontainer.lua +++ b/frontend/ui/widget/container/inputcontainer.lua @@ -48,13 +48,12 @@ function InputContainer:_init() end end self.ges_events = new_ges_events - - if not self.dimen then - self.dimen = Geom:new{} - end end function InputContainer:paintTo(bb, x, y) + if not self.dimen then + self.dimen = self[1]:getSize() + end self.dimen.x = x self.dimen.y = y if self[1] then diff --git a/frontend/ui/widget/container/widgetcontainer.lua b/frontend/ui/widget/container/widgetcontainer.lua index 766df85a1..dd63ec34b 100644 --- a/frontend/ui/widget/container/widgetcontainer.lua +++ b/frontend/ui/widget/container/widgetcontainer.lua @@ -7,14 +7,13 @@ WidgetContainer is a container for another Widget local WidgetContainer = Widget:new() function WidgetContainer:init() - if not self.dimen then - self.dimen = Geom:new{} - end - if not self.dimen.w then - self.dimen.w = self[1].getSize().w - end - if not self.dimen.h then - self.dimen.h = self[1].getSize().h + if self.dimen then + if not self.dimen.w then + self.dimen.w = self[1].getSize().w + end + if not self.dimen.h then + self.dimen.h = self[1].getSize().h + end end end diff --git a/frontend/ui/widget/touchmenu.lua b/frontend/ui/widget/touchmenu.lua index 596d7594b..77c375f78 100644 --- a/frontend/ui/widget/touchmenu.lua +++ b/frontend/ui/widget/touchmenu.lua @@ -274,6 +274,7 @@ local TouchMenu = InputContainer:new{ } function TouchMenu:init() + if not self.dimen then self.dimen = Geom:new{} end self.show_parent = self.show_parent or self if not self.close_callback then self.close_callback = function() diff --git a/frontend/ui/widget/widget.lua b/frontend/ui/widget/widget.lua index 6b7c19c0d..29f55a88a 100644 --- a/frontend/ui/widget/widget.lua +++ b/frontend/ui/widget/widget.lua @@ -31,8 +31,8 @@ definition. --]] function Widget:new(o) o = self:extend(o) - -- Both o._init and o.init are called on object create. But o._init is used - -- for base widget initialization (basic component used to build other + -- Both o._init and o.init are called on object creation. But o._init is + -- used for base widget initialization (basic component used to build other -- widgets). While o.init is for higher level widgets, for example Menu -- Widget if o._init then o:_init() end