select cursor pane by clicking on it
This commit is contained in:
parent
99eb76cb56
commit
976980e8bd
1
edit.lua
1
edit.lua
|
@ -9,7 +9,6 @@ Highlight_color = {r=0.7, g=0.7, b=0.9} -- selected text
|
|||
Icon_color = {r=0.7, g=0.7, b=0.7} -- color of current mode icon in drawings
|
||||
Help_color = {r=0, g=0.5, b=0}
|
||||
Help_background_color = {r=0, g=0.5, b=0, a=0.1}
|
||||
Editor_background_color = {r=0.9, g=0.9, b=0, a=0.1}
|
||||
|
||||
Margin_left = 25
|
||||
Margin_right = 25
|
||||
|
|
44
main.lua
44
main.lua
|
@ -9,6 +9,8 @@ require 'button'
|
|||
require 'main_tests'
|
||||
|
||||
Column_header_color = {r=0.4, g=0.4, b=0.4}
|
||||
Pane_background_color = {r=0.9, g=0.9, b=0, a=0.1}
|
||||
Cursor_pane_background_color = {r=0.5, g=0.5, b=0, a=0.1}
|
||||
|
||||
-- The note-taking app has a few differences with the baseline editor it's
|
||||
-- forked from:
|
||||
|
@ -58,6 +60,8 @@ function App.initialize_globals()
|
|||
|
||||
Pan = {}
|
||||
|
||||
Cursor_pane = nil -- surface column and row index, along with some cached data
|
||||
|
||||
-- resize
|
||||
Last_resize_time = nil
|
||||
|
||||
|
@ -165,11 +169,11 @@ function App.draw()
|
|||
-- top > Margin_top or Screen_top.line > 1
|
||||
local x = Padding_horizontal + Margin_left
|
||||
--? print('draw')
|
||||
for _, column in ipairs(Surface) do
|
||||
for column_index, column in ipairs(Surface) do
|
||||
if overlap(x, x+Display_settings.column_width, Display_settings.x, Display_settings.x + App.screen.width) then
|
||||
--? print('draw column')
|
||||
local y = Margin_top
|
||||
for _, pane in ipairs(column) do
|
||||
for pane_index, pane in ipairs(column) do
|
||||
if overlap(y, y + Margin_above + Cache[pane.id].height + Margin_below, Display_settings.y, Display_settings.y + App.screen.height) then
|
||||
--? print('draw pane')
|
||||
pane.top = y - Display_settings.y + Margin_above
|
||||
|
@ -178,7 +182,11 @@ function App.draw()
|
|||
pane.width = pane.right - pane.left
|
||||
-- TODO: update pane.screen_top1 and pane.cursor1
|
||||
edit.draw(pane)
|
||||
App.color(Editor_background_color)
|
||||
if Cursor_pane and column_index == Cursor_pane.col and pane_index == Cursor_pane.row then
|
||||
App.color(Cursor_pane_background_color)
|
||||
else
|
||||
App.color(Pane_background_color)
|
||||
end
|
||||
love.graphics.rectangle('fill', pane.left-Margin_left,pane.top-Margin_above, pane.width+Margin_left+Margin_right, pane.bottom-pane.top+Margin_above+Margin_below)
|
||||
end
|
||||
y = y + Margin_above + Cache[pane.id].height + Margin_below + Padding_vertical
|
||||
|
@ -238,6 +246,7 @@ function App.update(dt)
|
|||
end
|
||||
|
||||
function in_pane(x,y)
|
||||
-- duplicate some logic from App.draw
|
||||
local sx,sy = to_surface(x,y)
|
||||
local x = Padding_horizontal
|
||||
for column_idx, column in ipairs(Surface) do
|
||||
|
@ -261,6 +270,31 @@ function in_pane(x,y)
|
|||
return false
|
||||
end
|
||||
|
||||
function to_pane(x,y)
|
||||
-- duplicate some logic from App.draw
|
||||
local sx,sy = to_surface(x,y)
|
||||
local x = Padding_horizontal
|
||||
for column_idx, column in ipairs(Surface) do
|
||||
if sx < x then
|
||||
return nil
|
||||
end
|
||||
if sx < x + Margin_left + Display_settings.column_width + Margin_right then
|
||||
local y = Margin_top
|
||||
for pane_idx, pane in ipairs(column) do
|
||||
if sy < y then
|
||||
return nil
|
||||
end
|
||||
if sy < y + Margin_above + Cache[pane.id].height + Margin_below then
|
||||
return {col=column_idx, row=pane_idx}
|
||||
end
|
||||
y = y + Margin_above + Cache[pane.id].height + Margin_below + Padding_vertical
|
||||
end
|
||||
end
|
||||
x = x + Margin_left + Display_settings.column_width + Margin_right + Padding_horizontal
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function to_surface(x, y)
|
||||
return x+Display_settings.x, y+Display_settings.y
|
||||
end
|
||||
|
@ -292,7 +326,9 @@ function App.mousepressed(x,y, mouse_button)
|
|||
return
|
||||
end
|
||||
local sx,sy = to_surface(x,y)
|
||||
if not in_pane(x,y) then
|
||||
if in_pane(x,y) then
|
||||
Cursor_pane = to_pane(sx,sy)
|
||||
else
|
||||
Pan = {x=sx, y=sy}
|
||||
return
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user