Hi,
I try to reposition an image to be centerd.
The image is set to be width:75% and height:75%
but then, to make it square, i change the width so it’s the same amount of pixels as the height is.
Then I have to set the position, which is just centerd, no absolute is used in the xml.
But setting the position like this has no effect on the image…
[java]e.setConstraintX(new SizeValue(“1px”)); //MainGame.getWidth()/2+(w-h)+
e.getParent().layoutElements();[/java]
Does it have to do with the image being just “center”?
You mean the parent layout is center?
Yes - in that case it will always just center the contents.
You can do this much more simply though. Just set width:75% and don’t set height at all. It should then automatically adjust height to keep the aspect ratio constant, and then the center layout will position the image.
That sounds really like the thing I’m looking for
Only problem is it doesn’t work…
Is that some new invention?
Because I use the nightlybuild from 04/28 -2012 and if I don’t set the height, then the image will be very stretched…
My full xml is here:
[xml]<?xml version=“1.0” encoding=“UTF-8”?>
<nifty>
<screen id=“Maps” controller=“input.MenuListener”>
<layer childLayout=“vertical”>
<image filename=“MapsBackground.png” width=“100%” height=“100%” childLayout=“center”>
<image id=“MapImage” filename=“LakesideRest.png” width=“75%” childLayout=“center”>
<effect>
<onStartScreen name=“fade” end="#ff" start="#00" />
<onEndScreen name=“move” timeType=“exp” factor=“3.5” direction=“left” mode=“out” length=“300” inherit=“true” />
</effect>
<control align=“left”>
<interact onClick=“mapSelected(Lakeside Rest)” />
</control>
</image>
</image>
</layer>
</screen>
</nifty>
[/xml]
This is how you ment it right?
Yeah, I would expect that to work - although I mostly use panels with backgroundImage set rather than images directly. I don’t know if that makes a difference. Maybe I’m mis-remembering how Image resizing works as it’s not something I’ve really used much. I’m thought I remembered that it defaults to keeping aspect ratio but maybe it just defaults to using actual Image height in pixels.
Ahh yea, if you don’t write height nor width THEN it will be normal size
Would’ve been awsome if it keept the aspect ratio on it if only one was filled in… Maybe I could help to add that to nifty?
Ohwell… Thanks for the help anyways!
Very much appriciated
@Void256 is the main man for Nifty and is pretty open to patches in my experience (had no trouble getting a few applied myself) so I expect you could…although changing default behaviour I expect would be an issue so this might need to be made optional somehow.