Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-11

Centered elements in autosize enabled panel. Possible?

22 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Valdas Jankūnas

Hello,

I want to create this layout:
- form has a Panel;
- "Autosize" of Panel is True;
- Panel has Controls with various heights;
- every Control in Panel must be centered vertically.

I tried this (trough Anchor editor):
- Control2 centered to Control1;
- Control1 centered to Panel.
But then Panel shrinks to Height=2 (circular align happens?).

Is it possible to create mentioned layout (preferably not through code)?

Sorry for bad English.

Valdas Jank?nas

Reply by email

Valdas Jankūnas
to Avishai

2013.11.09 22:52, Avishai ra??:

OK. I tried putting 2 Labels Align:= alLeft. For both Labels I set BorderSpacing Left and Right := 10 and Layout := tlCenter. Then I set Panel.AutoSize := True. It looks like it does what you want.

It works! Even with autosized Buttons or Edits.

Thanks!

Valdas Jank?nas

Reply by email

Avishai
to Valdas Jankūnas

Glad I could help :)

Valdas Jank?nas wrote 21 lines
2013.11.09 22:52, Avishai ra??: > OK. I tried putting 2 Labels Align:= alLeft. For both Labels I set > BorderSpacing Left and Right := 10 and Layout := tlCenter. Then I set > Panel.AutoSize := True. It looks like it does what you want. > It works! Even with autosized Buttons or Edits. Thanks! -- Valdas Jank?nas -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Shalom, Avishai ????? ???? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131109/1955a4b1/attachment.html>

Reply by email

William Oliveira Ferreira
to Valdas Jankūnas: 2013.11.09 22:52, Avishai ra??: It works! Even with autosized Buttons or Edits. Thanks!…

I think you could also use anchors

"Valdas Jank?nas" wrote 21 lines
2013.11.09 22:52, Avishai ra??: > OK. I tried putting 2 Labels Align:= alLeft. For both Labels I set > BorderSpacing Left and Right := 10 and Layout := tlCenter. Then I set > Panel.AutoSize := True. It looks like it does what you want. > It works! Even with autosized Buttons or Edits. Thanks! -- Valdas Jank?nas -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131110/65673db0/attachment.html>

Reply by email

Valdas Jankūnas
to William Oliveira Ferreira

2013.11.10 18:24, William Oliveira Ferreira ra??:

I think you could also use anchors

Anchors not helps if Parent.Autosize is True.

I found better solution:
- Panel.AutoSize := True;
- Panel.ChildSizing.ControlsPerLine := MaxInt;
- Panel.ChildSizing.Layout := cclLeftToRightThenTopToBottom;
- Every Child.BorderSpacing.Left := 2;
- Every Child.BorderSpacing.CellAlignVertical := ccaCenter;
- Every Child.AutoSize := True;

If you want to adjust Child's Width (by default you cannot) then you must use overridden procedure "CalculatePreferredSize" in class of that Child, in which:

    inherited CalculatePreferredSize(PreferredWidth, PreferredHeight,
WithThemeSpace);
    PreferredWidth := Width;
Valdas Jank?nas

Reply by email

Avishai
to Valdas Jankūnas

You can also use Constraints to set height/width of children with ChildSizing.

Valdas Jank?nas wrote 35 lines
2013.11.10 18:24, William Oliveira Ferreira ra??: I think you could also use anchors > Anchors not helps if Parent.Autosize is True. I found better solution: - Panel.AutoSize := True; - Panel.ChildSizing.ControlsPerLine := MaxInt; - Panel.ChildSizing.Layout := cclLeftToRightThenTopToBottom; - Every Child.BorderSpacing.Left := 2; - Every Child.BorderSpacing.CellAlignVertical := ccaCenter; - Every Child.AutoSize := True; If you want to adjust Child's Width (by default you cannot) then you must use overridden procedure "CalculatePreferredSize" in class of that Child, in which: inherited CalculatePreferredSize(PreferredWidth, PreferredHeight, WithThemeSpace); PreferredWidth := Width; -- Valdas Jank?nas -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Shalom, Avishai ????? ???? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131110/a21d5a28/attachment.html>

Reply by email

Avishai
to Avishai

What I don't like about ChildSizing is if you need to change the order of controls it can be difficult. And here's something you should try. Have a TPanel as one of the Children - get everything set the way you want with ChildSizing - now add a TLabel to the TPanel.

Using LeftAlign it's only a matter of dragging the control to the location you want. BorderSpacing and Constraints gives me all the control I need (so far - I'm still playing with it).

Avishai wrote 50 lines
You can also use Constraints to set height/width of children with ChildSizing. On Sun, Nov 10, 2013 at 10:43 PM, Valdas Jank?nas wrote: > 2013.11.10 18:24, William Oliveira Ferreira ra??: > > I think you could also use anchors >> > > Anchors not helps if Parent.Autosize is True. > > I found better solution: > - Panel.AutoSize := True; > - Panel.ChildSizing.ControlsPerLine := MaxInt; > - Panel.ChildSizing.Layout := cclLeftToRightThenTopToBottom; > - Every Child.BorderSpacing.Left := 2; > - Every Child.BorderSpacing.CellAlignVertical := ccaCenter; > - Every Child.AutoSize := True; > > > If you want to adjust Child's Width (by default you cannot) then you must > use overridden procedure "CalculatePreferredSize" in class of that Child, > in which: > > inherited CalculatePreferredSize(PreferredWidth, PreferredHeight, > WithThemeSpace); > PreferredWidth := Width; > > > > -- > Valdas Jank?nas > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -- Shalom, Avishai ????? ????
Shalom, Avishai ????? ???? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131110/02c9ae0b/attachment.html>

Reply by email

Valdas Jankūnas
to Avishai: You can also use Constraints to set height/width of children with ChildSizing. Avishai…

2013.11.10 23:03, Avishai ra??:

You can also use Constraints to set height/width of children with ChildSizing.

Forgot about that, thanks.

One problem left: when you add TBevel as child and if you want it BorderSpacing.CellAlignVertical=ccaFill (to make separator), you get fixed height (always 50). To fix this I must use custom TBevel with overridden "CalculatePreferredSize" with "PreferredHeight := 1;" in it.

Is there more elegant way?

Valdas Jank?nas

Reply by email

Avishai
to Valdas Jankūnas

Hmmm. I tried setting TBevel .borderSpacing.Around:= 4 and it suddenly "corrected" itself. I'm not too sure I trust that approach but you can play with it and see.

Valdas Jank?nas wrote 25 lines
2013.11.10 23:03, Avishai ra??: You can also use Constraints to set height/width of children with > ChildSizing. > Forgot about that, thanks. One problem left: when you add TBevel as child and if you want it BorderSpacing.CellAlignVertical=ccaFill (to make separator), you get fixed height (always 50). To fix this I must use custom TBevel with overridden "CalculatePreferredSize" with "PreferredHeight := 1;" in it. Is there more elegant way? -- Valdas Jank?nas -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Shalom, Avishai ????? ???? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131111/d5988735/attachment-0001.html>

Reply by email

Avishai
to Avishai
Well?  I forgot that I had set Constraints.MaxHeight:= 24 before I set b
orderSpacing.Around:= 4.  Then I changed MaxHeight:= 20 and it went back to
Height:= 50.
Then I reset MaxHeight:= 24 and borderSpacing.Around:= 0 and it jumped back
to a height of 24.  I don't think that's an answer.  I'll keep looking.
Avishai wrote 41 lines
Hmmm. I tried setting TBevel .borderSpacing.Around:= 4 and it suddenly "corrected" itself. I'm not too sure I trust that approach but you can play with it and see. On Mon, Nov 11, 2013 at 12:01 AM, Valdas Jank?nas wrote: > 2013.11.10 23:03, Avishai ra??: > > You can also use Constraints to set height/width of children with >> ChildSizing. >> > > Forgot about that, thanks. > > One problem left: when you add TBevel as child and if you want it > BorderSpacing.CellAlignVertical=ccaFill (to make separator), you get > fixed height (always 50). To fix this I must use custom TBevel with > overridden "CalculatePreferredSize" with "PreferredHeight := 1;" in it. > > Is there more elegant way? > > > -- > Valdas Jank?nas > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -- Shalom, Avishai ????? ????
Shalom, Avishai ????? ???? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131111/f2ebb0bf/attachment.html>

Reply by email

Avishai
to Avishai

Could you use a TPanel in place of the TBevel? I tried that and it gives the same visual effect without the size problems. But I don't know what you are doing with the TBevel.

Avishai wrote 60 lines
Well? I forgot that I had set Constraints.MaxHeight:= 24 before I set b orderSpacing.Around:= 4. Then I changed MaxHeight:= 20 and it went back to Height:= 50. Then I reset MaxHeight:= 24 and borderSpacing.Around:= 0 and it jumped back to a height of 24. I don't think that's an answer. I'll keep looking. On Mon, Nov 11, 2013 at 12:09 AM, Avishai wrote: > Hmmm. I tried setting TBevel .borderSpacing.Around:= 4 and it suddenly > "corrected" itself. I'm not too sure I trust that approach but you can > play with it and see. > > > On Mon, Nov 11, 2013 at 12:01 AM, Valdas Jank?nas wrote: > >> 2013.11.10 23:03, Avishai ra??: >> >> You can also use Constraints to set height/width of children with >>> ChildSizing. >>> >> >> Forgot about that, thanks. >> >> One problem left: when you add TBevel as child and if you want it >> BorderSpacing.CellAlignVertical=ccaFill (to make separator), you get >> fixed height (always 50). To fix this I must use custom TBevel with >> overridden "CalculatePreferredSize" with "PreferredHeight := 1;" in it. >> >> Is there more elegant way? >> >> >> -- >> Valdas Jank?nas >> >> -- >> _______________________________________________ >> Lazarus mailing list >> >> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus >> > > > > -- > Shalom, > Avishai > > ????? ???? > -- Shalom, Avishai ????? ????
Shalom, Avishai ????? ???? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131111/ca0a6827/attachment.html>

Reply by email

Valdas Jankūnas
to Avishai

2013.11.11 06:06, Avishai ra??:

Could you use a TPanel in place of the TBevel? I tried that and it gives the same visual effect without the size problems. But I don't know what you are doing with the TBevel.

Hello,

I use TBevel as separator (Shape=bsLeftLine) between components. I tried TPanel: looks good, also its Width automatically adjusts to 2 when "CellAlighHorizontal" is set to other than "ccaFill".

  Also I found how to rearrange Childs easily when "ChildSizing" is used:
- Parent.ChildSizing set to "cclNone";
- change "Z order" of Child;
- revert back Parent.ChildSizing.
  I found why TBevel "doesn't want" shrink less than 50px: TBevel has
function "GetControlClassDefaultSize" where "Result.CY := 50;" is hardcoded.
Valdas Jank?nas

Reply by email

Avishai
to Valdas Jankūnas

Most of my applications are for RightToLeft (Hebrew) and TToolBar and TStatusBar don't support RightToLeft so I use this technique to make my own. I use the Align:= alLeft/alRight method though. And I use TPanel for dividers.

Valdas Jank?nas wrote 31 lines
2013.11.11 06:06, Avishai ra??: Could you use a TPanel in place of the TBevel? I tried that and it gives > the same visual effect without the size problems. But I don't know what > you are doing with the TBevel. > Hello, I use TBevel as separator (Shape=bsLeftLine) between components. I tried TPanel: looks good, also its Width automatically adjusts to 2 when "CellAlighHorizontal" is set to other than "ccaFill". Also I found how to rearrange Childs easily when "ChildSizing" is used: - Parent.ChildSizing set to "cclNone"; - change "Z order" of Child; - revert back Parent.ChildSizing. I found why TBevel "doesn't want" shrink less than 50px: TBevel has function "GetControlClassDefaultSize" where "Result.CY := 50;" is hardcoded. -- Valdas Jank?nas -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Shalom, Avishai ????? ???? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131111/fe7942e7/attachment.html>

Reply by email

Valdas Jankūnas
to Mattias Gaertner

2013.11.11 13:14, Mattias Gaertner ra??:

Show quoted text 12 lines
On Mon, 11 Nov 2013 12:51:14 +0200 Valdas Jank?nas wrote: > 2013.11.11 06:06, Avishai ra??: > [...] > I found why TBevel "doesn't want" shrink less than 50px: TBevel has > function "GetControlClassDefaultSize" where "Result.CY := 50;" is hardcoded. That's the default size of the control. The constraints are applied after. A TBevel can be shrinked to less than 50.

It not shrinks when ChildSizing is being used (see screenshot).

Valdas Jank?nas -------------- next part -------------- A non-text attachment was scrubbed... Name: nuotrauka4.jpg Type: image/jpeg Size: 63796 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131111/a40f250c/attachment-0001.jpg>

Reply by email

Mattias Gaertner
to Valdas Jankūnas
Show quoted text 15 lines
2013.11.11 13:14, Mattias Gaertner ra??: > On Mon, 11 Nov 2013 12:51:14 +0200 > Valdas Jank?nas wrote: > >> 2013.11.11 06:06, Avishai ra??: >> [...] >> I found why TBevel "doesn't want" shrink less than 50px: TBevel has >> function "GetControlClassDefaultSize" where "Result.CY := 50;" is hardcoded. > > That's the default size of the control. The constraints are > applied after. > > A TBevel can be shrinked to less than 50. It not shrinks when ChildSizing is being used (see screenshot).

Your bevel has no content. Then the default size is used. Drop something into it.

Mattias

Reply by email

Avishai
to Mattias Gaertner

I don't *think* that will work. TBevel is TGraphicControl so it's not a "container".

On Mon, Nov 11, 2013 at 2:25 PM, Mattias Gaertner <

Show quoted text 34 lines
wrote: On Mon, 11 Nov 2013 14:18:53 +0200 Valdas Jank?nas wrote: > 2013.11.11 13:14, Mattias Gaertner ra??: > > On Mon, 11 Nov 2013 12:51:14 +0200 > > Valdas Jank?nas wrote: > > > >> 2013.11.11 06:06, Avishai ra??: > >> [...] > >> I found why TBevel "doesn't want" shrink less than 50px: TBevel has > >> function "GetControlClassDefaultSize" where "Result.CY := 50;" is hardcoded. > > > > That's the default size of the control. The constraints are > > applied after. > > > > A TBevel can be shrinked to less than 50. > > It not shrinks when ChildSizing is being used (see screenshot). Your bevel has no content. Then the default size is used. Drop something into it. Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Shalom, Avishai ????? ???? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20131111/986fc3a8/attachment.html>

Reply by email