Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Question on GridBagLayout system — Gideros Forum

Question on GridBagLayout system

Hi Guys!
I am playing with the new Sprite layout system. Just simple test is trying to a layout center of a button to the top right of a dialog background
local bkg = Pixel.new(0x338899,1,300, 300)
stage:addChild(bkg)
bkg:setPosition(200, 200)
bkg:setLayoutParameters({
	columnWeights = {1,1,1},
	rowWeights = {1,1,1}
	})
local btn_close = Pixel.new(0x223344,1,200, 200)
 
btn_close:setLayoutConstraints({
	anchor = Sprite.LAYOUT_ANCHOR_NORTHEAST,
	gridwidth = 1,
	gridheight = 1,
	gridx = 2,
	gridy= 0,
	--insetTop = -100,
	insetRight=-100,
 
	})	
bkg:addChild(btn_close)
I think insetTop is not working. If we uncomment it, the button goes away.
Is there other way using GridBagLayout to get this layout works?
Well, we can easily make it work by calculating the position and then using setPosition. But I need to learn GridBagLayout system to make some dynamic UI layout in near future.
Thanks

Likes: Apollo14

Coming soon
+1 -1 (+1 / -0 )Share on Facebook

Comments

  • Is this the native implementation of Layout class? Vitalitymobile I'm sorry it's not an answer.. :)
  • hgy29hgy29 Maintainer
    Accepted Answer
    insets are expected to be positive values, I suppose that's why it doesn't work for you. However you can trick gideros into doing what you want by changing anchor point of your child sprite and leaving insets at 0:
    btn_close:setAnchorPoint(-0.5,0.5)
    +1 -1 (+1 / -0 )Share on Facebook
  • @hgy29 Cool! setAnchorPoint works.
    If insets are expected to be positive values, then how we can move btn_close some dx and dy outside the bkg (This time not exact haft width and haft height)?
    Coming soon
  • hgy29hgy29 Maintainer
    Well you can't, layout system was meant to place objects strictly inside parent sprite area. But you can take your problem differently: let gideros layout your background and button inside a transparent container. Take a look below:
    local container=Pixel.new(0,0,400,400) --Hollow container
    stage:addChild(container)
    container:setPosition(200, 200)
    container:setLayoutParameters({
    	columnWeights = {1,0,0},
    	rowWeights = {0,0,1},
    	columnWidths={0,100,100},
    	rowHeights={100,100,0},
    	})
    local bkg = Pixel.new(0x338899,1) -- Don't give explict size, layout system will grow it
    local btn_close = Pixel.new(0x223344,1) -- Same as above, fixed column and row sizes will define its size
     
    bkg:setLayoutConstraints({
    	gridwidth = 2,
    	gridheight = 2,
    	gridx = 0,
    	gridy= 1,
    	fill=Sprite.LAYOUT_FILL_BOTH
    	})	
    btn_close:setLayoutConstraints({
    	gridwidth = 2,
    	gridheight = 2,
    	gridx = 1,
    	gridy= 0,
    	fill=Sprite.LAYOUT_FILL_BOTH
    	})	
    container:addChild(bkg)
    container:addChild(btn_close)
    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.