I've got a layoutmanager that has initial sizes of different rows and columns. I want to allow resizing which keeps the percentage of total size for each component.
For example, if I have the following rows: 25, 50, 25, then the total size is 100 and their percentages are 25%, 50%, 25%. If the display is then resized to 111 pixels, the percentages yield 27.75px, 55.5px, 27.75 px. How do I decide who gets an extra pixel and who gets it taken away? (the problem looks tougher when you have percentages that yield numbers like 10.17px, 11.1245px...)
How do I create an algorithm to decide this "intelligently?"
Don't calculate the width of each component. Instead, calculate its left and right boundary, by adding up the percentages of all components left of it.
Would that help?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Paul Clapham: You might not think that this article is relevant to your question, but scroll down until you see Alexander Hamilton mentioned and start reading there.
Hmm, that's a pretty good start, but it doesn't fully answer the following (IMO):
A: 21.32 B: 54.96 C: 54.96
Nor this one:
A: 21.32 B: 54.96 C: 54.97
In the first, you've got equal remainders so we're again back to the original question. With the second, while I can just give an extra pixel to "C," "B" is so close to 55 that it almost seems incorrect to push it all the way back to 54.
Originally posted by Dan Bizman: Hmm, that's a pretty good start, but it doesn't fully answer the following (IMO):...
Yeah. The article doesn't actually say there is no good answer to the question (or does it? I didn't read the whole durn thing either), but that's basically the case. No matter which algorithm you choose, there are always cases where that algorithm produces ugly results.
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?