Forum > Linux

Form autosize problem in Linux

(1/2) > >>

artem101:
I have not-resizable form with auto sizing. Small example:


--- Code: ---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

--- End code ---


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    Label1: TLabel;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin  Label1.Caption:='llklklk kljkljklj jkhklhklj hkhklh'+LineEnding+'jjhkjhj jbkjbj bkjbjk'  +LineEnding+'kkjkjkjk';end; procedure TForm1.Button2Click(Sender: TObject);begin  Label1.Caption:='text...';end; end. 
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:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    Label1: TLabel;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);  private    procedure UpdateAutoSize; // Should be manually called in every place where form size may be changed  public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin  Label1.Caption:='llklklk kljkljklj jkhklhklj hkhklh'+LineEnding+'jjhkjhj jbkjbj bkjbjk'  +LineEnding+'kkjkjkjk';   UpdateAutoSize;end; procedure TForm1.Button2Click(Sender: TObject);begin  Label1.Caption:='text...';   UpdateAutoSize;end; procedure TForm1.UpdateAutoSize;begin  // Not needed for Windows  {$IfDef Linux}  AutoSize := not AutoSize; // Turn off  AutoSize := not AutoSize; // Turn on again  {$EndIf}end; end. 
Any ideas how to make it more correct?

wp:
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:

--- Quote from: wp on March 08, 2023, 03:26:44 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.

--- End quote ---

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.

wp:
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)...

Navigation

[0] Message Index

[#] Next page

Go to full version