From 033fabe27552f1c714ff7acb7e787b204a719254 Mon Sep 17 00:00:00 2001 From: Michael Freno Date: Thu, 9 Oct 2025 15:03:23 -0400 Subject: [PATCH] fix click detection --- FlexLove.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/FlexLove.lua b/FlexLove.lua index 5a1172f..bfc7800 100644 --- a/FlexLove.lua +++ b/FlexLove.lua @@ -1432,9 +1432,12 @@ function Element:update(dt) -- Handle click detection for element if self.callback then local mx, my = love.mouse.getPosition() - local bx = self.x - local by = self.y - if mx >= bx and mx <= bx + self.width and my >= by and my <= by + self.height then + -- Include padding in clickable area to match visual bounds + local bx = self.x - self.padding.left + local by = self.y - self.padding.top + local bw = self.width + self.padding.left + self.padding.right + local bh = self.height + self.padding.top + self.padding.bottom + if mx >= bx and mx <= bx + bw and my >= by and my <= by + bh then if love.mouse.isDown(1) then -- set pressed flag self._pressed = true @@ -1449,7 +1452,7 @@ function Element:update(dt) local touches = love.touch.getTouches() for _, id in ipairs(touches) do local tx, ty = love.touch.getPosition(id) - if tx >= bx and tx <= bx + self.width and ty >= by and ty <= by + self.height then + if tx >= bx and tx <= bx + bw and ty >= by and ty <= by + bh then self._touchPressed[id] = true elseif self._touchPressed[id] then self.callback(self)