VirtualKeyboard: Simplify our top-level dimen handling

Make sure it tracks the right widget, and stays accurate post-paint,
by fixing FrameContainer's paintTo method *not* to break the dimen ref...
reviewable/pr11367/r1
NiLuJe 4 months ago
parent 259b4ac950
commit d33bb0452c

@ -93,11 +93,12 @@ end
function FrameContainer:paintTo(bb, x, y) function FrameContainer:paintTo(bb, x, y)
local my_size = self:getSize() local my_size = self:getSize()
self.dimen = Geom:new{ if not self.dimen then
x = x, y = y, self.dimen = Geom:new{x = x, y = y, w = my_size.w, h = my_size.h}
w = my_size.w, else
h = my_size.h self.dimen.x = x
} self.dimen.y = y
end
local container_width = self.width or my_size.w local container_width = self.width or my_size.w
local container_height = self.height or my_size.h local container_height = self.height or my_size.h

@ -72,10 +72,11 @@ function InputContainer:paintTo(bb, x, y)
if not self.dimen then if not self.dimen then
local content_size = self[1]:getSize() local content_size = self[1]:getSize()
self.dimen = Geom:new{x = 0, y = 0, w = content_size.w, h = content_size.h} self.dimen = Geom:new{x = x, y = y, w = content_size.w, h = content_size.h}
else
self.dimen.x = x
self.dimen.y = y
end end
self.dimen.x = x
self.dimen.y = y
if self.vertical_align == "center" then if self.vertical_align == "center" then
local content_size = self[1]:getSize() local content_size = self[1]:getSize()
self[1]:paintTo(bb, x, y + math.floor((self.dimen.h - content_size.h)/2)) self[1]:paintTo(bb, x, y + math.floor((self.dimen.h - content_size.h)/2))

@ -495,7 +495,7 @@ function InputDialog:onTap(arg, ges)
-- so we'll have to double check that it wasn't inside of the whole VK region, -- so we'll have to double check that it wasn't inside of the whole VK region,
-- otherwise tapping inside a border would close the VK ;p. -- otherwise tapping inside a border would close the VK ;p.
-- Poke at keyboard_frame directly, as the top-level dimen never gets updated coordinates... -- Poke at keyboard_frame directly, as the top-level dimen never gets updated coordinates...
if self._input_widget.keyboard and self._input_widget.keyboard.dimen and ges.pos:notIntersectWith(self._input_widget.keyboard[1][1].dimen) then if self._input_widget.keyboard and self._input_widget.keyboard.dimen and ges.pos:notIntersectWith(self._input_widget.keyboard.dimen) then
self:onCloseKeyboard() self:onCloseKeyboard()
end end
else else

@ -312,6 +312,7 @@ end
function VirtualKey:paintTo(bb, x ,y) function VirtualKey:paintTo(bb, x ,y)
InputContainer.paintTo(self, bb, x, y) InputContainer.paintTo(self, bb, x, y)
-- Fudge self.dimen to include the padding, to make sure said padding is covered by our ges_events range... -- Fudge self.dimen to include the padding, to make sure said padding is covered by our ges_events range...
-- Like Geom, floor coordinates & ceil dims, to fill the gaps without overlaps. -- Like Geom, floor coordinates & ceil dims, to fill the gaps without overlaps.
local coords_padding = math.floor(self.keyboard.key_padding / 2) local coords_padding = math.floor(self.keyboard.key_padding / 2)
@ -359,7 +360,7 @@ function VirtualKey:update_keyboard(want_flash, want_a2)
-- We flash the *full* keyboard when we release a hold. -- We flash the *full* keyboard when we release a hold.
if want_flash then if want_flash then
UIManager:setDirty(self.keyboard, function() UIManager:setDirty(self.keyboard, function()
return "flashui", self.keyboard[1][1].dimen -- i.e., keyboard_frame return "flashui", self.keyboard.dimen
end) end)
else else
local refresh_type = "ui" local refresh_type = "ui"
@ -367,6 +368,8 @@ function VirtualKey:update_keyboard(want_flash, want_a2)
refresh_type = "a2" refresh_type = "a2"
end end
-- Only repaint the key itself, not the full board... -- Only repaint the key itself, not the full board...
-- NOTE: We use self[1] (i.e., FrameContainer),
-- because we fudge self.dimen to include the padding for the gesture hitbox...
UIManager:widgetRepaint(self[1], self[1].dimen.x, self[1].dimen.y) UIManager:widgetRepaint(self[1], self[1].dimen.x, self[1].dimen.y)
logger.dbg("update key", self.key) logger.dbg("update key", self.key)
UIManager:setDirty(nil, refresh_type, self[1].dimen) UIManager:setDirty(nil, refresh_type, self[1].dimen)
@ -504,7 +507,7 @@ VirtualKeyPopup = FocusManager:extend{
} }
function VirtualKeyPopup:onTapClose(arg, ges) function VirtualKeyPopup:onTapClose(arg, ges)
if ges.pos:notIntersectWith(self[1][1].dimen) then if ges.pos:notIntersectWith(self.dimen) then
UIManager:close(self) UIManager:close(self)
return true return true
end end
@ -519,7 +522,7 @@ end
function VirtualKeyPopup:onCloseWidget() function VirtualKeyPopup:onCloseWidget()
self:free() self:free()
UIManager:setDirty(nil, function() UIManager:setDirty(nil, function()
return "ui", self[1][1].dimen -- i.e., keyboard_frame return "ui", self.dimen
end) end)
end end
@ -706,6 +709,7 @@ function VirtualKeyPopup:init()
} }
} }
keyboard_frame.dimen = keyboard_frame:getSize() keyboard_frame.dimen = keyboard_frame:getSize()
self.dimen = keyboard_frame.dimen
self.ges_events.TapClose = { self.ges_events.TapClose = {
GestureRange:new{ GestureRange:new{
@ -762,7 +766,7 @@ function VirtualKeyPopup:init()
UIManager:show(self) UIManager:show(self)
-- Ensure the post-paint refresh will be able to grab updated coordinates from keyboard_frame by using a refresh function -- Ensure the post-paint refresh will be able to grab updated coordinates from keyboard_frame by using a refresh function
UIManager:setDirty(self, function() UIManager:setDirty(self, function()
return "ui", keyboard_frame.dimen return "ui", self.dimen
end) end)
end end
@ -938,7 +942,7 @@ function VirtualKeyboard:_refresh(want_flash, fullscreen)
return return
end end
UIManager:setDirty(self, function() UIManager:setDirty(self, function()
return refresh_type, self[1][1].dimen -- i.e., keyboard_frame return refresh_type, self.dimen
end) end)
end end
@ -1097,9 +1101,9 @@ function VirtualKeyboard:addKeys()
dimen = Screen:getSize(), dimen = Screen:getSize(),
keyboard_frame, keyboard_frame,
} }
-- Beware, this won't be updated post-paint, so the coordinates will stay at (0, 0) -- Point our top-level dimen to the relevant widget, keyboard_frame
-- (i.e., only the size is accurate, not the position). keyboard_frame.dimen = keyboard_frame:getSize()
self.dimen = keyboard_frame:getSize() self.dimen = keyboard_frame.dimen
end end
function VirtualKeyboard:setLayer(key) function VirtualKeyboard:setLayer(key)

Loading…
Cancel
Save