Elements whose sizes are 0 get the wrong position

Hi!

Elements whose sizes are 0 get the wrong position by about 10 pixels. I am using invisible elements of size 0 as containers. I tried to position one of them at the top of the screen, at position y = 0, but noticed I was not seeing the top 10 pixels of it’s contents. But as soon as I changed the size of the container to (20, 20) or something, it was positioned correctly.

Wasn’t there some trick that sizes/positions between 0 and 1 meant relative position 0-100% and in different direction on top of that?

@abies said: Wasn't there some trick that sizes/positions between 0 and 1 meant relative position 0-100% and in different direction on top of that?

Yes I saw that but I don’t think that has anything to do with it.

@tuffe said: Hi!

Elements whose sizes are 0 get the wrong position by about 10 pixels. I am using invisible elements of size 0 as containers. I tried to position one of them at the top of the screen, at position y = 0, but noticed I was not seeing the top 10 pixels of it’s contents. But as soon as I changed the size of the container to (20, 20) or something, it was positioned correctly.

Don’t do this…

use:

[java]
el.setAsContainerOnly();
[/java]

It removes the render component and leaves all the functionality… including a size. You can also do this:

[java]
Element el = ControlUtil.getContainer(screen);
// Add a bunch of stuff
el.sizeToContent();
[/java]

Which will set the container size to the outer most bounds of all child elements, in case you need to know the dimensions.

@t0neg0d I did .setAsContainerOnly() but also size (0, 0). While it’s true that I don’t need to have size (0, 0) when I have used setAsContainerOnly, it is still a bug. I shouldn’t have to know that.

To help see the problem: Above you can see a small grey, partically obscured, box behind each of the 4 inventories, in the top left corner of them. Those are the containers. On the left screen shot I set containers’ size to (0, 0), but the containers actually become like (10, 10). Then because the position is recalculated from 0 to (screenHeight - size), or whatever, and size is 0, and because the position is actually the bottom of the box that is not 0 but is supposed to be, the position is wrong. :stuck_out_tongue:

@t0neg0d It seems that somewhere the dimensions are set to (10, 10) if they are smaller than that. That means everything smaller than (10, 10) will get the wrong position.

@t0neg0d I used .setMinDimensions instead to set the min dimensions to (0, 0), and now everything is fine. Kind of makes me question why there is a minDimensions when it seems to cause problems but, at least as far as I can see, give no benefits whatsoever.

@tuffe said: @t0neg0d I used .setMinDimensions instead to set the min dimensions to (0, 0), and now everything is fine. Kind of makes me question why there is a minDimensions when it seems to cause problems but, at least as far as I can see, give no benefits whatsoever.

This was a placeholder until I was able to implement Layouts. It only served the purpose of stopping resize from going below minimum dimensions.

@t0neg0d said: This was a placeholder until I was able to implement Layouts. It only served the purpose of stopping resize from going below minimum dimensions.
Oh I see! But then you should only use it when taking care of resizes, because otherwise there is this hidden number that will mess with people who try to make small stuff.
@tuffe said: Oh I see! But then you should only use it when taking care of resizes, because otherwise there is this hidden number that will mess with people who try to make small stuff.

I’ll look into this. There was a reason it defaulted to 10x10… Oh… I believe it was supposed to be set the resize borders of the element… and this was a placeholder. I’ll update this to use the resize borders, however… this will require you create these tiny elements using the constructor that allows you to define the resize border. It’s the only way I can think of that this won’t disrupt the resize.

However, if these containers are not using a visual component, I would suggest using the ControlUtil moethod I posted above. This is all taken care of for you at that point.