Loveframes Text:GetLines()

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
riidom
Citizen
Posts: 74
Joined: Wed Jun 19, 2013 4:28 pm
Location: irgendwo an der Elbe
Contact:

Loveframes Text:GetLines()

Post by riidom »

Hi, I have a problem with the GetLines() function from the text object. It returns always nil.

Code: Select all

function Node:initialize(px, py, pw, ph)
	
  local SliW = 5 -- width of slider buttons
  local MinW = 50 -- minimum width of whole node
	
  -- Init of base and sub-elements
  local base = loveframes.Create("panel")
  base:SetPos(px, py):SetSize(pw, ph)
  base:SetProperty("RightEdgeX", px + pw)
  --
  local text = loveframes.Create("text", base)
  text:SetPos(SliW + 1, 0):SetSize(pw - (SliW + 1) * 2, ph):SetMaxWidth(pw - (SliW + 1) * 2)
  text:SetText("Objects (blablabla)")

  --more stuff

  -- update pos&size of all elements after resizing the base and having new amount of lines
  function base:Update(dt)
    --print(text:GetLines())
    local h
    if text:GetLines() then h = text:GetLines() * 10 else h = base:GetHeight() end
    local x, y, w = base:GetX(), base:GetY(), base:GetWidth()
    base:SetHeight(h)
    leftResizer:SetHeight(h)
    rightResizer:SetX(w - SliW):SetHeight(h)
		
    --text:SetPos(SliW + 1, 0):SetSize(w - (SliW + 1) * 2, h):SetMaxWidth(w - (SliW + 1) * 2)
    text:SetPos(SliW + 1, 0):SetMaxWidth(w - (SliW + 1) * 2)
  end
end
this results in Image, to not get an error I checked for nil and instead use the default height.

So am I using GetLines somehow wrong? Here is the full code in a .love if anybody is interested (per se not interesting yet, it's pretty much a stub, I would like to solve this problem first, before I go on) What you can do, is grabbing the left and right borders of the nodes and change the width by dragging.
comap.love
(984.78 KiB) Downloaded 118 times
User avatar
artofwork
Citizen
Posts: 91
Joined: Mon Sep 15, 2014 1:17 am
Location: East Coast USA

Re: Loveframes Text:GetLines()

Post by artofwork »

Well I don't know much about this library but i do know that GetLines() in text.lua will always return nil because self.lines doesn't exist anywhere in the object creation other then inside GetLines().

line 667 of LoveFrames/objects/text.lua

Code: Select all

function newobject:GetLines()

	return self.lines
	
end
there is a local lines inside of SetText() but its never used

on line 373 of LoveFrames/objects/text.lua

Code: Select all

	local lines = 0
User avatar
riidom
Citizen
Posts: 74
Joined: Wed Jun 19, 2013 4:28 pm
Location: irgendwo an der Elbe
Contact:

Re: Loveframes Text:GetLines()

Post by riidom »

Oh well, thanks for looking in the source, I could have get the idea to do so myself :)
It seems to be very recent and not fully done, on top of file it says:

Code: Select all

-- note: the text wrapping of this object is experimental and not final
Good there is a lot of other stuff for me to add as well in meantime.
User avatar
Nikolai Resokav
Party member
Posts: 140
Joined: Wed Apr 28, 2010 12:51 am
Location: United States

Re: Loveframes Text:GetLines()

Post by Nikolai Resokav »

User avatar
riidom
Citizen
Posts: 74
Joined: Wed Jun 19, 2013 4:28 pm
Location: irgendwo an der Elbe
Contact:

Re: Loveframes Text:GetLines()

Post by riidom »

Thanks for the quick fix, works like a charm!
Post Reply

Who is online

Users browsing this forum: No registered users and 139 guests