This was hard to track down because lua's print implicitly hides tiny fractions, making non-integers look like integers. So there's a gotcha here: ensure that parameters to edit.initialize are integers. I'm documenting it on the caller and also defensively converting to an int inside the callee.
ACEWU2ORP2QPYQQL2MXWLOQGAG4XBU5YWOO57K6KJBPJU4VDNH5AC
{"on.mouse_released":178,"Box_heights":277,"on":1,"on.keychord_pressed":311,"Page":324,"A":309,"on.update":315,"on.textinput":177,"clip_all":265,"parent":337,"Surface":196,"scale":7,"on.code_changed":306,"on.draw":310,"font":228,"vx":5,"Cursor_node":172,"Viewport":303,"clip":236,"on.mouse_pressed":179,"vy":8,"initialize_editor":338,"box_height":317,"B":316,"compute_layout":335,"on.initialize":304,"to_text":180}
initialize_editor = function(obj)
if obj.w then
-- use an editor to wrap the text
local scaled_fontsize = scale(20)
local scaled_lineheight = math.floor(scaled_fontsize*1.3)
obj.editor = edit.initialize_state(vy(obj.y), math.floor(vx(obj.x)), math.ceil(vx(obj.x+obj.w)), scaled_fontsize, scaled_lineheight)
obj.editor.lines = load_array(obj.data)
Text.redraw_all(obj.editor)
end
end
{"on.initialize":304,"Surface":196,"B":316,"on.draw":310,"on":1,"vx":5,"on.mouse_released":178,"Viewport":303,"initialize_editor":337,"box_height":317,"vy":8,"compute_layout":335,"to_text":180,"Page":324,"on.keychord_pressed":311,"Box_heights":277,"on.mouse_pressed":179,"on.code_changed":306,"Cursor_node":172,"font":228,"clip":236,"parent":336,"clip_all":265,"scale":7,"on.textinput":177,"on.update":315,"A":309}
initialize_editor = function(obj)
if obj.w then
-- use an editor to wrap the text
local scaled_fontsize = scale(20)
local scaled_lineheight = math.floor(scaled_fontsize*1.3)
----[[
print('init', obj.data[1], obj.w)
print('at zoom', Viewport.zoom)
print('width', obj.w, 'scales to', scale(obj.w))
print('left', vx(obj.x))
print('right', vx(obj.x+obj.w))
print('width', vx(obj.x+obj.w)-vx(obj.x))
-- ]]
obj.editor = edit.initialize_state(vy(obj.y), math.floor(vx(obj.x)), math.ceil(vx(obj.x+obj.w)), scaled_fontsize, scaled_lineheight)
obj.editor.lines = load_array(obj.data)
Text.redraw_all(obj.editor)
end
end
{"on.mouse_released":178,"initialize_editor":336,"on.update":315,"to_text":180,"compute_layout":335,"A":309,"box_height":317,"Box_heights":277,"Page":324,"clip":236,"on.code_changed":306,"on.textinput":177,"Surface":196,"on":1,"on.draw":310,"vx":5,"clip_all":265,"Viewport":303,"B":316,"vy":8,"scale":7,"parent":335,"Cursor_node":172,"font":228,"on.initialize":304,"on.mouse_pressed":179,"on.keychord_pressed":311}
initialize_editor = function(obj)
if obj.w then
-- use an editor to wrap the text
local scaled_fontsize = scale(20)
local scaled_lineheight = math.floor(scaled_fontsize*1.3)
----[[
print('init', obj.data[1], obj.w)
print('at zoom', Viewport.zoom)
print('width', obj.w, 'scales to', scale(obj.w))
print('left', vx(obj.x))
print('right', vx(obj.x+obj.w))
print('width', vx(obj.x+obj.w)-vx(obj.x))
-- ]]
obj.editor = edit.initialize_state(vy(obj.y), vx(obj.x), math.ceil(vx(obj.x+obj.w)), scaled_fontsize, scaled_lineheight)
obj.editor.lines = load_array(obj.data)
Text.redraw_all(obj.editor)
end
end
{"parent":334,"font":228,"on.mouse_released":178,"on.update":315,"box_height":317,"on.keychord_pressed":311,"compute_layout":335,"to_text":180,"Page":324,"clip":236,"on.code_changed":306,"scale":7,"on.initialize":304,"Surface":196,"A":309,"on.draw":310,"Box_heights":277,"initialize_editor":333,"vx":5,"on.mouse_pressed":179,"Viewport":303,"on":1,"Cursor_node":172,"vy":8,"B":316,"clip_all":265,"on.textinput":177}
compute_layout = function(node, x,y, nodes_to_render)
-- append to nodes_to_render flattened instructions to render a hierarchy of nodes
-- return x,y rendered until (surface coordinates)
if node.type == 'text' then
-- leaf node containing raw text
node.x = x
node.y = y
-- render background if necessary
local node_to_render
if node.bg then
node_to_render = {type='rectangle', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x, y=node.y}
table.insert(nodes_to_render, node_to_render)
end
-- render contents
if node.width then
node.w = node.width
else
node.w = 0
for i,s in ipairs(node.data) do
local text = love.graphics.newText(font(20), node.data)
local width = text:getWidth()
print(node.data[i], 'has width', width)
if node.w < width then node.w = width end
end
end
initialize_editor(node)
node.h = box_height(node)
table.insert(nodes_to_render, node)
if node_to_render then
node_to_render.w = node.w
node_to_render.h = node.h
end
elseif node.type == 'rows' then
node.x = x
node.y = y
local node_to_render
if node.bg then
node_to_render = {type='rectangle', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x, y=node.y}
table.insert(nodes_to_render, node_to_render)
end
-- lay out children top to bottom
local subx,suby = x,y
local w,h = 0,0
local subnodes
for _,child in ipairs(node.data) do
if child.margin then
suby = suby+child.margin
h = h+child.margin
end
subx,suby = compute_layout(child, x,suby, nodes_to_render)
if w < child.w then
w = child.w
end
h = h+child.h
end
node.w = w
node.h = h
if node_to_render then
node_to_render.w = w
node_to_render.h = h
end
elseif node.type == 'cols' then
node.x = x
node.y = y
-- lay out children left to right
local node_to_render
if node.bg then
node_to_render = {type='rectangle', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x, y=node.y}
table.insert(nodes_to_render, node_to_render)
end
local subx,suby = x,y
local w,h = 0,0
for _,child in ipairs(node.data) do
if child.margin then
subx = subx+child.margin
w = w+child.margin
end
subx,suby = compute_layout(child, subx,y, nodes_to_render)
w = w + child.w
if h < child.h then
h = child.h
end
end
node.w = w
node.h = h
if node_to_render then
node_to_render.w = w
node_to_render.h = h
end
end
return x+node.w,y+node.h
end
{"parent":333,"font":228,"on.mouse_released":178,"on.update":315,"box_height":317,"on.keychord_pressed":311,"compute_layout":334,"to_text":180,"Page":324,"clip":236,"on.code_changed":306,"scale":7,"on.initialize":304,"Surface":196,"A":309,"on.draw":310,"Box_heights":277,"initialize_editor":333,"vx":5,"on.mouse_pressed":179,"Viewport":303,"on":1,"Cursor_node":172,"vy":8,"B":316,"clip_all":265,"on.textinput":177}
compute_layout = function(node, x,y, nodes_to_render)
-- append to nodes_to_render flattened instructions to render a hierarchy of nodes
-- return x,y rendered until (surface coordinates)
if node.type == 'text' then
-- leaf node containing raw text
node.x = x
node.y = y
-- render background if necessary
local node_to_render
if node.bg then
node_to_render = {type='rectangle', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x, y=node.y}
table.insert(nodes_to_render, node_to_render)
end
-- render contents
if node.width then
node.w = node.width
else
node.w = 0
for i,s in ipairs(node.data) do
local text = love.graphics.newText(20, node.data)
local width = text:getWidth()
print(node.data[i], 'has width', width)
if node.w < width then node.w = width end
end
end
initialize_editor(node)
node.h = box_height(node)
table.insert(nodes_to_render, node)
if node_to_render then
node_to_render.w = node.w
node_to_render.h = node.h
end
elseif node.type == 'rows' then
node.x = x
node.y = y
local node_to_render
if node.bg then
node_to_render = {type='rectangle', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x, y=node.y}
table.insert(nodes_to_render, node_to_render)
end
-- lay out children top to bottom
local subx,suby = x,y
local w,h = 0,0
local subnodes
for _,child in ipairs(node.data) do
if child.margin then
suby = suby+child.margin
h = h+child.margin
end
subx,suby = compute_layout(child, x,suby, nodes_to_render)
if w < child.w then
w = child.w
end
h = h+child.h
end
node.w = w
node.h = h
if node_to_render then
node_to_render.w = w
node_to_render.h = h
end
elseif node.type == 'cols' then
node.x = x
node.y = y
-- lay out children left to right
local node_to_render
if node.bg then
node_to_render = {type='rectangle', r=node.bg.r, g=node.bg.g, b=node.bg.b, x=node.x, y=node.y}
table.insert(nodes_to_render, node_to_render)
end
local subx,suby = x,y
local w,h = 0,0
for _,child in ipairs(node.data) do
if child.margin then
subx = subx+child.margin
w = w+child.margin
end
subx,suby = compute_layout(child, subx,y, nodes_to_render)
w = w + child.w
if h < child.h then
h = child.h
end
end
node.w = w
node.h = h
if node_to_render then
node_to_render.w = w
node_to_render.h = h
end
end
return x+node.w,y+node.h
end
{"parent":332,"font":228,"on.mouse_released":178,"on.update":315,"box_height":317,"on.keychord_pressed":311,"compute_layout":301,"to_text":180,"Page":324,"clip":236,"on.code_changed":306,"scale":7,"on.initialize":304,"Surface":196,"A":309,"on.draw":310,"Box_heights":277,"initialize_editor":333,"vx":5,"on.mouse_pressed":179,"Viewport":303,"on":1,"Cursor_node":172,"vy":8,"B":316,"clip_all":265,"on.textinput":177}
initialize_editor = function(obj)
if obj.w then
-- use an editor to wrap the text
local scaled_fontsize = scale(20)
local scaled_lineheight = math.floor(scaled_fontsize*1.3)
----[[
print('init', obj.data[1], obj.w)
print('at zoom', Viewport.zoom)
print('width', obj.w, 'scales to', scale(obj.w))
print('left', vx(obj.x))
print('right', vx(obj.x+obj.w))
print('width', vx(obj.x+obj.w)-vx(obj.x))
-- ]]
obj.editor = edit.initialize_state(vy(obj.y), vx(obj.x), vx(obj.x+obj.w), scaled_fontsize, scaled_lineheight)
obj.editor.lines = load_array(obj.data)
Text.redraw_all(obj.editor)
end
end
{"on.keychord_pressed":311,"scale":7,"Page":324,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":331,"box_height":317,"on.mouse_pressed":179,"initialize_editor":332,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
initialize_editor = function(obj)
if obj.w then
-- use an editor to wrap the text
local scaled_fontsize = scale(20)
local scaled_lineheight = math.floor(scaled_fontsize*1.3)
----[[
print('init', obj.data[1], obj.w)
print('at zoom', Viewport.zoom)
print('width', obj.w, 'scales to', scale(obj.w))
print('left', vx(obj.x))
print('right', vx(obj.x+obj.w))
print('width', vx(obj.x+obj.w)-vx(obj.x))
-- ]]
obj.editor = edit.initialize_state(vy(obj.y), vx(obj.x), vx(obj.x+obj.w), scaled_fontsize, scaled_lineheight)
obj.editor.lines = load_array(obj.data)
Text.redraw_all(obj.editor)
end
end
{"on.keychord_pressed":311,"scale":7,"Page":324,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":330,"box_height":317,"on.mouse_pressed":179,"initialize_editor":331,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
initialize_editor = function(obj)
if obj.w then
-- use an editor to wrap the text
local scaled_fontsize = scale(20)
local scaled_lineheight = math.floor(scaled_fontsize*1.3)
----[[
print('init', obj.data[1], obj.w)
print('at zoom', Viewport.zoom)
print('width', obj.w, 'scales to', scale(obj.w))
print('left', vx(obj.x))
print('right', vx(obj.x+obj.w))
print('width', vx(obj.x+obj.w)-vx(obj.x))
-- ]]
obj.editor = edit.initialize_state(vy(obj.y), vx(obj.x), vx(obj.x+obj.w), scaled_fontsize, scaled_lineheight)
obj.editor.lines = load_array(obj.data)
Text.redraw_all(obj.editor)
end
end
{"on.keychord_pressed":311,"scale":7,"Page":324,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":329,"box_height":317,"on.mouse_pressed":179,"initialize_editor":330,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
initialize_editor = function(obj)
if obj.w then
-- use an editor to wrap the text
local scaled_fontsize = scale(20)
local scaled_lineheight = math.floor(scaled_fontsize*1.3)
--[[
print('init', obj.data[1], obj.w)
print('at zoom', Viewport.zoom)
print('width', obj.w, 'scales to', scale(obj.w))
print('left', vx(obj.x))
print('right', vx(obj.x+obj.w))
print('width', vx(obj.x+obj.w)-vx(obj.x))
-- ]]
obj.editor = edit.initialize_state(vy(obj.y), vx(obj.x), vx(obj.x+obj.w), scaled_fontsize, scaled_lineheight)
obj.editor.lines = load_array(obj.data)
Text.redraw_all(obj.editor)
end
end
{"on.keychord_pressed":311,"scale":7,"Page":324,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":328,"box_height":317,"on.mouse_pressed":179,"initialize_editor":329,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
initialize_editor = function(obj)
if obj.w then
-- use an editor to wrap the text
local scaled_fontsize = scale(20)
local scaled_lineheight = math.floor(scaled_fontsize*1.3)
----[[
print('init', obj.data[1], obj.w)
print('at zoom', Viewport.zoom)
print('width', obj.w, 'scales to', scale(obj.w))
print('left', vx(obj.x))
print('right', vx(obj.x+obj.w))
print('width', vx(obj.x+obj.w)-vx(obj.x))
-- ]]
obj.editor = edit.initialize_state(vy(obj.y), vx(obj.x), vx(obj.x+obj.w), scaled_fontsize, scaled_lineheight)
obj.editor.lines = load_array(obj.data)
Text.redraw_all(obj.editor)
end
end
{"on.keychord_pressed":311,"scale":7,"Page":324,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":327,"box_height":317,"on.mouse_pressed":179,"initialize_editor":328,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
initialize_editor = function(obj)
if obj.w then
-- use an editor to wrap the text
local scaled_fontsize = scale(20)
local scaled_lineheight = math.floor(scaled_fontsize*1.3)
--[[
print('init', obj.data[1], obj.w)
print('at zoom', Viewport.zoom)
print('width', obj.w, 'scales to', scale(obj.w))
print('left', vx(obj.x))
print('right', vx(obj.x+obj.w))
print('width', vx(obj.x+obj.w)-vx(obj.x))
]]
obj.editor = edit.initialize_state(vy(obj.y), vx(obj.x), vx(obj.x+obj.w), scaled_fontsize, scaled_lineheight)
obj.editor.lines = load_array(obj.data)
Text.redraw_all(obj.editor)
end
end
{"on.keychord_pressed":311,"scale":7,"Page":324,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":326,"box_height":317,"on.mouse_pressed":179,"initialize_editor":327,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
initialize_editor = function(obj)
if obj.w then
-- use an editor to wrap the text
local scaled_fontsize = scale(20)
local scaled_lineheight = math.floor(scaled_fontsize*1.3)
print('init', obj.data[1], obj.w)
print('at zoom', Viewport.zoom)
print('width', obj.w, 'scales to', scale(obj.w))
print('left', vx(obj.x))
print('right', vx(obj.x+obj.w))
print('width', vx(obj.x+obj.w)-vx(obj.x))
obj.editor = edit.initialize_state(vy(obj.y), vx(obj.x), vx(obj.x+obj.w), scaled_fontsize, scaled_lineheight)
obj.editor.lines = load_array(obj.data)
Text.redraw_all(obj.editor)
end
end
{"on.keychord_pressed":311,"scale":7,"Page":324,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":325,"box_height":317,"on.mouse_pressed":179,"initialize_editor":326,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
initialize_editor = function(obj)
if obj.w then
-- use an editor to wrap the text
local scaled_fontsize = scale(20)
local scaled_lineheight = math.floor(scaled_fontsize*1.3)
print('init', obj.data[1], obj.w)
print('at zoom', Viewport.zoom)
print('width', obj.w, 'scales to', scale(obj.w))
obj.editor = edit.initialize_state(vy(obj.y), vx(obj.x), vx(obj.x+obj.w), scaled_fontsize, scaled_lineheight)
obj.editor.lines = load_array(obj.data)
Text.redraw_all(obj.editor)
end
end
{"on.keychord_pressed":311,"scale":7,"Page":324,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":324,"box_height":317,"on.mouse_pressed":179,"initialize_editor":325,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
initialize_editor = function(obj)
if obj.w then
-- use an editor to wrap the text
local scaled_fontsize = scale(20)
local scaled_lineheight = math.floor(scaled_fontsize*1.3)
print('init', obj.data[1], obj.w)
print('at zoom', Viewport.zoom)
print('with width', obj.w)
obj.editor = edit.initialize_state(vy(obj.y), vx(obj.x), vx(obj.x+obj.w), scaled_fontsize, scaled_lineheight)
obj.editor.lines = load_array(obj.data)
Text.redraw_all(obj.editor)
end
end
{"on.keychord_pressed":311,"scale":7,"Page":324,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":323,"box_height":317,"on.mouse_pressed":179,"initialize_editor":313,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
Page = {
-- page
type='cols', x=0, y=0,
width=800, data={
--[[
-- editor covering left side
{
type='text',
name='editor',
doc='prose goes here, on the left half of the window',
margin=Margin_left,
data={
-- "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
'1',
'2',
'3',
'mno',
'Acb',
'g',
'hij',
'klm',
'nop',
},
width=400, bg={r=1,g=1,b=0}
},
]]
-- a table on the right
{ type='rows', name='searches', margin=50, data={
-- { type='text', data={''},},
--[[
{ type='cols', data={
{ type='text', data={'search:'},},
{ type='text', name='search', bg={r=0.8,g=0.8,b=0.8}, data={''}, width=90,},
}},
]]
-- { type='text', data={'table:'},},
{ type='cols', bg={r=0.8,g=0.8,b=0.8}, data={
--[[
{ type='rows', width=90, data={
{type='text', data={'abc'},},
{type='text', data={'abc'},},
}},
]]
{ type='rows', width=90, data={
-- {type='text', data={'def'},},
{type='text', data={'def'},},
}},
}},
}},
},
}
{"on.keychord_pressed":311,"scale":7,"Page":323,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":322,"box_height":317,"on.mouse_pressed":179,"initialize_editor":313,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
Page = {
-- page
type='cols', x=0, y=0,
width=800, data={
--[[
-- editor covering left side
{
type='text',
name='editor',
doc='prose goes here, on the left half of the window',
margin=Margin_left,
data={
-- "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
'1',
'2',
'3',
'mno',
'Acb',
'g',
'hij',
'klm',
'nop',
},
width=400, bg={r=1,g=1,b=0}
},
]]
-- a table on the right
{ type='rows', name='searches', margin=50, data={
-- { type='text', data={''},},
--[[
{ type='cols', data={
{ type='text', data={'search:'},},
{ type='text', name='search', bg={r=0.8,g=0.8,b=0.8}, data={''}, width=90,},
}},
]]
-- { type='text', data={'table:'},},
{ type='cols', bg={r=0.8,g=0.8,b=0.8}, data={
--[[
{ type='rows', width=90, data={
{type='text', data={'abc'},},
{type='text', data={'abc'},},
}},
]]
{ type='rows', width=90, data={
{type='text', data={'def'},},
{type='text', data={'def'},},
}},
}},
}},
},
}
{"on.keychord_pressed":311,"scale":7,"Page":322,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":321,"box_height":317,"on.mouse_pressed":179,"initialize_editor":313,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
Page = {
-- page
type='cols', x=0, y=0,
width=800, data={
--[[
-- editor covering left side
{
type='text',
name='editor',
doc='prose goes here, on the left half of the window',
margin=Margin_left,
data={
-- "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
'1',
'2',
'3',
'mno',
'Acb',
'g',
'hij',
'klm',
'nop',
},
width=400, bg={r=1,g=1,b=0}
},
]]
-- a table on the right
{ type='rows', name='searches', margin=50, data={
-- { type='text', data={''},},
--[[
{ type='cols', data={
{ type='text', data={'search:'},},
{ type='text', name='search', bg={r=0.8,g=0.8,b=0.8}, data={''}, width=90,},
}},
]]
-- { type='text', data={'table:'},},
{ type='cols', bg={r=0.8,g=0.8,b=0.8}, data={
{ type='rows', width=90, data={
{type='text', data={'abc'},},
-- {type='text', data={'abc'},},
}},
{ type='rows', width=90, data={
{type='text', data={'def'},},
{type='text', data={'def'},},
}},
}},
}},
},
}
{"on.keychord_pressed":311,"scale":7,"Page":321,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":320,"box_height":317,"on.mouse_pressed":179,"initialize_editor":313,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
Page = {
-- page
type='cols', x=0, y=0,
width=800, data={
--[[
-- editor covering left side
{
type='text',
name='editor',
doc='prose goes here, on the left half of the window',
margin=Margin_left,
data={
-- "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
'1',
'2',
'3',
'mno',
'Acb',
'g',
'hij',
'klm',
'nop',
},
width=400, bg={r=1,g=1,b=0}
},
]]
-- a table on the right
{ type='rows', name='searches', margin=50, data={
-- { type='text', data={''},},
--[[
{ type='cols', data={
{ type='text', data={'search:'},},
{ type='text', name='search', bg={r=0.8,g=0.8,b=0.8}, data={''}, width=90,},
}},
]]
-- { type='text', data={'table:'},},
{ type='cols', bg={r=0.8,g=0.8,b=0.8}, data={
{ type='rows', width=90, data={
{type='text', data={'abc'},},
{type='text', data={'abc'},},
}},
{ type='rows', width=90, data={
{type='text', data={'def'},},
{type='text', data={'def'},},
}},
}},
}},
},
}
{"on.keychord_pressed":311,"scale":7,"Page":320,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":319,"box_height":317,"on.mouse_pressed":179,"initialize_editor":313,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
Page = {
-- page
type='cols', x=0, y=0,
width=800, data={
--[[
-- editor covering left side
{
type='text',
name='editor',
doc='prose goes here, on the left half of the window',
margin=Margin_left,
data={
-- "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
'1',
'2',
'3',
'mno',
'Acb',
'g',
'hij',
'klm',
'nop',
},
width=400, bg={r=1,g=1,b=0}
},
]]
-- a table on the right
{ type='rows', name='searches', margin=50, data={
-- { type='text', data={''},},
{ type='cols', data={
{ type='text', data={'search:'},},
{ type='text', name='search', bg={r=0.8,g=0.8,b=0.8}, data={''}, width=90,},
}},
-- { type='text', data={'table:'},},
{ type='cols', bg={r=0.8,g=0.8,b=0.8}, data={
{ type='rows', width=90, data={
{type='text', data={'abc'},},
{type='text', data={'abc'},},
}},
{ type='rows', width=90, data={
{type='text', data={'def'},},
{type='text', data={'def'},},
}},
}},
}},
},
}
{"on.keychord_pressed":311,"scale":7,"Page":319,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":318,"box_height":317,"on.mouse_pressed":179,"initialize_editor":313,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
Page = {
-- page
type='cols', x=0, y=0,
width=800, data={
--[[
-- editor covering left side
{
type='text',
name='editor',
doc='prose goes here, on the left half of the window',
margin=Margin_left,
data={
-- "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
'1',
'2',
'3',
'mno',
'Acb',
'g',
'hij',
'klm',
'nop',
},
width=400, bg={r=1,g=1,b=0}
},
]]
-- a table on the right
{ type='rows', name='searches', margin=50, data={
-- { type='text', data={''},},
{ type='cols', data={
{ type='text', data={'search:'},},
{ type='text', name='search', bg={r=0.8,g=0.8,b=0.8}, data={''}, width=90,},
}},
{ type='text', data={'table:'},},
{ type='cols', bg={r=0.8,g=0.8,b=0.8}, data={
{ type='rows', width=90, data={
{type='text', data={'abc'},},
{type='text', data={'abc'},},
}},
{ type='rows', width=90, data={
{type='text', data={'def'},},
{type='text', data={'def'},},
}},
}},
}},
},
}
{"on.keychord_pressed":311,"scale":7,"Page":318,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":317,"box_height":317,"on.mouse_pressed":179,"initialize_editor":313,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
Page = {
-- page
type='cols', x=0, y=0,
width=800, data={
--[[
-- editor covering left side
{
type='text',
name='editor',
doc='prose goes here, on the left half of the window',
margin=Margin_left,
data={
-- "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
'1',
'2',
'3',
'mno',
'Acb',
'g',
'hij',
'klm',
'nop',
},
width=400, bg={r=1,g=1,b=0}
},
]]
-- a table on the right
{ type='rows', name='searches', margin=50, data={
{ type='text', data={''},},
{ type='cols', data={
{ type='text', data={'search:'},},
{ type='text', name='search', bg={r=0.8,g=0.8,b=0.8}, data={''}, width=90,},
}},
{ type='text', data={'table:'},},
{ type='cols', bg={r=0.8,g=0.8,b=0.8}, data={
{ type='rows', width=90, data={
{type='text', data={'abc'},},
{type='text', data={'abc'},},
}},
{ type='rows', width=90, data={
{type='text', data={'def'},},
{type='text', data={'def'},},
}},
}},
}},
},
}
{"on.keychord_pressed":311,"scale":7,"Page":312,"on.code_changed":306,"clip":236,"clip_all":265,"on.textinput":177,"Surface":196,"on.initialize":304,"font":228,"A":309,"vx":5,"Box_heights":277,"Viewport":303,"B":316,"compute_layout":301,"vy":8,"Cursor_node":172,"on":1,"parent":316,"box_height":317,"on.mouse_pressed":179,"initialize_editor":313,"on.mouse_released":178,"to_text":180,"on.update":315,"on.draw":310}
box_height = function(node)
-- return the height of a node. The result is scaled.
print('computing box height based on font size', node.scaled_fontsize, node.editor.font_height, node.editor.line_height)
if #node.editor.lines > 1 then Box_heights = {} end
local y = 0
for i=1,#node.editor.lines do
local line = node.editor.lines[i]
if node.editor.line_cache[i] == nil then
node.editor.line_cache[i] = {}
end
node.editor.line_cache[i].fragments = nil
node.editor.line_cache[i].screen_line_starting_pos = nil
Text.compute_fragments(node.editor, i)
Text.populate_screen_line_starting_pos(node.editor, i)
y = y + node.editor.line_height*#node.editor.line_cache[i].screen_line_starting_pos
if #node.editor.lines > 1 then
table.insert(Box_heights, y)
end
Text.clear_screen_line_cache(node.editor, i)
end
return y
end