Skip to content

Conversation

thethethetheraven
Copy link

this implements Font:getGlyphPosition as outlined in issue #1021.

@thethethetheraven
Copy link
Author

demo:

local utf8 = require "utf8"

local text = "hello, this is a program that uses Font:getGlyphPosition()."
local font = love.graphics.newFont(30)

local i = 1

function love.load()
	love.keyboard.setKeyRepeat(true)
end

function love.keypressed(k)
	if k == "right" then
		i = i + 1
	elseif k == "left" then
		i = i - 1
	end
	i = math.max(math.min(i, utf8.len(text)), 1)
end

function love.draw()
	love.graphics.setFont(font)
	love.graphics.setColor(0.8, 0.5, 0.8)
	love.graphics.rectangle("fill", font:getGlyphPosition(i, text, 400))
	love.graphics.setColor(1, 1, 1)
	love.graphics.printf(text, 0, 0, 400)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant