Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2019-08

Cross-platform project. Font sizes not the same....

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I have just transfered a simple 3-form project from Windows7 to Linux (Raspbian on RPi4).
I am using the same versions of Fpc and Lazarus on both (3.0.4 and 2.0.4).

The project compiled fine after the transfer to Raspbian as it did on Windows.

But the form is very much in need of control changes since text no longer fits in the controls. Edit boxes grow a lot in height and so on.
I can go into the font property of affected controls and change the font size to make it look better, but there are so many...

If this is the normal case I don't see how I can maintain two versions from the same sources, I cannot ifdef UNIX vs Windows every place a font is mentioned in the code, in fact it is not even in the code but inside the form file (lfm)...

There must be something I have done wrong here, but what? Any porting advice somewhere?

I did not set font sizes at all in Lazarus on Windows. it used the defaults and when I check they are set to be 9. But in Lazarus on Linux the font size on the form is 10. It makes quite a difference.

Is there some global project setting for the fonts that I can use to make the project cross-platform withut code changes?

Bo Berglund Developer in Sweden

Reply by email

Werner Pamler
to Bo Berglund

AFIK there is no simple way to force fonts to use the same size (unless you specify a given font size - which however may not be the size of some theme of one of the target systems which will make your program look "strange"). The only way I know to make forms cross-platform is to use auto-sizing as much as possible. And don't position controls absolutely, but attach them to their neighbors by means of the AnchorEditor. Avoid frozen form sizes -- the user must be able to readjust the size if something is awfully wrong.

Reply by email

Bo Berglund
to Bo Berglund: I have just transfered a simple 3-form project from Windows7 to Linux (Raspbian on RPi4).…
Bo Berglund wrote
I can go into the font property of affected controls and change the font size to make it look better, but there are so many...

In fact there are not that many controls so I tried to do the following on Windows:

procedure TfrmMain.SetFontSize(S: integer);
begin
  // Set font size on load.
  btnDec60.Font.Size := S;
  btnDec30.Font.Size := S;
  btnDec10.Font.Size := S;
  btnDec1.Font.Size := S;
  btnInc1.Font.Size := S;
  btnInc10.Font.Size := S;
  btnInc30.Font.Size := S;
  btnInc60.Font.Size := S;
  btnCutStart.Font.Size := S;
  btnCutEnd.Font.Size := S;
  btnAddCut.Font.Size := S;
  btnJump.Font.Size := S;
  btnShiftAudio.Font.Size := S;
  speDelay.Font.Size := S;
  stxCutStart.Font.Size := S;
  stxCutEnd.Font.Size := S;
  stxCutTime.Font.Size := S;
  stxClipCnt.Font.Size := S;
  gbxCut.Font.Size := S;
  ckbLogin.Font.Size := S;
end;
procedure TfrmMain.FormShow(Sender: TObject);
begin
  SetFontSize(9);
end;

This works just fine on Windows so I went to my RPi4 and opened the project there and added these two procedures also to that instance of the project, thinking it would at laset fix the font size temporarily. But when I run this I get an exception!

--------------------------------------------------------------------- Debugger Exception Notification
Project VideoPlayer raised exception class 'EReadError' with message: Invalid value for property
At address C4920

[] Ignore this exception type [Break] [Continue] ---------------------------------------------------------------------

If I check the Ignore checkbox and contine I get another error:

--------------------------------------------------------- Error reading frmMain.OnShow: Invalid value for property Press OK to ignore and risk data corruption
Press Abort to kill the program
[Abort] [OK]
---------------------------------------------------------

Strangely it did not manage to handle the integer value for font size so I redefined the SetFontSize procedure to be declared as follows:

procedure TfrmMain.SetFontSize(S: shortint);

With this in place the form in Linux became the same as on Windows size-wise regarding texts.

Maybe a difference between the operating systems, I think Raspbian is still a 32 bit system whereas Lazarus on Window 7 x64 is a 64 bit program on a 64 bit OS.

Bo Berglund Developer in Sweden

Reply by email

Kostas Michalopoulos
to Bo Berglund

I *highly* recommend to avoid changing font sizes, users select themes because they want applications to use them, so it is better to stick with their choices and use autosizing (the default setting for most controls), the align property and the anchor editor.

Here is an old (but still valid) video i made ~6 years ago where i quickly show the anchor editor in practice:
https://www.youtube.com/watch?v=neigk9Pt21o

Using the anchor editor you can create UIs that dynamically adjust position and size based on the user settings and allow the user to resize windows.

Generally speaking try to design UIs that use as little fixed positioning as possible. Fixed positioning (that is, dragging and dropping a control on the form and manually adjusting its position and size there with the mouse) is fine for simple applications that will only work on Windows or macOS that traditionally has kept font sizes the same over the years (though even then on Windows you can use different fonts and some people do), but on Linux you simply cannot rely on anything to be constant and fixed positioning can only be used as a starting point for your layout (ie. place the controls manually in a fixed position+size and then open the anchor editor and start stitching them together one by one - this is basically what i do in the video above).

Kostas

AM Bo Berglund wrote 84 lines
On Tue, 20 Aug 2019 23:47:39 +0200, Bo Berglund via lazarus wrote: >I can go into the font property of affected controls and change the >font size to make it look better, but there are so many... In fact there are not that many controls so I tried to do the following on Windows: procedure TfrmMain.SetFontSize(S: integer); begin // Set font size on load. btnDec60.Font.Size := S; btnDec30.Font.Size := S; btnDec10.Font.Size := S; btnDec1.Font.Size := S; btnInc1.Font.Size := S; btnInc10.Font.Size := S; btnInc30.Font.Size := S; btnInc60.Font.Size := S; btnCutStart.Font.Size := S; btnCutEnd.Font.Size := S; btnAddCut.Font.Size := S; btnJump.Font.Size := S; btnShiftAudio.Font.Size := S; speDelay.Font.Size := S; stxCutStart.Font.Size := S; stxCutEnd.Font.Size := S; stxCutTime.Font.Size := S; stxClipCnt.Font.Size := S; gbxCut.Font.Size := S; ckbLogin.Font.Size := S; end; procedure TfrmMain.FormShow(Sender: TObject); begin SetFontSize(9); end; This works just fine on Windows so I went to my RPi4 and opened the project there and added these two procedures also to that instance of the project, thinking it would at laset fix the font size temporarily. But when I run this I get an exception! --------------------------------------------------------------------- Debugger Exception Notification Project VideoPlayer raised exception class 'EReadError' with message: Invalid value for property At address C4920 [] Ignore this exception type [Break] [Continue] --------------------------------------------------------------------- If I check the Ignore checkbox and contine I get another error: --------------------------------------------------------- Error reading frmMain.OnShow: Invalid value for property Press OK to ignore and risk data corruption Press Abort to kill the program [Abort] [OK] --------------------------------------------------------- Strangely it did not manage to handle the integer value for font size so I redefined the SetFontSize procedure to be declared as follows: procedure TfrmMain.SetFontSize(S: shortint); With this in place the form in Linux became the same as on Windows size-wise regarding texts. Maybe a difference between the operating systems, I think Raspbian is still a 32 bit system whereas Lazarus on Window 7 x64 is a 64 bit program on a 64 bit OS. -- Bo Berglund Developer in Sweden -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

Reply by email