[Lazarus] TPanel bevel and client size

Mattias Gärtner nc-gaertnma at netcologne.de
Fri Feb 12 11:17:20 CET 2010


Zitat von cobines <cobines at gmail.com>:

> 2010/2/12 Mattias Gärtner <nc-gaertnma at netcologne.de>:
>> Zitat von cobines <cobines at gmail.com>:
>>
>>> 2010/2/12 Paul Ishenin <ip at kmiac.ru>:
>>>>
>>>> Bevels reduce ClientRect by BevelSize value.
>>>
>>> I thought so that they're supposed to do that, but if I put a TPanel
>>> on a form with a outer bevel set to Lowered , the panel's ClientHeight
>>> = Height.
>>
>> Bevel reduces the AdjustClientRect, which is ClientRect minus the Bevels.
>> ClientWidth is the client area width from the widgetset. The bevels are
>> custom drawn by TPanel and therefore not in the ClientWidth of TPanel.
>>
>
> Ok, that clears up why ClientWidth=Width. But why the bevels are
> included in ClientRect? I think child controls are not supposed to
> occupy the bevels' space. Can the ClientWidth, ClientHeight from the
> widgetset be adjusted to include bevels?

The widgetset values should only include the widgetset things.

Maybe you want new properties AdjustedClientWidth,  
AdjustedClientHeight. Changing ClientWidth/ClientHeight would be a big  
change and some third party controls rely on that.
Note: The LCL ClientWidth/Height are not compatible to the VCL, so  
Delphi compatibility is irrelevant here.


> For example if I want to check how much space is in the Panel for a
> control, I do:
>
> SpaceAvailable := Panel.ClientHeight;
> if SpaceAvailable >= 100 then
>   ShowMyControl_of_size_100_or_more (because I'm sure it will fit)
> else
>   HideMyControl... (don't want to show it partially)
>
> (The Panel size is controlled by the user.)
>
> However, if TPanel contains bevels then the space available for the
> child control is ClientHeight - BevelSize * 2. I have to take it into
> account when calculating space. Otherwise, either my control will not
> be fully shown, or it will be drawn over the bevels. Is there some
> other property I can check that will include all borders, bevels,
> etc.?

r:=ClientRect;
AdjustClientRect(r);
SpaceAvailable:=r.Right-r.Left;

Did you know, that you can anchor controls:
MyControl.AnchorParallel(akLeft,0,MyControl.Parent);
MyControl.AnchorParallel(akRight,0,MyControl.Parent);

This will expand MyControl to the full client area width, excluding  
the bevels.


>>>> BevelSize is used to calculate the ClientRect in
>>>> TCustomPanel.AdjustClientRect.
>>>
>>> Yes, that function recalculates the rectangle correctly, but it seems
>>> it's somehow not propagated to the auto size algorithm or to the
>>> stored client rectangle.
>>
>> The autosize algorithm uses AdjustClientRect.
>
> It still puts child controls over the bevels. I don't know, maybe I'm
> confusing it with aligning child controls. It is supposed to either
> make the child control smaller so that it doesn't overwrite the
> bevels, or make the TPanel bigger so that the child control fits in
> whole and there's still space left for the bevels.

It works here on a simple example. Child controls are not on the  
bevels but within the bevels with autosize=true on gtk2.


>> Please add an example to demonstrate the problem.
>
> I have found an already existing bug on this with a good example. But
> it said the problem is only for BevelWidth > 1 and only for GTK, GTK2.
> I confirmed this issue also on QT and with any bevel width. I'll check
> later on Win32.
>
> Unfortunately Mantis died on me while I was reading it so I didn't get
> the bug number. Will try later.

Thanks.

Mattias






More information about the Lazarus mailing list