slightly shrink the clickable area for a button

The reason is tooltips for buttons that lie along the left or bottom
edge of the app window. Since adding tooltips I noticed that the tooltip
on the 'next' button (which lies all down the right margin of the
window) would continue to be visible after the mouse moves off the
window. It turns out that LÖVE doesn't disable the mouse position
somehow after it goes off screen. It just remains at 0 or width-1 or
height-1.

Why was I not seeing the same issue with the 'previous' button? Kinda by
happy accident. The checks in button.lua were comparing using < and >,
not <= or >=. And the x coordinate when the mouse goes off window is 0.

So the quick solution is to remove one px of clickable area from the
bottom and right. It doesn't seem too hacky; the icon switches to
resizing the window anyway when you're _right_ at the border.

I'm also focusing now on the fact that pixel values in LÖVE go from 0 to
width-1 in spite of Lua's 1-based indexing in most places.
This commit is contained in:
Kartik K. Agaram 2024-02-23 15:23:28 -08:00
parent 3293f3e139
commit c7a81906cc
2 changed files with 3 additions and 3 deletions

View File

@ -1,5 +1,5 @@
next_pane_button = function(r)
button(Global_state, 'right', {x=r-30, y=Menu_bottom, w=100, h=App.screen.height, bg={r=0.5, g=0.5, b=0.5, a=0.2},
button(Global_state, 'right', {x=r-30, y=Menu_bottom, w=30, h=App.screen.height, bg={r=0.5, g=0.5, b=0.5, a=0.2},
icon = function(p)
App.color{r=0.4,g=0.4,b=0.4}
love.graphics.polygon('fill', r-25, App.screen.height/2-10, r-25, App.screen.height/2+10, r-5, App.screen.height/2)

View File

@ -22,7 +22,7 @@ function mouse_press_consumed_by_any_button(State, x, y, mouse_button)
local button_pressed = false
local consume_press = true
for _,ev in ipairs(State.button_handlers) do
if x>ev.x and x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h then
if x>ev.x and x<ev.x+ev.w-1 and y>ev.y and y<ev.y+ev.h-1 then
if ev.onpress1 and mouse_button == 1 then
button_pressed = true
if ev.onpress1() then
@ -39,7 +39,7 @@ function draw_button_tooltips(State)
local x,y = love.mouse.getPosition()
for _,ev in ipairs(State.button_handlers) do
if ev.tooltip then
if x>ev.x and x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h then
if x>ev.x and x<ev.x+ev.w-1 and y>ev.y and y<ev.y+ev.h-1 then
ev.tooltip(x,y)
end
end