Merge template-live-editor-mobile
This commit is contained in:
commit
c1bc2b9616
|
@ -3,7 +3,7 @@ output_editor_state = function(editor_state)
|
||||||
editor_state.bottom+5+10+5, -- top
|
editor_state.bottom+5+10+5, -- top
|
||||||
nil, -- buttom
|
nil, -- buttom
|
||||||
editor_state.left, editor_state.right,
|
editor_state.left, editor_state.right,
|
||||||
Font_height, Line_height)
|
Font, Font_height, Line_height)
|
||||||
Text.redraw_all(result)
|
Text.redraw_all(result)
|
||||||
return result
|
return result
|
||||||
end
|
end
|
|
@ -4,7 +4,7 @@ code_editor_state = function()
|
||||||
Safe_height/2-Line_height, -- bottom
|
Safe_height/2-Line_height, -- bottom
|
||||||
Menu_left + 50 + Line_number_padding, -- left
|
Menu_left + 50 + Line_number_padding, -- left
|
||||||
math.min(100+30*App.width('m'), Safe_width*2/3), -- right
|
math.min(100+30*App.width('m'), Safe_width*2/3), -- right
|
||||||
Font_height, Line_height)
|
Font, Font_height, Line_height)
|
||||||
Text.redraw_all(result)
|
Text.redraw_all(result)
|
||||||
return result
|
return result
|
||||||
end
|
end
|
11
edit.lua
11
edit.lua
|
@ -18,7 +18,7 @@ require 'colorize'
|
||||||
edit = {}
|
edit = {}
|
||||||
|
|
||||||
-- run in both tests and a real run
|
-- run in both tests and a real run
|
||||||
function edit.initialize_state(top, bottom, left, right, font_height, line_height)
|
function edit.initialize_state(top, bottom, left, right, font, font_height, line_height)
|
||||||
local result = {
|
local result = {
|
||||||
lines = {{data=''}}, -- array of strings
|
lines = {{data=''}}, -- array of strings
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ function edit.initialize_state(top, bottom, left, right, font_height, line_heigh
|
||||||
cursor_x = 0,
|
cursor_x = 0,
|
||||||
cursor_y = 0,
|
cursor_y = 0,
|
||||||
|
|
||||||
|
font = font,
|
||||||
font_height = font_height,
|
font_height = font_height,
|
||||||
line_height = line_height,
|
line_height = line_height,
|
||||||
|
|
||||||
|
@ -77,7 +78,7 @@ function edit.initialize_state(top, bottom, left, right, font_height, line_heigh
|
||||||
search_backup = nil, -- stuff to restore when cancelling search
|
search_backup = nil, -- stuff to restore when cancelling search
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
end -- App.initialize_state
|
end -- edit.initialize_state
|
||||||
|
|
||||||
function edit.check_locs(State)
|
function edit.check_locs(State)
|
||||||
-- if State is inconsistent (i.e. file changed by some other program),
|
-- if State is inconsistent (i.e. file changed by some other program),
|
||||||
|
@ -109,6 +110,7 @@ end
|
||||||
|
|
||||||
-- return y drawn until
|
-- return y drawn until
|
||||||
function edit.draw(State, fg, hide_cursor, show_line_numbers)
|
function edit.draw(State, fg, hide_cursor, show_line_numbers)
|
||||||
|
love.graphics.setFont(State.font)
|
||||||
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(#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
|
State.cursor_x = nil
|
||||||
State.cursor_y = nil
|
State.cursor_y = nil
|
||||||
|
@ -408,7 +410,7 @@ end
|
||||||
|
|
||||||
function edit.update_font_settings(State, font_height)
|
function edit.update_font_settings(State, font_height)
|
||||||
State.font_height = 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)
|
State.line_height = math.floor(font_height*1.3)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -426,7 +428,8 @@ function edit.initialize_test_state()
|
||||||
nil, -- to bottom of screen
|
nil, -- to bottom of screen
|
||||||
Test_margin_left,
|
Test_margin_left,
|
||||||
App.screen.width - Test_margin_right,
|
App.screen.width - Test_margin_right,
|
||||||
14, -- font height assuming default LÖVE font
|
love.graphics.getFont(),
|
||||||
|
14,
|
||||||
15) -- line height
|
15) -- line height
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
1
main.lua
1
main.lua
|
@ -109,6 +109,7 @@ end
|
||||||
|
|
||||||
function load_settings()
|
function load_settings()
|
||||||
local settings = json.decode(love.filesystem.read('config'))
|
local settings = json.decode(love.filesystem.read('config'))
|
||||||
|
-- set up desired window dimensions and make window resizable
|
||||||
_, _, App.screen.flags = App.screen.size()
|
_, _, App.screen.flags = App.screen.size()
|
||||||
App.screen.flags.resizable = true
|
App.screen.flags.resizable = true
|
||||||
App.screen.width, App.screen.height = settings.width, settings.height
|
App.screen.width, App.screen.height = settings.width, settings.height
|
||||||
|
|
|
@ -214,8 +214,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
|
The text-editor widget includes extremely thorough automated tests to give you
|
||||||
early warning if you break something.
|
early warning if you break something.
|
||||||
|
|
||||||
* `state = edit.initialize_state(top, left, right, font_height, line_height)` --
|
* `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
|
-- returns an object that can be used to render an interactive editor widget
|
||||||
for text starting at `y=top` on the app window, between `x=left` and
|
for text 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
|
`x=right`. Wraps long lines at word boundaries where possible, or in the
|
||||||
middle of words (no hyphenation yet) when it must.
|
middle of words (no hyphenation yet) when it must.
|
||||||
|
|
Loading…
Reference in New Issue