bugfix: panning with mouse in file picker

This commit is contained in:
Kartik K. Agaram 2023-06-22 08:14:00 -07:00
parent 91831af1c8
commit 2a32a1468b
4 changed files with 18 additions and 35 deletions

View File

@ -1,6 +1,16 @@
on.mouse_press = function(x,y, mouse_button)
if Global_state.thread == nil then
-- do nothing; everything happens on release
-- we're rendering the file picker
-- check for any button clicks
for _,button in ipairs(Global_state.file_picker) do
-- do nothing; everything happens on release
-- (to avoid changing the surface between press and release)
if in_rect(button, x,y) then
return
end
end
-- no button clicked; pan surface
Pan = {x=Viewport.x+x/Viewport.zoom,y=Viewport.y+y/Viewport.zoom}
return
end
if Cursor_node then

View File

@ -1,21 +1,22 @@
on.mouse_release = function(x,y, mouse_button)
if Global_state.thread == nil then
-- we're rendering the file picker
-- file picker
-- check for any button clicks
-- compute_layout reuses nodes and so it fills in x,y for us
for _,button in ipairs(Global_state.file_picker) do
if in_rect(button, x,y) then
open_thread(button.data[1].data)
A()
break
return
end
end
return
end
if Pan then
-- HACK: shared by file picker and thread view
Pan = nil
A()
elseif Cursor_node then
-- thread view
Cursor_node.show_cursor = true
edit.mouse_release(Cursor_node.editor, x,y, mouse_button)
end

View File

@ -1,13 +1,10 @@
on.update = function(dt)
if Pan then
set_mouse_cursor('hand')
else
set_mouse_cursor('arrow')
end
if Pan then
Viewport.x = Pan.x - App.mouse_x()/Viewport.zoom
Viewport.y = Pan.y - App.mouse_y()/Viewport.zoom
B()
return
else
set_mouse_cursor('arrow')
end
end

View File

@ -1,25 +0,0 @@
draw_file_picker = function()
local font = love.graphics.getFont()
local y, x = Margin_top, Margin_left
for _,f in ipairs(Files) do
local w = font:getWidth(f)
if x + w > App.screen.width then
y = y + font:getHeight()*font:getLineHeight() + 10
x = Margin_left
end
button(Global_state, f, {
x=x-5, y=y-2, w=w+10, h=font:getHeight()*font:getLineHeight()+4,
color={0.7,0.7,1.0},
icon=function(p)
App.color{r=0.4,g=0.4,b=0.7}
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 5,5)
App.color{r=0,g=0,b=0}
love.graphics.print(f, x,y)
end,
onpress1 = function()
open_thread(f)
end,
})
x = x + App.width(f) + 15
end
end