• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

How properly "decide" where to put/take pixels in resizing?  RSS feed

 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?"
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you're going to have to iterate over each component, checking values.



might give you a first approximation.

J
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ilja Preuss:
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?



I'm not sure I follow you on this. Can you give some pseudo code to help explain what you mean? Thanks!
 
Paul Clapham
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!