Recent

Author Topic: Form autosize problem in Linux  (Read 1282 times)

artem101

  • Jr. Member
  • **
  • Posts: 84
Form autosize problem in Linux
« on: March 07, 2023, 10:43:06 am »
I have not-resizable form with auto sizing. Small example:

Code: [Select]
object Form1: TForm1
  Left = 260
  Height = 240
  Top = 250
  Width = 320
  AutoSize = True
  BorderStyle = bsSingle
  Caption = 'Form1'
  ChildSizing.Layout = cclLeftToRightThenTopToBottom
  ChildSizing.ControlsPerLine = 1
  ClientHeight = 240
  ClientWidth = 320
  LCLVersion = '2.2.4.0'
  object Label1: TLabel
    Left = 0
    Height = 16
    Top = 0
    Width = 70
    Caption = 'Label1'
    ParentColor = False
  end
  object Button1: TButton
    Left = 0
    Height = 28
    Top = 16
    Width = 70
    Caption = 'Long text'
    OnClick = Button1Click
    TabOrder = 0
  end
  object Button2: TButton
    Left = 0
    Height = 28
    Top = 44
    Width = 70
    Caption = 'Short text'
    OnClick = Button2Click
    TabOrder = 1
  end
end

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Button2: TButton;
  17.     Label1: TLabel;
  18.     procedure Button1Click(Sender: TObject);
  19.     procedure Button2Click(Sender: TObject);
  20.   private
  21.  
  22.   public
  23.  
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.Button1Click(Sender: TObject);
  36. begin
  37.   Label1.Caption:='llklklk kljkljklj jkhklhklj hkhklh'+LineEnding+'jjhkjhj jbkjbj bkjbjk'
  38.   +LineEnding+'kkjkjkjk';
  39. end;
  40.  
  41. procedure TForm1.Button2Click(Sender: TObject);
  42. begin
  43.   Label1.Caption:='text...';
  44. end;
  45.  
  46. end.
  47.  

On MS Windows this code works as expected, but on Linux window changes size only once and no more reaction to component resizing (see attached image).

I checked this on Linux Mint 20.3 and Ubuntu 20.04.5.

artem101

  • Jr. Member
  • **
  • Posts: 84
Re: Form autosize problem in Linux
« Reply #1 on: March 08, 2023, 01:15:41 pm »
It's possible to trigger form size recalculation by setting AutoSize to False and then back to True. But I think it`s not good solution, because I need to manually call this in every place of code where form size may be changed.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Button2: TButton;
  17.     Label1: TLabel;
  18.     procedure Button1Click(Sender: TObject);
  19.     procedure Button2Click(Sender: TObject);
  20.   private
  21.     procedure UpdateAutoSize; // Should be manually called in every place where form size may be changed
  22.   public
  23.  
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35. procedure TForm1.Button1Click(Sender: TObject);
  36. begin
  37.   Label1.Caption:='llklklk kljkljklj jkhklhklj hkhklh'+LineEnding+'jjhkjhj jbkjbj bkjbjk'
  38.   +LineEnding+'kkjkjkjk';
  39.  
  40.   UpdateAutoSize;
  41. end;
  42.  
  43. procedure TForm1.Button2Click(Sender: TObject);
  44. begin
  45.   Label1.Caption:='text...';
  46.  
  47.   UpdateAutoSize;
  48. end;
  49.  
  50. procedure TForm1.UpdateAutoSize;
  51. begin
  52.   // Not needed for Windows
  53.   {$IfDef Linux}
  54.   AutoSize := not AutoSize; // Turn off
  55.   AutoSize := not AutoSize; // Turn on again
  56.   {$EndIf}
  57. end;
  58.  
  59. end.
  60.  

Any ideas how to make it more correct?

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Form autosize problem in Linux
« Reply #2 on: March 08, 2023, 03:26:44 pm »
Just tested on Linux Mint 20.2 and on macOS 10.14 (Mojave) and found no issue, the test application that you described worked flawlessly (even without UpdateAutoSize) (Laz/main + fpc 3.2.2, on Mint also Laz 2.0.0).

Please post a full compilable project (.lpi, lpr, .lfm, .pas files - pack them into a shared zip which you can upload diretly via "Attachments and other options"); maybe the issue is in some other setting.

artem101

  • Jr. Member
  • **
  • Posts: 84
Re: Form autosize problem in Linux
« Reply #3 on: March 08, 2023, 05:51:48 pm »
Please post a full compilable project (.lpi, lpr, .lfm, .pas files - pack them into a shared zip which you can upload diretly via "Attachments and other options"); maybe the issue is in some other setting.

Already attached to the first post.

I use latest Lazarus 2.2.4 and FPC 3.2.2.

Just tested my first code in latest Linux Mint 21.1 with XFCE. The problem is reproduced.
« Last Edit: March 08, 2023, 06:12:52 pm by artem101 »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Form autosize problem in Linux
« Reply #4 on: March 08, 2023, 07:18:15 pm »
Sorry, I was distracted by the screenshot...

You demo seems to be exactly like mine, except for the BorderStyle (I had it at bsSizeable), different "words" in the long caption and having the label's WordWrap=true.

I could reproduce the issue on Linux Mint now (this was not possible with my demo). Switching BorderStyle to bsSizeable or bsNone or bsSizeToolWin, however, made your application work correctly, it does not work correctly for BorderStyle = bsSingle, bsDialog and bsToolWin.

Then returned to Windows and saw another issue here. At first: the form did not shrink to tightly enclose the label and the buttons (Width = 130), and after clicking on the "Long text" button it grew somehow but truncated all controls, the "Short text" button was below the bottom form border. Trying to resize the form at designtime I noticed that this is not possible... Had the idea to restrict the width of the buttons and specified Button1.Constraints.minWidth := 130 - the issue is gone (any larger value can be used, 129 makes the issue return again).

Quite mystical. No idea where that magic number 130 comes from, maybe related to the minimum form width of 120 px in windows (which exists also in Delphi)...

artem101

  • Jr. Member
  • **
  • Posts: 84
Re: Form autosize problem in Linux
« Reply #5 on: March 11, 2023, 01:20:24 pm »
Then returned to Windows and saw another issue here..

This is not what I interested in. I make another more real demo. It has no problem in Windows, in Linus problem still the same

zeljko

  • Hero Member
  • *****
  • Posts: 1596
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Form autosize problem in Linux
« Reply #6 on: March 12, 2023, 10:15:33 am »
This works perfect under linux, but with qt,qt5 or qt6 ws.

artem101

  • Jr. Member
  • **
  • Posts: 84
Re: Form autosize problem in Linux
« Reply #7 on: March 12, 2023, 04:17:31 pm »
This works perfect under linux, but with qt,qt5 or qt6 ws.
But what about GTK?

balazsszekely

  • Guest
Re: Form autosize problem in Linux
« Reply #8 on: March 12, 2023, 05:14:05 pm »
@artem101
Try this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.CheckBox1Change(Sender: TObject);
  2. begin
  3.   CheckGroup2.Visible:=CheckBox1.Checked;
  4.   {$ifdef LCLGTK2}
  5.   Self.AutoSize := False;
  6.   Self.AutoSize := True;
  7.   {$endif}
  8. end;    

 

TinyPortal © 2005-2018