• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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

 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 27365
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 27365
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic