Hello, getBounds() always return Rectangle<int>, even if component was defined by floats, like that: myComboBox.setBounds(0.5f, 0.05f, 10.5f, 10.5f);
Of course there is method Rectangle<int>::toFloat() but it rounds the coordinates and size.
Why is that? Do I need to write my own class to handle that?
I mean class that stores float values of fX=0.5f, fY=0.5f etc. Because getX(), getY() etc. also always gives me int value.
Or is there any solution? I can’t find anything in documentation.
Heh! That’s true. Component::setBounds() doesn’t take floats as parameters. I have not noticed that, sorry.
But still void Rectangle< ValueType >::setBounds() takes ValueTypes which can be floats.
And I can use such Rectangle<float> for example to draw elements in paint() method. So why can’t I draw whole component with such rectangle?
It’s easy to get mess in code if you forgot which elements are defined by Rectangle<int> and which one by <float>.
Have you got any advices how to avoid such miss mess? Of course I can try to avoid using <float>. But sometimes it’s realy handy for me.
If you’re using rectangle for abstract positioning/layout/computation/etc, use floats!
If you’re using rectangle to set the bounds of a component, it needs to be ints. Screens are usually defined by an integer number of pixels (or points), so that makes sense. There’s nothing wrong with using Rectangle with floats to compute bounds accurately, then round it to int when actually setting component bounds, so long as you know it is being cast/rounded.