Refactor skill button and row to use UIElement with Rect bounds and transform Update layout references and coordinate calculations accordingly
22 lines
813 B
Lua
22 lines
813 B
Lua
local Rect = require "lib.simple_ui.rect"
|
|
|
|
--- @class UIElement
|
|
--- @field bounds Rect Прямоугольник, в границах которого размещается элемент. Размеры и положение в *локальных* координатах
|
|
--- @field transform love.Transform Преобразование из локальных координат элемента (bounds) в экранные координаты
|
|
local uiElement = {
|
|
bounds = Rect {},
|
|
transform = love.math.newTransform()
|
|
}
|
|
uiElement.__index = uiElement
|
|
|
|
function uiElement:update(dt) end
|
|
|
|
function uiElement:draw() end
|
|
|
|
function uiElement:hitTest(screenX, screenY)
|
|
local lx, ly = self.transform:inverseTransformPoint(screenX, screenY)
|
|
return self.bounds:hasPoint(lx, ly)
|
|
end
|
|
|
|
return uiElement
|