canvas overhaul

This commit is contained in:
kepler155c@gmail.com
2020-03-31 09:57:23 -06:00
parent 369070e19c
commit 5a874c1944
69 changed files with 1134 additions and 786 deletions

View File

@@ -1,21 +1,9 @@
local Canvas = require('opus.ui.canvas')
local class = require('opus.class')
local UI = require('opus.ui')
local Util = require('opus.util')
local colors = _G.colors
-- need to add offsets to this test
local function getPosition(element)
local x, y = 1, 1
repeat
x = element.x + x - 1
y = element.y + y - 1
element = element.parent
until not element
return x, y
end
UI.Page = class(UI.Window)
UI.Page.defaults = {
UIElement = 'Page',
@@ -26,21 +14,15 @@ UI.Page.defaults = {
['shift-tab' ] = 'focus_prev',
up = 'focus_prev',
},
backgroundColor = colors.cyan,
backgroundColor = UI.colors.primary,
textColor = colors.white,
}
function UI.Page:postInit()
self.parent = self.parent or UI.defaultDevice
self.__target = self
self.canvas = Canvas({
x = 1, y = 1, width = self.parent.width, height = self.parent.height,
isColor = self.parent.isColor,
})
self.canvas:clear(self.backgroundColor, self.textColor)
end
function UI.Page:enable()
self.canvas.visible = true
UI.Window.enable(self)
if not self.focused or not self.focused.enabled then
@@ -49,12 +31,12 @@ function UI.Page:enable()
end
function UI.Page:disable()
self.canvas.visible = false
UI.Window.disable(self)
end
function UI.Page:sync()
if self.enabled then
self:checkFocus()
self.parent:sync()
end
end
@@ -73,22 +55,24 @@ function UI.Page:pointToChild(x, y)
if self.__target == self then
return UI.Window.pointToChild(self, x, y)
end
x = x + self.offx - self.x + 1
y = y + self.offy - self.y + 1
--[[
-- this is supposed to fix when there are multiple sub canvases
local absX, absY = getPosition(self.__target)
if self.__target.canvas then
x = x - (self.__target.canvas.x - self.__target.x)
y = y - (self.__target.canvas.y - self.__target.y)
_syslog({'raw', self.__target.canvas.y, self.__target.y})
-- need to add offsets to this test
local function getPosition(element)
local x, y = 1, 1
repeat
x = element.x + x - 1
y = element.y + y - 1
element = element.parent
until not element
return x, y
end
]]
return self.__target:pointToChild(x, y)
local absX, absY = getPosition(self.__target)
return self.__target:pointToChild(x - absX + self.__target.x, y - absY + self.__target.y)
end
function UI.Page:getFocusables()
if self.__target == self or self.__target.pageType ~= 'modal' then
if self.__target == self or not self.__target.modal then
return UI.Window.getFocusables(self)
end
return self.__target:getFocusables()
@@ -149,12 +133,25 @@ function UI.Page:setFocus(child)
if not child.focused then
child.focused = true
child:emit({ type = 'focus_change', focused = child })
--self:emit({ type = 'focus_change', focused = child })
end
child:focus()
end
function UI.Page:checkFocus()
if not self.focused or not self.focused.enabled then
local el = self.__target
while el do
local focusables = el:getFocusables()
if focusables[1] then
self:setFocus(focusables[1])
break
end
el = el.parent
end
end
end
function UI.Page:eventHandler(event)
if self.focused then
if event.type == 'focus_next' then