switch arg for a function
This commit is contained in:
parent
50a57d7ef6
commit
cff1e58cf6
2
main.lua
2
main.lua
|
@ -225,8 +225,8 @@ end
|
||||||
|
|
||||||
function App.draw()
|
function App.draw()
|
||||||
Button_handlers = {}
|
Button_handlers = {}
|
||||||
love.graphics.setColor(0, 0, 0)
|
|
||||||
|
|
||||||
|
love.graphics.setColor(0, 0, 0)
|
||||||
--? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos)
|
--? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos)
|
||||||
assert(Text.le1(Screen_top1, Cursor1))
|
assert(Text.le1(Screen_top1, Cursor1))
|
||||||
Cursor_y = -1
|
Cursor_y = -1
|
||||||
|
|
26
text.lua
26
text.lua
|
@ -22,7 +22,7 @@ function Text.draw(line, line_index)
|
||||||
if line.fragments == nil then
|
if line.fragments == nil then
|
||||||
Text.compute_fragments(line)
|
Text.compute_fragments(line)
|
||||||
end
|
end
|
||||||
Text.populate_screen_line_starting_pos(line_index)
|
Text.populate_screen_line_starting_pos(line)
|
||||||
--? print('--')
|
--? print('--')
|
||||||
for _, f in ipairs(line.fragments) do
|
for _, f in ipairs(line.fragments) do
|
||||||
local frag, frag_text = f.data, f.text
|
local frag, frag_text = f.data, f.text
|
||||||
|
@ -143,7 +143,7 @@ function Text.textinput(t)
|
||||||
--? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
|
--? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
|
||||||
Text.insert_at_cursor(t)
|
Text.insert_at_cursor(t)
|
||||||
if Cursor_y >= App.screen.height - Line_height then
|
if Cursor_y >= App.screen.height - Line_height then
|
||||||
Text.populate_screen_line_starting_pos(Cursor1.line)
|
Text.populate_screen_line_starting_pos(Lines[Cursor1.line])
|
||||||
Text.snap_cursor_to_bottom_of_screen()
|
Text.snap_cursor_to_bottom_of_screen()
|
||||||
--? print('=>', Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
|
--? print('=>', Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
|
||||||
end
|
end
|
||||||
|
@ -176,7 +176,7 @@ function Text.keychord_pressed(chord)
|
||||||
--? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
|
--? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
|
||||||
Text.insert_at_cursor('\t')
|
Text.insert_at_cursor('\t')
|
||||||
if Cursor_y >= App.screen.height - Line_height then
|
if Cursor_y >= App.screen.height - Line_height then
|
||||||
Text.populate_screen_line_starting_pos(Cursor1.line)
|
Text.populate_screen_line_starting_pos(Lines[Cursor1.line])
|
||||||
Text.snap_cursor_to_bottom_of_screen()
|
Text.snap_cursor_to_bottom_of_screen()
|
||||||
--? print('=>', Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
|
--? print('=>', Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
|
||||||
end
|
end
|
||||||
|
@ -415,7 +415,7 @@ function Text.up()
|
||||||
if Lines[new_cursor_line].mode == 'text' then
|
if Lines[new_cursor_line].mode == 'text' then
|
||||||
--? print('found previous text line')
|
--? print('found previous text line')
|
||||||
Cursor1.line = new_cursor_line
|
Cursor1.line = new_cursor_line
|
||||||
Text.populate_screen_line_starting_pos(Cursor1.line)
|
Text.populate_screen_line_starting_pos(Lines[Cursor1.line])
|
||||||
-- previous text line found, pick its final screen line
|
-- previous text line found, pick its final screen line
|
||||||
--? print('has multiple screen lines')
|
--? print('has multiple screen lines')
|
||||||
local screen_line_starting_pos = Lines[Cursor1.line].screen_line_starting_pos
|
local screen_line_starting_pos = Lines[Cursor1.line].screen_line_starting_pos
|
||||||
|
@ -588,7 +588,7 @@ function Text.right_without_scroll()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Text.pos_at_start_of_cursor_screen_line()
|
function Text.pos_at_start_of_cursor_screen_line()
|
||||||
Text.populate_screen_line_starting_pos(Cursor1.line)
|
Text.populate_screen_line_starting_pos(Lines[Cursor1.line])
|
||||||
for i=#Lines[Cursor1.line].screen_line_starting_pos,1,-1 do
|
for i=#Lines[Cursor1.line].screen_line_starting_pos,1,-1 do
|
||||||
local spos = Lines[Cursor1.line].screen_line_starting_pos[i]
|
local spos = Lines[Cursor1.line].screen_line_starting_pos[i]
|
||||||
if spos <= Cursor1.pos then
|
if spos <= Cursor1.pos then
|
||||||
|
@ -599,7 +599,7 @@ function Text.pos_at_start_of_cursor_screen_line()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Text.cursor_at_final_screen_line()
|
function Text.cursor_at_final_screen_line()
|
||||||
Text.populate_screen_line_starting_pos(Cursor1.line)
|
Text.populate_screen_line_starting_pos(Lines[Cursor1.line])
|
||||||
local screen_lines = Lines[Cursor1.line].screen_line_starting_pos
|
local screen_lines = Lines[Cursor1.line].screen_line_starting_pos
|
||||||
--? print(screen_lines[#screen_lines], Cursor1.pos)
|
--? print(screen_lines[#screen_lines], Cursor1.pos)
|
||||||
return screen_lines[#screen_lines] <= Cursor1.pos
|
return screen_lines[#screen_lines] <= Cursor1.pos
|
||||||
|
@ -667,7 +667,7 @@ function Text.in_line(line_index,line, x,y)
|
||||||
if line.starty == nil then return false end -- outside current page
|
if line.starty == nil then return false end -- outside current page
|
||||||
if x < Margin_left then return false end
|
if x < Margin_left then return false end
|
||||||
if y < line.starty then return false end
|
if y < line.starty then return false end
|
||||||
Text.populate_screen_line_starting_pos(line_index)
|
Text.populate_screen_line_starting_pos(line)
|
||||||
return y < line.starty + Line_height*(#line.screen_line_starting_pos - Text.screen_line_index(line, line.startpos) + 1)
|
return y < line.starty + Line_height*(#line.screen_line_starting_pos - Text.screen_line_index(line, line.startpos) + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -822,7 +822,7 @@ function Text.to2(pos1)
|
||||||
return {line=pos1.line, screen_line=1, screen_pos=1}
|
return {line=pos1.line, screen_line=1, screen_pos=1}
|
||||||
end
|
end
|
||||||
local result = {line=pos1.line, screen_line=1}
|
local result = {line=pos1.line, screen_line=1}
|
||||||
Text.populate_screen_line_starting_pos(pos1.line)
|
Text.populate_screen_line_starting_pos(Lines[pos1.line])
|
||||||
for i=#Lines[pos1.line].screen_line_starting_pos,1,-1 do
|
for i=#Lines[pos1.line].screen_line_starting_pos,1,-1 do
|
||||||
local spos = Lines[pos1.line].screen_line_starting_pos[i]
|
local spos = Lines[pos1.line].screen_line_starting_pos[i]
|
||||||
if spos <= pos1.pos then
|
if spos <= pos1.pos then
|
||||||
|
@ -887,14 +887,12 @@ function Text.previous_screen_line(pos2)
|
||||||
return {line=pos2.line-1, screen_line=1, screen_pos=1}
|
return {line=pos2.line-1, screen_line=1, screen_pos=1}
|
||||||
else
|
else
|
||||||
local l = Lines[pos2.line-1]
|
local l = Lines[pos2.line-1]
|
||||||
Text.populate_screen_line_starting_pos(pos2.line-1)
|
Text.populate_screen_line_starting_pos(Lines[pos2.line-1])
|
||||||
return {line=pos2.line-1, screen_line=#Lines[pos2.line-1].screen_line_starting_pos, screen_pos=1}
|
return {line=pos2.line-1, screen_line=#Lines[pos2.line-1].screen_line_starting_pos, screen_pos=1}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Text.populate_screen_line_starting_pos(line_index)
|
function Text.populate_screen_line_starting_pos(line)
|
||||||
--? print('Text.populate_screen_line_starting_pos', line_index)
|
|
||||||
local line = Lines[line_index]
|
|
||||||
if line.screen_line_starting_pos then
|
if line.screen_line_starting_pos then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -909,11 +907,9 @@ function Text.populate_screen_line_starting_pos(line_index)
|
||||||
local frag, frag_text = f.data, f.text
|
local frag, frag_text = f.data, f.text
|
||||||
-- render fragment
|
-- render fragment
|
||||||
local frag_width = App.width(frag_text)
|
local frag_width = App.width(frag_text)
|
||||||
--? print(x, pos, frag, frag_width)
|
|
||||||
if x + frag_width > App.screen.width-Margin_right then
|
if x + frag_width > App.screen.width-Margin_right then
|
||||||
x = Margin_left
|
x = Margin_left
|
||||||
table.insert(line.screen_line_starting_pos, pos)
|
table.insert(line.screen_line_starting_pos, pos)
|
||||||
--? print('new screen line:', #line.screen_line_starting_pos, pos)
|
|
||||||
end
|
end
|
||||||
x = x + frag_width
|
x = x + frag_width
|
||||||
local frag_len = utf8.len(frag)
|
local frag_len = utf8.len(frag)
|
||||||
|
@ -924,8 +920,8 @@ end
|
||||||
function Text.tweak_screen_top_and_cursor()
|
function Text.tweak_screen_top_and_cursor()
|
||||||
--? print('a', Selection1.line)
|
--? print('a', Selection1.line)
|
||||||
if Screen_top1.pos == 1 then return end
|
if Screen_top1.pos == 1 then return end
|
||||||
Text.populate_screen_line_starting_pos(Screen_top1.line)
|
|
||||||
local line = Lines[Screen_top1.line]
|
local line = Lines[Screen_top1.line]
|
||||||
|
Text.populate_screen_line_starting_pos(line)
|
||||||
for i=2,#line.screen_line_starting_pos do
|
for i=2,#line.screen_line_starting_pos do
|
||||||
local pos = line.screen_line_starting_pos[i]
|
local pos = line.screen_line_starting_pos[i]
|
||||||
if pos == Screen_top1.pos then
|
if pos == Screen_top1.pos then
|
||||||
|
|
Loading…
Reference in New Issue