Browse Source

Fix font loading when lib is in nested directory

Thanks to Jost Grant
John Dodis 1 year ago
parent
commit
5444687625
3 changed files with 5 additions and 2 deletions
  1. 0 0
      lovrlogo.png
  2. 1 1
      main.lua
  3. 4 1
      ui2d/ui2d.lua

+ 0 - 0
ui2d/lovrlogo.png → lovrlogo.png


+ 1 - 1
main.lua

@@ -7,7 +7,7 @@ local sl1 = 20
 local sl2 = 10
 local sl3 = 10.3
 local txt = "sample text"
-local icon = lovr.graphics.newTexture( "ui2d/lovrlogo.png" )
+local icon = lovr.graphics.newTexture( "lovrlogo.png" )
 local tab_bar_idx = 1
 local check1 = true
 local check2 = false

+ 4 - 1
ui2d/ui2d.lua

@@ -344,7 +344,10 @@ end
 --                                User                                        --
 -- -------------------------------------------------------------------------- --
 function UI2D.Init( size )
-	font.handle = lovr.graphics.newFont( "ui2d/" .. "DejaVuSansMono.ttf", size or 14, 4 )
+	local info = debug.getinfo( 1, "S" )
+	local lib_path = info.source:match( "@(.*[\\/])" )
+
+	font.handle = lovr.graphics.newFont( lib_path .. "DejaVuSansMono.ttf", size or 14, 4 )
 	font.handle:setPixelDensity( 1.0 )
 	font.h = font.handle:getHeight()
 	font.w = font.handle:getWidth( "W" )