Hidden controls inside of a flow panel still occupy space lazarus / 31-LCL ---------------------------------------------------------------------- Joanna · 2023-02-09 01:44 I don't know if this is intended or not but the hidden controls inside of a flowpanel still occupy space and cause the flow panel to be bloated with extra blank space. My current workaround is to remove invisible controls from the flovwpanel and only have flowpanel as parent for visible controls. Perhaps the code for the tflowpanel needs some reworking to take visibility into account when sizing ? ---------------------------------------------------------------------- Handoko · 2023-02-09 04:03 Tested on Lazarus 2.3.0 GTK2 on Ubuntu Mate 64-bit. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, ExtCtrls, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    Button3: TButton;    Button4: TButton;    FlowPanel1: TFlowPanel;    procedure Button4Click(Sender: TObject);    procedure FormCreate(Sender: TObject);  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button4Click(Sender: TObject);begin  Button2.Visible := False;end; procedure TForm1.FormCreate(Sender: TObject);begin  FlowPanel1.Anchors := [akLeft] + [akRight] + [akTop] + [akBottom];end; end. After clicking the "Click Me" button, the Button2 will be hidden. It's working good on my test, or did I misunderstand what you meant? ---------------------------------------------------------------------- Joanna · 2023-02-09 06:06 have you tried making the flow panel a distinct color like clred and then trying to get the flow panel elements to be on one row? and then hiding one ?  when i do this the flow panel is wider than necessary because it is accommodating the hidden control. what does it look like if you hide button2? ---------------------------------------------------------------------- Handoko · 2023-02-09 08:23 Sorry, I couldn't reproduce it or fully understood what you said. Please provide a demo that shows the problem or at least modify the code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, ExtCtrls, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    btnClickMe: TButton;    FlowPanel1: TFlowPanel;    procedure btnClickMeClick(Sender: TObject);    procedure FormCreate(Sender: TObject);  private    FTarget: TButton;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.btnClickMeClick(Sender: TObject);begin  FTarget.Visible  := False;end; procedure TForm1.FormCreate(Sender: TObject);var  Button: TButton;  i:      Integer;begin  Constraints.MinHeight := 300;  Constraints.MaxHeight := 300;  FlowPanel1.Anchors    := [akLeft] + [akRight] + [akTop] + [akBottom];  FlowPanel1.Color      := clRed;  for i := 0 to 20 do  begin    Button         := TButton.Create(FlowPanel1);    Button.Parent  := FlowPanel1;    Button.Caption := i.ToString;    Button.Color   := $FF00AA + i * $BFF;    if i = 6 then    begin      Button.Color := $00FF00;      FTarget      := Button;    end;  end;end; end. Note: TButton.Color is not supported on Windows. ---------------------------------------------------------------------- Joanna · 2023-02-09 10:59 Thanks for trying to help , what happens if you have just 4 buttons and try to have the flow panel fit the buttons without extra space on one line then hide one of the buttons? Also your picture shows a lot of extra space under the buttons. Are you able to have flowpanel fit around buttons without the blank area underneath? I use tcdbuttons so I can control color ---------------------------------------------------------------------- Handoko · 2023-02-09 11:14 I modified the source code in the reply #3: - Line #46:   for i := 0 to 3 do - Line #52:     if i = 2 then Nothing weird happened, still worked as what it should be. Quote from: Joanna on February 09, 2023, 11:59:38 amAlso your picture shows a lot of extra space under the buttons. Are you able to have flowpanel fit around buttons without the blank area? FlowPanel doesn't handle that issue. As the name suggests, it just makes all the items inside to flow to stick together. I haven't tried but if I want, I think I can to make all the items to fit properly without blank area but I would rather use a TPanel and write the code myself. ---------------------------------------------------------------------- Joanna · 2023-02-09 11:25 Doesn’t flowpanel have some sort of autosize mechanism? So it can detect how much space it needs on bottom? I use flowpanel inside a frame and constrain the frame to fit the flow panel but if the flowpanel contains hidden controls it still makes space where they would have been which is undesirable ---------------------------------------------------------------------- Handoko · 2023-02-09 11:37 I rarely use TFlowPanel and I also rarely use AutoSize. But for the similar purpose I ever used combination of: - TPanel - TSplitter - Align := alClient - Align := alTop or alButton. And that worked. ---------------------------------------------------------------------- Joanna · 2023-02-09 12:32 I use splitters and panels for some things but in this case I’m looking for a flowpanel that fits controls tightly without extra space on bottom. I will keep changing the parent of hidden controls I was just curious why I need to do this or if it will ever be fixed. ---------------------------------------------------------------------- Joanna · 2023-02-09 12:56 to be fair I'm doing something complicated .i have a frame with a flovwpanel that is inherited by another frame which creates frames inside the ancestor flow panel ---------------------------------------------------------------------- KodeZwerg · 2023-02-09 12:58 Can you attach a demo project to tinker a little? Sound like fun what you are doing/try to do ---------------------------------------------------------------------- wp · 2023-02-09 12:58 In my own tests (Windows, Linux), the TFlowPanel does rearrange the layout when a control is hidden. It does not resize the controls to fill the extra space at the bottom. Setting TFlowPanel.AutoSize to true arranges all controls in a single column, unless you specify an appropriate Constraints.MinWidth value for the FlowPanel. Alternatively you could use a plain-old TPanel as containter and instruct the ChildSizing property to do the layout work: Select the panel and go to its ChildSizing property.Set Layout to cclLeftToRightThenTopToBottomSet ControlsPerLine to the number of controls that you want to have in each row before following controls are wrapped into the nexxt rowAdd your controls - they will be arranged automatically in rows (up to ControlsPerLine) and wrapped. Do not modify the Anchors (must be [akLeft, akTop], otherwise ChildSizing does not work).Define the distance between the controls by means of HorizontalSpacing and VerticalSpacing. The border spacing is given by LeftRightSpacing and TopBottomSpacing.Set the panel's AutoSize to true, and it will shrink to the total size of the automatically arranged controls.On the other hand, you can keep Panel.AutoSize at false and force ChildSizing to resize the controls so that the total row width and column height fills the available space. For this you must set the panel.ChildSizing.EnlargeHorizontal, .EnlargeVertical, .ShrinkHorizontal, .ShrinkVertical to crsHomoenousChildResize. You have further control over the resizing processing when you do not apply this to all of these properites.Practice work with ChildSizing in a dummy project because sometime the changes due to some settings cannot be reverted. wiki documentation: https://wiki.freepascal.org/Autosize_/_Layout#Layout ---------------------------------------------------------------------- Joanna · 2023-02-09 13:38 Quote from: KodeZwerg on February 09, 2023, 01:58:40 pmCan you attach a demo project to tinker a little? Sound like fun what you are doing/try to do My code is rather tightly coupled with inheritance. A brief description of what I’m doing is.. 1. I have a base frame with a flowpanel-> 2.a frame with Label and combobox inside flow panel -> 3. A frame with label and combobox which loads a list selected and unselected filtering Boolean Columns from an sqlite table-> 4. A frame with a Boolean filter labeled combobox which creates frames with buttons to set a Boolean column to false in sqlite table. The idea is to select one of the items in the combobox which generates an sql statement for example item ‘favorites’ generates ... select * from mytable where favorite = 1 ‘Non favorite’ gives select * from mytable Where favorite = 0 I keep track of how many items in each column are selected using an array . Only items that will generate a non empty dataset are permitted in combobox. There are frames with button added to the ancestor flowpanel for for each Boolean column. Only button frames corresponding to Sqlite table columns with selected Values are visible. Hence the strange behavior of flowpanel being too tall if some are hidden. Which I solve by changing their parent to the frame itself. I constrain the controls to fit their captions usually. I often have nested frames that are descendants of same flowpanel ancestor.