zorg wrote:
Only other thing would be that obj.text was not set, since that's the only line i didn't see in the first post's code block.
ye I could it's declared elsewhere, I'll put that code below, just didn't include it cause it was kind of irrelevant but here you go
Code: Select all
local boxButton = {} --text, x, y, r, scaleX, scaleY, onClickEvent, onHoverEvent, offHoverEvent, color
local function boxButtonToggleFollow(obj)
obj.isFollowing = not obj.isFollowing
return obj
end
local function boxButtonClickEvent(obj)
local obj = obj.toggleFollow(obj) or obj
return obj
end
local function boxButtonOnHoverEvent(obj)
if obj.isFollowing then return obj end
obj.color = {0,255,0}
return obj
end
local function boxButtonOffHoverEvent(obj)
if obj.isFollowing then return obj end
obj.color = {255,0,255}
return obj
end
local function boxButtonDestroy()
UserInterface:destroyObj("NicksButtonTest")
end
local function boxButtonUpdate(dt, obj)
obj.w = obj.font:getWidth(obj.text)
obj.h = obj.font:getHeight(obj.text)
obj.text = obj.text
if obj.isFollowing then
obj.x = love.mouse.getX() - obj.w/2
obj.y = love.mouse.getY() - obj.h/2
obj.color = {255,255,255}
end
return obj
end
boxButton.isFollowing = false
boxButton.ident = "NicksButtonTest"
boxButton.text = "Testing The Fucking Function"
boxButton.x = 10
boxButton.y = 10
boxButton.w = 0
boxButton.h = 0
boxButton.r = 0
boxButton.scaleX = 1
boxButton.scaleY = 1
boxButton.color = {255,0,255}
boxButton.popout = false
boxButton.popoutX = 0
boxButton.popoutY = 0
boxButton.font = love.graphics.newFont("gfx/MenuFont.ttf", 32)
boxButton.onClickEvent = boxButtonClickEvent
boxButton.onHoverEvent = boxButtonOnHoverEvent
boxButton.offHoverEvent = boxButtonOffHoverEvent
boxButton.destroy = boxButtonDestroy
boxButton.update = boxButtonUpdate
boxButton.toggleFollow = boxButtonToggleFollow
UserInterface:addTextButton(boxButton)
Edit: I've made quite a few workarounds and if you notice in boxButtonUpdate() it's setting the w and h of the text, so that's a workout but I'm still curious as to why it didn't work before, it's almost identical code but works now? it's weird xD