Recent

Author Topic: [SOLVED] Auto sizing GUI to size of users screen?  (Read 7153 times)

Gizmo

  • Hero Member
  • *****
  • Posts: 831
[SOLVED] Auto sizing GUI to size of users screen?
« on: November 24, 2014, 12:14:26 am »
I'm having some difficulties with the GUI of one of my programs in as much as despite my best efforts to fit everything in, when users adopt a small screen resolution, the GUI is too large for the screen.

One user has posted the following :

"The headline of the gui is outside the screen, seems to be positioned with it's upper left corner in negative Y-coordinate. I cannot access the top bar and so can't move the window to drag or resize. Changing to a higher screen of 1366x768 / 1600x900 temporarly gives access to it, but after a restart it's again out of screen area.

...the left upper corner of the GUI should be at X=10 / Y=10, independent of the resolution of the screen."


I accept my GUI design skills probably need to be enhanced but in the meantime, is there a way to make it detect the screen resolution of the user and have it scaled to that, even if it does mean labels and fields might be a touch squashed together or even overlapping? I have tried the "Autosize" property of the main form, but that seems to scale the GUI to the minimum width of 'something' (not sure what it uses to base the scaling on) meaning the default view when launched is half the size that it should be and many of the my labels and buttons are not visible. I also tried the default windows state property to wsMaximised instead of wsNormal, but then the top bar does indeed seem to be higher than the screen resolution so the only way to close it is using Alt + F4 as it is not possible to access the top minimise, maximise or exit buttons.

« Last Edit: November 24, 2014, 06:05:30 pm by Gizmo »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Auto sizing GUI to size of users screen?
« Reply #1 on: November 24, 2014, 12:58:26 am »
You can detect resolution by
Code: [Select]
x:=screen.width;
y:=screen.height;
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Syndrome

  • New Member
  • *
  • Posts: 35
Re: Auto sizing GUI to size of users screen?
« Reply #2 on: November 24, 2014, 03:09:15 am »
simple gui scale example
press keyboard arrow to change app size

bzman24

  • Jr. Member
  • **
  • Posts: 71
Re: [SOLVED] Auto sizing GUI to size of users screen?
« Reply #3 on: November 28, 2014, 01:06:40 am »
I'm curious about the answer for this.  What do you mean "press keyboard arrow to change app size"?  What keyboard arrow?

I have apps that are designed and work fine on my desktop but don't look good at all on my laptop.

Please explain.

Thanks,

Bzman
==============
OS: Win7 - i5 - win64
Linux Mint 17.3
Lazarus: V1.8.2 / FPC - 3.0.4

Syndrome

  • New Member
  • *
  • Posts: 35
Re: [SOLVED] Auto sizing GUI to size of users screen?
« Reply #4 on: November 28, 2014, 01:33:12 am »
bzman24
download and compile attached file
it contains a simple lcl application with scalable gui
« Last Edit: November 28, 2014, 01:35:38 am by Syndrome »

bzman24

  • Jr. Member
  • **
  • Posts: 71
Re: [SOLVED] Auto sizing GUI to size of users screen?
« Reply #5 on: November 28, 2014, 02:09:34 am »
Syndrome, thanks.  Embarrassed for not seeing the attached file.  That explains what you are saying.  That is quite interesting.  I hope you don't mind if I incorporate some of that code into my projects.

FYI when I run it it gives a heap dump error when closed.  Not sure why.

Bzman :D :D
« Last Edit: November 28, 2014, 02:12:14 am by bzman24 »
==============
OS: Win7 - i5 - win64
Linux Mint 17.3
Lazarus: V1.8.2 / FPC - 3.0.4

Syndrome

  • New Member
  • *
  • Posts: 35
Re: [SOLVED] Auto sizing GUI to size of users screen?
« Reply #6 on: November 28, 2014, 03:22:53 am »
FYI when I run it it gives a heap dump error when closed.  Not sure why.

its not an error
heap tracer is enabled by default for my projects
you can disable it: Main menu -> project -> project options -> debug -> heaptrc checkbox
« Last Edit: November 28, 2014, 03:27:08 am by Syndrome »

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: [SOLVED] Auto sizing GUI to size of users screen?
« Reply #7 on: November 28, 2014, 05:04:11 am »
Although a universal solution for this task is welcome, its applicability will always be limited.

A general algorithm can only provide basic adaptation. Fine tuning depends on special needs of your application, the used widget set etc. Therefore, in most cases it will still be necessary to read out the screen's resolution at startup time and to do some "manual" adaptation.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Re: [SOLVED] Auto sizing GUI to size of users screen?
« Reply #8 on: November 28, 2014, 11:43:55 am »
My solution, based on Braazans suggestion, was to add this to my FormCreate instance, which at least ensures the top border and left border are visible for dragging, resizing etc

Code: [Select]
procedure TMainForm.FormCreate(Sender: TObject);
var
  x : integer;
  y : integer;
begin
 x := screen.width;
 y := screen.Height;

 if x < MainForm.Width then
 begin
   MainForm.Width := x - 50;
 end;

 if y < Mainform.Height then
 begin
   Mainform.Height := y - 50;
 end;
end;

 

TinyPortal © 2005-2018