Merge lines.love
This commit is contained in:
commit
334ec7bf7c
|
@ -843,7 +843,7 @@ end
|
|||
-- regular pane: pass in id, load from disk, may be edited
|
||||
-- search pane: create without id, initialize id after search term is typed in, create empty file, slowly append to disk, may not be edited
|
||||
function initialize_search_all_pane()
|
||||
local result = edit.initialize_state(0, 0, math.min(Display_settings.column_width, App.screen.width-Margin_right), Font_height, Line_height)
|
||||
local result = edit.initialize_state(0, 0, math.min(Display_settings.column_width, App.screen.width-Margin_right), love.graphics.getFont(), Font_height, Line_height)
|
||||
result.font_height = Font_height
|
||||
result.line_height = Line_height
|
||||
result.editable = false
|
||||
|
|
11
edit.lua
11
edit.lua
|
@ -23,7 +23,7 @@ Same_point_distance = 4 -- pixel distance at which two points are considered th
|
|||
edit = {}
|
||||
|
||||
-- run in both tests and a real run
|
||||
function edit.initialize_state(top, left, right, font_height, line_height) -- currently always draws to bottom of screen
|
||||
function edit.initialize_state(top, left, right, font, font_height, line_height) -- currently always draws to bottom of screen
|
||||
local result = {
|
||||
id='test_id',
|
||||
-- a line is either text or a drawing
|
||||
|
@ -85,6 +85,7 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
|
|||
current_drawing_mode = 'line', -- one of the available shape modes
|
||||
previous_drawing_mode = nil, -- extra state for some ephemeral modes like moving/deleting/naming points
|
||||
|
||||
font = font,
|
||||
font_height = font_height,
|
||||
line_height = line_height,
|
||||
|
||||
|
@ -106,7 +107,7 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
|
|||
search_backup = nil, -- stuff to restore when cancelling search
|
||||
}
|
||||
return result
|
||||
end -- App.initialize_state
|
||||
end -- edit.initialize_state
|
||||
|
||||
function edit.check_locs(State)
|
||||
-- if State is inconsistent (i.e. file changed by some other program),
|
||||
|
@ -168,6 +169,7 @@ end
|
|||
function edit.draw(State)
|
||||
--? print_and_log(('edit.draw %s %d %d,%d'):format(State.id, State.top, State.left,State.right))
|
||||
State.button_handlers = {}
|
||||
love.graphics.setFont(State.font)
|
||||
App.color(Text_color)
|
||||
assert(#State.lines == #State.line_cache, ('line_cache is out of date; %d elements when it should be %d'):format(#State.line_cache, #State.lines))
|
||||
State.cursor_x = nil
|
||||
|
@ -597,7 +599,7 @@ end
|
|||
|
||||
function edit.update_font_settings(State, font_height)
|
||||
State.font_height = font_height
|
||||
love.graphics.setFont(love.graphics.newFont(State.font_height))
|
||||
State.font = love.graphics.newFont(State.font_height)
|
||||
State.line_height = math.floor(font_height*1.3)
|
||||
end
|
||||
|
||||
|
@ -614,7 +616,8 @@ function edit.initialize_test_state()
|
|||
15, -- top margin
|
||||
Test_margin_left,
|
||||
App.screen.width - Test_margin_right,
|
||||
14, -- font height assuming default LÖVE font
|
||||
love.graphics.getFont(),
|
||||
14,
|
||||
15) -- line height
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
-- functions to render them into the log_render namespace.
|
||||
|
||||
function source.initialize_log_browser_side()
|
||||
Log_browser_state = edit.initialize_state(Margin_top, Editor_state.right + Margin_right + Margin_left, (Editor_state.right+Margin_right)*2, Editor_state.font_height, Editor_state.line_height)
|
||||
Log_browser_state = edit.initialize_state(Margin_top, Editor_state.right + Margin_right + Margin_left, (Editor_state.right+Margin_right)*2, Editor_state.font, Editor_state.font_height, Editor_state.line_height)
|
||||
Log_browser_state.filename = 'log'
|
||||
load_from_disk(Log_browser_state) -- TODO: pay no attention to Fold
|
||||
log_browser.parse(Log_browser_state)
|
||||
|
|
|
@ -190,8 +190,8 @@ There's much more I could include here; check out [the LÖVE manual](https://lov
|
|||
The text-editor widget includes extremely thorough automated tests to give you
|
||||
early warning if you break something.
|
||||
|
||||
* `state = edit.initialize_state(top, left, right, font_height, line_height)` --
|
||||
returns an object that can be used to render an interactive editor widget
|
||||
* `state = edit.initialize_state(top, left, right, font, font_height, line_height)`
|
||||
-- returns an object that can be used to render an interactive editor widget
|
||||
for text and line drawings starting at `y=top` on the app window, between
|
||||
`x=left` and `x=right`. Wraps long lines at word boundaries where possible,
|
||||
or in the middle of words (no hyphenation yet) when it must.
|
||||
|
|
8
run.lua
8
run.lua
|
@ -221,6 +221,7 @@ function print_and_log(s)
|
|||
end
|
||||
|
||||
function run.load_settings()
|
||||
local font = love.graphics.newFont(Settings.font_height)
|
||||
-- set up desired window dimensions and make window resizable
|
||||
_, _, App.screen.flags = App.screen.size()
|
||||
App.screen.flags.resizable = true
|
||||
|
@ -229,7 +230,7 @@ function run.load_settings()
|
|||
run.set_window_position_from_settings(Settings)
|
||||
Font_height = Settings.font_height
|
||||
Line_height = math.floor(Font_height*1.3)
|
||||
love.graphics.setFont(love.graphics.newFont(Font_height))
|
||||
love.graphics.setFont(font)
|
||||
end
|
||||
|
||||
function run.load_more_settings_from_notes_directory()
|
||||
|
@ -291,7 +292,7 @@ end
|
|||
|
||||
function load_pane(id)
|
||||
--? print('load pane from file', id)
|
||||
local result = edit.initialize_state(0, 0, math.min(Display_settings.column_width, App.screen.width-Margin_right), Font_height, Line_height)
|
||||
local result = edit.initialize_state(0, 0, math.min(Display_settings.column_width, App.screen.width-Margin_right), love.graphics.getFont(), Font_height, Line_height)
|
||||
result.id = id
|
||||
result.filename = Directory..id
|
||||
load_from_disk(result)
|
||||
|
@ -954,11 +955,12 @@ end
|
|||
function update_font_settings(font_height)
|
||||
local column_width_in_ems = Display_settings.column_width / App.width('m')
|
||||
Font_height = font_height
|
||||
love.graphics.setFont(love.graphics.newFont(Font_height))
|
||||
local font = love.graphics.newFont(Font_height)
|
||||
Line_height = math.floor(font_height*1.3)
|
||||
Display_settings.column_width = column_width_in_ems*App.width('m')
|
||||
for _,column in ipairs(Surface) do
|
||||
for _,pane in ipairs(column) do
|
||||
pane.font = font
|
||||
pane.font_height = Font_height
|
||||
pane.line_height = Line_height
|
||||
pane.left = 0
|
||||
|
|
10
source.lua
10
source.lua
|
@ -115,7 +115,7 @@ end
|
|||
|
||||
function source.load_settings()
|
||||
local settings = Settings.source
|
||||
love.graphics.setFont(love.graphics.newFont(settings.font_height))
|
||||
local font = love.graphics.newFont(settings.font_height)
|
||||
-- set up desired window dimensions and make window resizable
|
||||
_, _, App.screen.flags = App.screen.size()
|
||||
App.screen.flags.resizable = true
|
||||
|
@ -127,7 +127,7 @@ function source.load_settings()
|
|||
if Show_log_browser_side then
|
||||
right = App.screen.width/2 - Margin_right
|
||||
end
|
||||
Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), right, settings.font_height, math.floor(settings.font_height*1.3))
|
||||
Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), right, font, settings.font_height, math.floor(settings.font_height*1.3))
|
||||
Editor_state.filename = settings.filename
|
||||
Editor_state.filename = basename(Editor_state.filename) -- migrate settings that used full paths; we now support only relative paths within the app
|
||||
if settings.cursors then
|
||||
|
@ -153,12 +153,10 @@ end
|
|||
|
||||
function source.initialize_default_settings()
|
||||
local font_height = 20
|
||||
love.graphics.setFont(love.graphics.newFont(font_height))
|
||||
local font = love.graphics.newFont(font_height)
|
||||
source.initialize_window_geometry()
|
||||
Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), App.screen.width-Margin_right)
|
||||
Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), App.screen.width-Margin_right, font, font_height, math.floor(font_height*1.3))
|
||||
Editor_state.filename = 'run.lua'
|
||||
Editor_state.font_height = font_height
|
||||
Editor_state.line_height = math.floor(font_height*1.3)
|
||||
end
|
||||
|
||||
function source.initialize_window_geometry()
|
||||
|
|
|
@ -25,7 +25,7 @@ Same_point_distance = 4 -- pixel distance at which two points are considered th
|
|||
edit = {}
|
||||
|
||||
-- run in both tests and a real run
|
||||
function edit.initialize_state(top, left, right, font_height, line_height) -- currently always draws to bottom of screen
|
||||
function edit.initialize_state(top, left, right, font, font_height, line_height) -- currently always draws to bottom of screen
|
||||
local result = {
|
||||
-- a line is either text or a drawing
|
||||
-- a text is a table with:
|
||||
|
@ -85,6 +85,7 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
|
|||
current_drawing_mode = 'line',
|
||||
previous_drawing_mode = nil, -- extra state for some ephemeral modes like moving/deleting/naming points
|
||||
|
||||
font = font,
|
||||
font_height = font_height,
|
||||
line_height = line_height,
|
||||
|
||||
|
@ -105,7 +106,7 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
|
|||
search_backup = nil, -- stuff to restore when cancelling search
|
||||
}
|
||||
return result
|
||||
end -- App.initialize_state
|
||||
end -- edit.initialize_state
|
||||
|
||||
function edit.check_locs(State)
|
||||
-- if State is inconsistent (i.e. file changed by some other program),
|
||||
|
@ -157,6 +158,7 @@ end
|
|||
|
||||
function edit.draw(State, hide_cursor, show_line_numbers)
|
||||
State.button_handlers = {}
|
||||
love.graphics.setFont(State.font)
|
||||
App.color(Text_color)
|
||||
assert(#State.lines == #State.line_cache, ('line_cache is out of date; %d elements when it should be %d'):format(#State.line_cache, #State.lines))
|
||||
assert(Text.le1(State.screen_top1, State.cursor1), ('screen_top (line=%d,pos=%d) is below cursor (line=%d,pos=%d)'):format(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos))
|
||||
|
@ -552,7 +554,7 @@ end
|
|||
|
||||
function edit.update_font_settings(State, font_height)
|
||||
State.font_height = font_height
|
||||
love.graphics.setFont(love.graphics.newFont(State.font_height))
|
||||
State.font = love.graphics.newFont(State.font_height)
|
||||
State.line_height = math.floor(font_height*1.3)
|
||||
end
|
||||
|
||||
|
@ -569,7 +571,8 @@ function edit.initialize_test_state()
|
|||
15, -- top margin
|
||||
Test_margin_left,
|
||||
App.screen.width - Test_margin_right,
|
||||
14, -- font height assuming default LÖVE font
|
||||
love.graphics.getFont(),
|
||||
14,
|
||||
15) -- line height
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue