Merge luaML.love

This commit is contained in:
Kartik K. Agaram 2023-07-10 19:28:39 -07:00
commit 936c0228ec
3 changed files with 42 additions and 42 deletions

View File

@ -1,6 +1,4 @@
on.load_settings = function(settings)
if settings then
Settings = settings
end
Settings = settings
-- we don't know the Filename yet, so do nothing else
end

View File

@ -36,8 +36,6 @@ function App.initialize_globals()
-- blinking cursor
Cursor_time = 0
Font_height = 20
-- for hysteresis in a few places
Current_time = 0
Last_focus_time = 0 -- https://love2d.org/forums/viewtopic.php?p=249700
@ -55,7 +53,11 @@ function App.initialize(arg)
live.initialize(arg)
load_settings()
if love.filesystem.getInfo('config') then
load_settings()
else
initialize_default_settings()
end
@ -100,42 +102,46 @@ function settings()
end
function load_settings()
if love.filesystem.getInfo('config') then
local settings = json.decode(love.filesystem.read('config'))
local width, height, flags = App.screen.size()
flags.resizable = true
flags.minwidth = math.min(width, 200)
flags.minheight = math.min(height, 200)
App.screen.flags = flags
App.screen.width = settings.width
App.screen.height = settings.height
App.screen.resize(App.screen.width, App.screen.height, App.screen.flags)
App.screen.move(settings.x, settings.y, settings.displayindex)
if on.load_settings then on.load_settings(settings.app) end
local settings = json.decode(love.filesystem.read('config'))
_, _, App.screen.flags = App.screen.size()
App.screen.flags.resizable = true
App.screen.width, App.screen.height = settings.width, settings.height
App.screen.resize(App.screen.width, App.screen.height, App.screen.flags)
set_window_position_from_settings(settings)
if on.load_settings then on.load_settings(settings.app) end
end
function set_window_position_from_settings(settings)
local os = love.system.getOS()
if os == 'Linux' then
-- love.window.setPosition doesn't quite seem to do what is asked of it on Linux.
App.screen.move(settings.x, settings.y-37, settings.displayindex)
else
Font_height = 20
love.graphics.setFont(love.graphics.newFont(Font_height))
local os = love.system.getOS()
if os == 'Android' or os == 'iOS' then
-- maximizing on iOS breaks text rendering: https://github.com/deltadaedalus/vudu/issues/7
-- no point second-guessing window dimensions on mobile
App.screen.width, App.screen.height, App.screen.flags = App.screen.size()
else
-- maximize window
App.screen.resize(0, 0) -- maximize
App.screen.width, App.screen.height, App.screen.flags = App.screen.size()
-- shrink height slightly to account for window decoration
App.screen.height = App.screen.height-100
App.screen.width = 40*App.width('m')
App.screen.flags.resizable = true
App.screen.flags.minwidth = math.min(App.screen.width, 200)
App.screen.flags.minheight = math.min(App.screen.height, 200)
App.screen.resize(App.screen.width, App.screen.height, App.screen.flags)
end
if on.load_settings then on.load_settings() end
App.screen.move(settings.x, settings.y, settings.displayindex)
end
end
function initialize_default_settings()
local font_height = 20
love.graphics.setFont(love.graphics.newFont(font_height))
initialize_window_geometry(App.width('m'))
end
function initialize_window_geometry(em_width)
-- Initialize window width/height and make window resizable.
--
-- I get tempted to have opinions about window dimensions here, but they're
-- non-portable:
-- - maximizing doesn't work on mobile and messes things up
-- - maximizing keeps the title bar on screen in Linux, but off screen on
-- Windows. And there's no way to get the height of the title bar.
-- It seems more robust to just follow LÖVE's default window size until
-- someone overrides it.
App.screen.width, App.screen.height, App.screen.flags = App.screen.size()
App.screen.flags.resizable = true
App.screen.resize(App.screen.width, App.screen.height, App.screen.flags)
end
function App.resize(w, h)
--? print(("Window resized to width: %d and height: %d."):format(w, h))
App.screen.width, App.screen.height = w, h

View File

@ -24,10 +24,6 @@ two categories.
* `flags` -- some properties of the app window. See [`flags` in `love.graphics.getMode`](https://love2d.org/wiki/love.window.getMode)
for details.
* `Font_height` -- remembers the current font height on initialization. But
you're responsible for setting it when updating font height. (Think of this
as the body font, but apps so far assume a single font size.)
## Functions you can implement that will get automatically called
* `on.initialize(arg)` -- called when app starts up. Provides in `arg` an