[Lazarus] Autosize behaviour

Michael Van Canneyt michael at freepascal.org
Mon Apr 5 21:26:47 CEST 2010



On Mon, 5 Apr 2010, Mattias Gaertner wrote:

> On Mon, 5 Apr 2010 10:48:00 +0200 (CEST)
> Michael Van Canneyt <michael at freepascal.org> wrote:
>
>>
>>
>> On Mon, 5 Apr 2010, Mattias Gaertner wrote:
>>
>>> On Sun, 4 Apr 2010 19:21:00 +0200 (CEST)
>>> Michael Van Canneyt <michael at freepascal.org> wrote:
>>>
>>>> Hi,
>>>>
>>>> In delphi, setting a panel's AutoSize property to 'true' and aligning it to a
>>>> form edge, makes the panel disappear when the project is run.
>>>> This is logical, because, if there are no controls on the panel,
>>>> the needed size is zero.
>>>
>>> Yes, and this is the problem. A visible control must not have the size
>>> 0,0. It makes no sense. This is bad in the designer. The gtk does not
>>> like it.
>>> Therefore the LCL ignores the child bounds if no childs are there.
>>>
>>>
>>>> In Lazarus, the panel is still shown.
>>>>
>>>> Is this a known bug ?
>>>
>>> A feature. You are the first asking. Do you need it?
>>
>> What is "need"... The current behaviour is definitely not compatible to delphi.
>>
>> In Delphi, you can make dock zones along the edges of your
>> form by dropping 4 panels and aligning them along the edges of the form.
>> If autosize=true, then they have size 0 when the app is run (not when designed),
>> but you can dock controls on them, since there is a "fuzzy" zone of 10 pixels.
>> No code is needed, and you can then dock toolbars etc. along the edges of the form.
>
> I see.
>
> I changed a few things:
>
> TPanel paints its borders itself and sets AdjustClientRect. This was
> ignored when no childs were there. I fixed that bug. Now empty panels
> are autosized to 2,2 (the 1 pixel border).
> Panels without borders will autosize to 0,0, unless the interface
> limits this to 1,1 - like the gtk.

I tried to test, but rev. 24444 of the IDe does not compile; 
SourceEditor.pp does not compile.

After fixing that, I tested and would suggest a change (Delphi compatible):
in the IDE (when csDesigning is in ComponentState) the original
designed size should be kept.

I tried fiddling in lcl/include/wincontrol.inc around line 3379 :

     if WidthIsFixed or (PreferredWidth<0)
     or ((PreferredWidth=0) and (not (csAutoSize0x0 in ControlStyle)) and  (csDesigning in Componentstate)) then
       PreferredWidth:=Constraints.MinMaxWidth(Width);
     if HeightIsFixed or (PreferredHeight<0)
     or ((PreferredHeight=0) and (not (csAutoSize0x0 in ControlStyle)) and (csDesigning in Componentstate)) then
       PreferredHeight:=Constraints.MinMaxHeight(Height);

but can't get it to work :/

>
>> If lazarus is not compatible:
>> It means that I must put width/height=0 manually in the IDE (or do this when
>> the form is created), and enable autosizing as soon as the first control is
>> docked on the panel, and when a docked control is removed from the panel, I must
>> put width/height again to zero, manually.
>>
>> IMHO Autosize should do what it says at runtime, not with exceptions: fit the
>> children. If there are none: size=0. For aligned, this means just the
>> dimension which is orthogonal to the aligned dimension: alRight -> width=0.
>
> AutoSize means: use a nice size - the preferred size.
> For example a TLabel has no childs.

Good point. From the Delphi help for TControl.

"Specifies whether the control sizes itself automatically to accommodate its contents."

For TCustomLabel.AutoSize is adapted to say something about the text.

Michael.




More information about the Lazarus mailing list