diff options
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/main.lua b/main.lua index cd515ec..7f39cb5 100644 --- a/main.lua +++ b/main.lua @@ -14,7 +14,7 @@ Editor_state = {} -- called both in tests and real run function App.initialize_globals() - Editor_state = edit.initialize_state() + -- tests currently mostly clear their own state -- resize Last_resize_time = nil @@ -33,7 +33,7 @@ function App.initialize(arg) if love.filesystem.getInfo('config') then load_settings() else - load_defaults() + initialize_default_settings() end if #arg > 0 then @@ -60,9 +60,6 @@ function App.initialize(arg) end love.window.setTitle('lines.love - '..Editor_state.filename) - Editor_state.margin_right = 25 - Editor_state.margin_width = Editor_state.margin_left + Editor_state.margin_right - if #arg > 1 then print('ignoring commandline args after '..arg[1]) end @@ -86,24 +83,34 @@ function load_settings() App.screen.flags.minheight = math.min(App.screen.width, 200) App.screen.width, App.screen.height = settings.width, settings.height love.window.setMode(App.screen.width, App.screen.height, App.screen.flags) + Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right) Editor_state.filename = settings.filename - initialize_font_settings(settings.font_height) + Editor_state.font_height = settings.font_height + love.graphics.setFont(love.graphics.newFont(Editor_state.font_height)) + Editor_state.line_height = math.floor(Editor_state.font_height*1.3) + Editor_state.em = App.newText(love.graphics.getFont(), 'm') Editor_state.screen_top1 = settings.screen_top Editor_state.cursor1 = settings.cursor end -function load_defaults() - initialize_font_settings(20) - initialize_window_geometry() +function initialize_default_settings() + local font_height = 20 + love.graphics.setFont(love.graphics.newFont(font_height)) + local em = App.newText(love.graphics.getFont(), 'm') + initialize_window_geometry(App.width(em)) + Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right) + Editor_state.font_height = font_height + Editor_state.line_height = math.floor(font_height*1.3) + Editor_state.em = em end -function initialize_window_geometry() +function initialize_window_geometry(em_width) -- maximize window love.window.setMode(0, 0) -- maximize App.screen.width, App.screen.height, App.screen.flags = love.window.getMode() - -- shrink slightly to account for window decoration - App.screen.width = 40*App.width(Editor_state.em) + -- shrink height slightly to account for window decoration App.screen.height = App.screen.height-100 + App.screen.width = 40*em_width App.screen.flags.resizable = true App.screen.flags.minwidth = math.min(App.screen.width, 200) App.screen.flags.minheight = math.min(App.screen.width, 200) @@ -115,18 +122,10 @@ function App.resize(w, h) App.screen.width, App.screen.height = w, h Text.redraw_all(Editor_state) Editor_state.selection1 = {} -- no support for shift drag while we're resizing - Text.tweak_screen_top_and_cursor(Editor_state, Editor_state.margin_left, App.screen.height-Editor_state.margin_right) + Text.tweak_screen_top_and_cursor(Editor_state, Editor_state.left, Editor_state.right) Last_resize_time = App.getTime() end -function initialize_font_settings(font_height) - Editor_state.font_height = font_height - love.graphics.setFont(love.graphics.newFont(Editor_state.font_height)) - Editor_state.line_height = math.floor(font_height*1.3) - - Editor_state.em = App.newText(love.graphics.getFont(), 'm') -end - function App.filedropped(file) -- first make sure to save edits on any existing file if Editor_state.next_save then |