Recent

Author Topic: Set Dynamic View for Lazarus Tool [SOLVED]  (Read 1112 times)

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Set Dynamic View for Lazarus Tool [SOLVED]
« on: April 09, 2021, 03:18:22 pm »
Hello everybody,

I recently finished a tool of mine which works fine. Now I want to fine tune it.
At the moment My PC is connected to a 2160p monitor. I set a static view meaning that the tool has no BorderStyle (no close, minimize and fullscreen-button) and can't be moved. After I connected my PC to a new monitor (which only supports 1080p) the windows of my tool was halfway out the screen.

Therefore I wanted to know if there is an option to automatically adjusts to the current screen resolution without stretching or moving the position of the window (let's say it should always be about 1/4 the size of the height and width of the screen resolutionan the buttons and images should be as well.

Unfortunatly I don't have any code as for this moment.
« Last Edit: April 14, 2021, 10:32:35 am by AlphaInc. »

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Set Dynamic View for Lazarus Tool
« Reply #1 on: April 09, 2021, 04:04:25 pm »
I hate the standard dialogs which cannot be resized and which force me to scroll because of this limitation although the monitor provides enough space. A window which cannot be moved is a "no-go" because it certainly will cover another piece of important information.

If you still think that your layout concept is absolutely needed then you must calculate the position and size of the controls as fractions of the monitor size. You could also use some auto-layout tools like a TFlowPanel which helps to arrange controls in rows and columns which scale with the size of the window. But watch out: Texts do not necessarily scale in the same ratio as the controls, they may become too long or too short and be truncated or may overlap.

The correct layout strategy, in my opinion, is demonstrated by the Lazarus IDE: Sizes can be controlled by the user and are stored in the applications config file. This way the user can adjust every detail to his linkings and requirements.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9912
  • Debugger - SynEdit - and more
    • wiki
Re: Set Dynamic View for Lazarus Tool
« Reply #2 on: April 09, 2021, 04:22:25 pm »
There is a global var "Screen: TScreen" in unit Forms.
But be aware, it is more complicated.

First you must find the monitor you want to use. (Many people have more than one).

Then be aware, that Top/Left coordinates can be negative.

There is also the Desktop (but that may be partly invisible, if monitors do not align on all edges.
And there is the WorkArea (e.g. without taskbar) for the desktop.
And each Monitor has a WorkArea too.

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: Set Dynamic View for Lazarus Tool
« Reply #3 on: April 09, 2021, 04:43:04 pm »
I hate the standard dialogs which cannot be resized and which force me to scroll because of this limitation although the monitor provides enough space. A window which cannot be moved is a "no-go" because it certainly will cover another piece of important information.

If you still think that your layout concept is absolutely needed then you must calculate the position and size of the controls as fractions of the monitor size. You could also use some auto-layout tools like a TFlowPanel which helps to arrange controls in rows and columns which scale with the size of the window. But watch out: Texts do not necessarily scale in the same ratio as the controls, they may become too long or too short and be truncated or may overlap.

The correct layout strategy, in my opinion, is demonstrated by the Lazarus IDE: Sizes can be controlled by the user and are stored in the applications config file. This way the user can adjust every detail to his linkings and requirements.

The application config file sound like a good start for me to configure the tool. How do I set a config file up?

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Set Dynamic View for Lazarus Tool
« Reply #4 on: April 09, 2021, 05:32:40 pm »
I normally write all sizes, splitter positions etc at program end to an ini file and read it back when the application starts the next time. But there are also automatic components for that purpose: TXMLPropStorage, TIniPropStorage, TJsonPropStorage. For XMLPropStorage there is a wiki article (https://wiki.freepascal.org/TXMLPropStorage), but I think it can be extended logically to IniPropStorage and JsonPropStorage.

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: Set Dynamic View for Lazarus Tool
« Reply #5 on: April 09, 2021, 06:03:36 pm »
I normally write all sizes, splitter positions etc at program end to an ini file and read it back when the application starts the next time. But there are also automatic components for that purpose: TXMLPropStorage, TIniPropStorage, TJsonPropStorage. For XMLPropStorage there is a wiki article (https://wiki.freepascal.org/TXMLPropStorage), but I think it can be extended logically to IniPropStorage and JsonPropStorage.

Do you also use TXMLPropStorage (or TIniPropStorage)?
If yes, how do you do it?

Let's make an example for 1080p and 2160p. Do you have a procedure at the end of your project which implements the values of height, width, left and top for the form, every button and the tool itself and import them off the ini?
How do you this ? (Sorry if I ask too much, this i fairly new to me)

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Set Dynamic View for Lazarus Tool
« Reply #6 on: April 09, 2021, 07:28:51 pm »
I normally write all sizes, splitter positions etc at program end to an ini file and read it back when the application starts the next time. But there are also automatic components for that purpose: TXMLPropStorage, TIniPropStorage, TJsonPropStorage. For XMLPropStorage there is a wiki article (https://wiki.freepascal.org/TXMLPropStorage), but I think it can be extended logically to IniPropStorage and JsonPropStorage.

Do you also use TXMLPropStorage (or TIniPropStorage)?
I don't use them myself, but for not a good reason, just being used to writing code.

How to use them? Just follow the steps written under "Usage" in the wiki article. The attached demo only has an XMLPropStorage component on the form, and in the SessionProperties I defined the Width, Height, Left and Top properties to be stored. So, compile and run the demo. Change position and size of the window. When you close the program the XMLPropStorage creates an xml file with these settings (by default in the program folder, but you can change it by the FileName property of the XMLPropStorage). When you start the application the next time, the settings are read from the xml file and reapplied and the program will appear in the size and at the position where you left it. All this is done without a single line of code!

I would not store the position of every button and every other control. You should use the anchor editor (https://wiki.freepascal.org/Anchor_Sides) to align the sides of the controls to each other, e.g. anchor the left side of a TEdit to the right side of a label to avoid the label text running into the edit. The anchor editor is a bit unusual to use at first time, but an absolute necessity for self-adjusting layouts

I cannot give more specific advice because I don't know what your application looks like. maybe you can post a screenshot here.

AlphaInc.

  • Jr. Member
  • **
  • Posts: 93
Re: Set Dynamic View for Lazarus Tool
« Reply #7 on: April 10, 2021, 12:29:51 am »
I normally write all sizes, splitter positions etc at program end to an ini file and read it back when the application starts the next time. But there are also automatic components for that purpose: TXMLPropStorage, TIniPropStorage, TJsonPropStorage. For XMLPropStorage there is a wiki article (https://wiki.freepascal.org/TXMLPropStorage), but I think it can be extended logically to IniPropStorage and JsonPropStorage.

Do you also use TXMLPropStorage (or TIniPropStorage)?
I don't use them myself, but for not a good reason, just being used to writing code.

How to use them? Just follow the steps written under "Usage" in the wiki article. The attached demo only has an XMLPropStorage component on the form, and in the SessionProperties I defined the Width, Height, Left and Top properties to be stored. So, compile and run the demo. Change position and size of the window. When you close the program the XMLPropStorage creates an xml file with these settings (by default in the program folder, but you can change it by the FileName property of the XMLPropStorage). When you start the application the next time, the settings are read from the xml file and reapplied and the program will appear in the size and at the position where you left it. All this is done without a single line of code!

I would not store the position of every button and every other control. You should use the anchor editor (https://wiki.freepascal.org/Anchor_Sides) to align the sides of the controls to each other, e.g. anchor the left side of a TEdit to the right side of a label to avoid the label text running into the edit. The anchor editor is a bit unusual to use at first time, but an absolute necessity for self-adjusting layouts

I cannot give more specific advice because I don't know what your application looks like. maybe you can post a screenshot here.

Thank you again for the replay. I will this code tomorrow after I wake up.

 

TinyPortal © 2005-2018