Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
setLayout syntax do not work — Gideros Forum

setLayout syntax do not work

Hello guys! Need your help with regards to setLayout implementation. Please see the image to check what's wrong to my code.image
Tagged:

Comments

  • I have no errors. Try to close "console.lua" file and refresh project files (by right clicking on "Files" in project files section and hit "Refresh"). Open "console.lua" again and check if something changed.
  • MoKaLuxMoKaLux Member
    edited December 2019
    according to this example your code looks right:
    -- then we set the layout: width, height, line spacing and justify center
    textfield:setLayout( {w=200, h=100, lineSpacing=7, flags=FontBase.TLF_CENTER} )
    https://wiki.giderosmobile.com/index.php/TextField:setLayout
    Available since: Gideros 2017.10

    @koeosstudio can you copy/paste your code please?
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • @rrraptor just wanna ask if tried my code above? Maybe my version of gideros is issue.
  • @MoKaLux I will try your example. Will update the result in a moment :smile:
  • @MoKaLux @rrraptor Heres my code. My gideros version is 2019.5
    console = Core.class(Sprite)
     
    function console:init()
    	local fnt = TTFont.new("Assets/cour.ttf", 47)
    	self.txt = TextField.new(fnt, nil)
    	self.txt:setPosition(50, 50)
    	self.txt:setLayout({w=200, h=100, lineSpacing=7, flags=FontBase.TLF_LEFT})
    	self:addChild(self.txt)
    	self.allowType = true
    end
  • MoKaLuxMoKaLux Member
    edited December 2019
    I tried your code I had no errors but there was no text.
    To have some text you need to change your code a little bit:
    console = Core.class(Sprite)
    function console:init(sometext)
    	local fnt = TTFont.new("Assets/arial.ttf", 47)
    	self.txt = TextField.new(fnt, sometext)
    	self.txt:setPosition(50, 50)
    	self.txt:setLayout({w=200, h=100, lineSpacing=7, flags=FontBase.TLF_LEFT})
    	self:addChild(self.txt)
    	self.allowType = true
    end
     
    local myconsole = console.new("this is a sample text.")
    stage:addChild(myconsole)
    PS: I changed font to arial because I did not have cour.ttf
    PS2: gideros 2019.10
    PS3: if you don't understand some part just ask us :)

    Likes: plicatibu

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • koeosstudiokoeosstudio Member
    edited December 2019
    Thank you very much for the great answers. Fixed it by creating a new project and copy pasting the exact same code. It's a bit strange but nevermind. :D :D
    By the way, here's my final code : a simple Texfield with typwriter effect and basic scroll function.
    console = Core.class(Sprite)
     
    function console:init()
    	local fnt = TTFont.new("Assets/cour.ttf", 20)
    	self.txt = TextField.new(fnt, nil)
    	self.txt:setLayout({w = 300, flags=FontBase.TLF_LEFT})
    	self.txt:setAnchorPoint(0, 0)
    	self:addChild(self.txt)
    	self.allowType = true
     
    	-- Simple scroll function
    	local z = nil
     
    	self:addEventListener(Event.MOUSE_DOWN, function (event)
    		z = event.y - self.txt:getY()
    	end)
    	self:addEventListener(Event.MOUSE_MOVE, function (event)
    		self.txt:setY(event.y - z)
    	end)
    end 
     
    function console:tWrite(txtToPrint)
    	if self.allowType then
    		self.allowType = false
    		local i = 1
    		self.txt:setText(self.txt:getText()..'\n')
     
    		local function typeFunc()
    			self.txt:setText(self.txt:getText()..string.sub(txtToPrint, i, i))
    			i = i + 1
     
    			if i > string.len(txtToPrint) then
    				self.allowType = true
    				self:removeEventListener(Event.ENTER_FRAME, typeFunc)
    			end
    		end
     
    		self:addEventListener(Event.ENTER_FRAME, typeFunc)
    	end
    end
     
     
    -- Test 
     
    application:setLogicalDimensions(480, 800)
    local myconsole = console.new(1)
    stage:addChild(myconsole)
     
    -- Generate sample txt 
    	local s = ""
    	for i = 1, 10 do
    	s = s.."TextField with typewriter effect. Drag to Scroll.\n\n"
    	end
     
    -- Print
    myconsole:tWrite(s)

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • @koeosstudio super cool snipet, thank you for sharing :)
    Can I add it to gideros wiki please?
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • MoKaLuxMoKaLux Member
    edited November 2023

    Likes: koeosstudio

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.