Merge lines-mobile.love
This commit is contained in:
commit
85cb87bdbe
|
@ -9,6 +9,9 @@
|
|||
|
||||
-- draw button and queue up event handlers
|
||||
function button(State, name, params)
|
||||
if State.button_handlers == nil then
|
||||
State.button_handlers = {}
|
||||
end
|
||||
if params.bg then
|
||||
love.graphics.setColor(params.bg.r, params.bg.g, params.bg.b, params.bg.a)
|
||||
love.graphics.rectangle('fill', params.x,params.y, params.w,params.h, 5,5)
|
||||
|
@ -19,6 +22,9 @@ end
|
|||
|
||||
-- process button event handlers
|
||||
function mouse_press_consumed_by_any_button(State, x, y, mouse_button)
|
||||
if State.button_handlers == nil then
|
||||
return
|
||||
end
|
||||
local button_pressed = false
|
||||
local consume_press = true
|
||||
for _,ev in ipairs(State.button_handlers) do
|
||||
|
|
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 = {
|
||||
-- a line is either text or a drawing
|
||||
-- a text is a table with:
|
||||
|
@ -83,6 +83,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,
|
||||
|
||||
|
@ -103,7 +104,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),
|
||||
|
@ -155,6 +156,7 @@ end
|
|||
|
||||
-- return y drawn until
|
||||
function edit.draw(State)
|
||||
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))
|
||||
|
@ -533,7 +535,7 @@ function edit.update_font_settings(State, font_height)
|
|||
Font_height = font_height
|
||||
Line_height = math.floor(Font_height*1.3)
|
||||
State.font_height = Font_height
|
||||
love.graphics.setFont(love.graphics.newFont(Font_height))
|
||||
State.font = love.graphics.newFont(Font_height)
|
||||
State.line_height = Line_height
|
||||
end
|
||||
|
||||
|
@ -550,7 +552,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)
|
||||
|
|
|
@ -166,8 +166,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.
|
||||
|
|
10
run.lua
10
run.lua
|
@ -83,8 +83,8 @@ end
|
|||
function run.load_settings()
|
||||
Font_height = Settings.font_height
|
||||
Line_height = math.floor(Font_height*1.3)
|
||||
love.graphics.setFont(love.graphics.newFont(Font_height))
|
||||
Editor_state = edit.initialize_state(Menu_bar_height + Margin_top, Margin_left, App.screen.width-Margin_right, Font_height, Line_height)
|
||||
local font = love.graphics.newFont(Font_height)
|
||||
Editor_state = edit.initialize_state(Menu_bar_height + Margin_top, Margin_left, App.screen.width-Margin_right, font, Font_height, Line_height)
|
||||
Editor_state.filename = Settings.filename
|
||||
Editor_state.screen_top1 = Settings.screen_top
|
||||
Editor_state.cursor1 = Settings.cursor
|
||||
|
@ -94,10 +94,8 @@ function run.initialize_default_settings()
|
|||
Font_height = 20
|
||||
Line_height = math.floor(Font_height*1.3)
|
||||
Menu_bar_height = 5 + Line_height + 5
|
||||
love.graphics.setFont(love.graphics.newFont(Font_height))
|
||||
Editor_state = edit.initialize_state(Menu_bar_height + Margin_top, Margin_left, App.screen.width-Margin_right)
|
||||
Editor_state.font_height = Font_height
|
||||
Editor_state.line_height = Line_height
|
||||
local font = love.graphics.newFont(Font_height)
|
||||
Editor_state = edit.initialize_state(Menu_bar_height + Margin_top, Margin_left, App.screen.width-Margin_right, font, Font_height, Line_height)
|
||||
Settings = run.settings()
|
||||
end
|
||||
|
||||
|
|
|
@ -117,13 +117,13 @@ 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)
|
||||
Show_log_browser_side = settings.show_log_browser_side
|
||||
local right = App.screen.width - Margin_right
|
||||
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
|
||||
|
@ -139,11 +139,9 @@ 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)
|
||||
Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), App.screen.width-Margin_right)
|
||||
Editor_state.filename = 'run.lua'
|
||||
Editor_state.font_height = font_height
|
||||
Editor_state.line_height = math.floor(font_height*1.3)
|
||||
end
|
||||
|
||||
-- a copy of source.file_drop when given a filename
|
||||
|
|
|
@ -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