Recent

Author Topic: Resolution dependent component resizing  (Read 5215 times)

Stygian

  • Jr. Member
  • **
  • Posts: 90
Resolution dependent component resizing
« on: August 17, 2016, 09:27:21 am »
Hello,

I would like to develop and application which is running on fullscreen. The problem is not all monitor will be the same resolution. What is the correct way to resize the components(like Grinds, Textfiles...etc)?

Thanks You,
Sty.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Resolution dependent component resizing
« Reply #1 on: August 17, 2016, 09:48:12 am »

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Resolution dependent component resizing
« Reply #2 on: August 17, 2016, 10:56:28 am »
Use autosizing.

DON'T EVER USE AUTOSIZING!
At some point that screws up. BAD advice.
Specialize a type, not a var.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Resolution dependent component resizing
« Reply #3 on: August 17, 2016, 11:04:54 am »
DON'T EVER USE AUTOSIZING!
At some point that screws up. BAD advice.

Well, nothing is perfect. However, such a sweeping generalization in condemning valuable functionality is unwarranted. The Lazarus IDE itself uses autosizing throughout. So it can't be that bad. Yes, there are occasional glitches in IDE layout/sizing, but the bugs are usually remedied quickly.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Resolution dependent component resizing
« Reply #4 on: August 17, 2016, 11:20:07 am »
Use autosizing.

DON'T EVER USE AUTOSIZING!
At some point that screws up. BAD advice.
Contrary to your shout: ALWAYS USE AUTOSIZING, THAT'S THE ONLY WAY YOU CAN MAKE YOUR APP'S LAYOUT CORRECTLY IN ALL DIFFERENT WIDGETSETS AND PLATFORMS.
Well, unless you believe in your own manually coded resizing event handler so much that you're willing to devote a lot of time on it instead of letting the framework does it for you. Most autosizing problems come from the misunderstanding of how to use it. Surely it has (had?) bugs, but what doesn't? Keeping people away from using it only keeps the hidden bugs, not solving it even a little.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Resolution dependent component resizing
« Reply #5 on: August 17, 2016, 11:24:35 am »
I used autosizing. But as Thaddy said, in some rare cases the components will look bad. Fortunately, with proper combination of anchors and constraints so far my programs are working correctly.

Or you can write your own visual components which do not depend on the screen resolution just as what I am working. It takes lots of time and not easy, but the result is more satisfied.

Stygian

  • Jr. Member
  • **
  • Posts: 90
Re: Resolution dependent component resizing
« Reply #6 on: August 17, 2016, 11:35:36 am »
Hello,

Thanks for the answers. Currently what i don't have is enough time, so I'll give another shot to autosize(i tried before and it not like stringgrid :) ). I'm also tried another method when i decrease the size of the components based on the resulution(but my rate converting equation was not perfect at all). All properties was stored in an .ini file. It was nice but a hole lot of work.

Thanks,
Sty

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Resolution dependent component resizing
« Reply #7 on: August 17, 2016, 01:04:00 pm »
If auto sizing does not work as expected for some reason, here is some simple code I used 20 years ago that can help with components layout:

http://stackoverflow.com/questions/8296784/how-do-i-make-my-gui-behave-well-when-windows-font-scaling-is-greater-than-100/8311695#8311695
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Stygian

  • Jr. Member
  • **
  • Posts: 90
[Sloved]Resolution dependent component resizing
« Reply #8 on: August 24, 2016, 08:49:23 am »
Thank you everyone,

With all the tools and ideas i get it's working kinda fine.

Regards,
Sty.

derek.john.evans

  • Guest
Re: Resolution dependent component resizing
« Reply #9 on: August 24, 2016, 10:28:19 am »
There was a question like this a few months back. ie: Percentage scaling of components. If that is what you want, this is how I'd do it:

Code: Pascal  [Select][+][-]
  1. procedure WinControlScale(const AWinControl: TWinControl);
  2. var
  3.   LIndex: integer;
  4.   LDiv, LMul: TPoint;
  5.   LControl: TControl;
  6. begin
  7.   LMul := Point(AWinControl.Width, AWinControl.Height);
  8.   LDiv := Point(AWinControl.ReadBounds.Right - AWinControl.ReadBounds.Left,
  9.     AWinControl.ReadBounds.Bottom - AWinControl.ReadBounds.Top);
  10.   for LIndex := 0 to AWinControl.ControlCount - 1 do begin
  11.     LControl := AWinControl.Controls[LIndex];
  12.     LControl.BoundsRect := Rect(LControl.ReadBounds.Left * LMul.X div LDiv.X,
  13.       LControl.ReadBounds.Top *
  14.       LMul.Y div LDiv.Y, LControl.ReadBounds.Right * LMul.X div LDiv.X,
  15.       LControl.ReadBounds.Bottom * LMul.Y div LDiv.Y);
  16.     LControl.Font.Height := Screen.SystemFont.Height * LMul.Y div LDiv.Y;
  17.     if LControl is TTreeView then begin
  18.       TTreeView(LControl).Indent := 15 * LMul.X div LDiv.X;
  19.     end else if LControl is TToolBar then begin
  20.       TToolBar(LControl).ButtonHeight := TToolBar(LControl).ClientHeight;
  21.       TToolBar(LControl).ButtonWidth := TToolBar(LControl).ButtonHeight;
  22.     end;
  23.     if LControl is TWinControl then begin
  24.       WinControlScale(TWinControl(LControl));
  25.     end;
  26.   end;
  27. end;  
  28.  

In TForm.OnResize just put:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormResize(Sender: TObject);
  2. begin
  3.   WinControlScale(Self);
  4. end;  
  5.  

Looks kinda cool imho

 

TinyPortal © 2005-2018