Recent

Author Topic: How to show a Label in a ToolBar  (Read 5345 times)

Superdisk

  • Jr. Member
  • **
  • Posts: 73
How to show a Label in a ToolBar
« on: January 26, 2021, 12:22:43 am »
I have a toolbar with some buttons on it, but I also want to include a label. The when I add a label to the bar, it's stuck to the top and isn't centered in the bar like all the other button text.

How do I fix this? Also, how do I add padding between the label and other controls? BorderSpacing doesn't seem to work.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: How to show a Label in a ToolBar
« Reply #1 on: January 26, 2021, 01:19:03 am »
Put the label into a panel, and add the panel to the toolbar.

Superdisk

  • Jr. Member
  • **
  • Posts: 73
Re: How to show a Label in a ToolBar
« Reply #2 on: January 26, 2021, 01:30:43 am »
Appreciate the response, but that doesn't actually help anything. I then have to manually position/resize the panel which is the problem I'm trying to avoid with the label.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: How to show a Label in a ToolBar
« Reply #3 on: January 26, 2021, 03:10:32 am »
There is a TLabelEdit on the additional bar.
The only true wisdom is knowing you know nothing

Superdisk

  • Jr. Member
  • **
  • Posts: 73
Re: How to show a Label in a ToolBar
« Reply #4 on: January 26, 2021, 04:05:52 am »
There is a TLabelEdit on the additional bar.

Hey jamie, appreciate the response. Sadly the label of the TLabelEdit appears at the far left of the toolbar no matter what, which isn't correct.

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: How to show a Label in a ToolBar
« Reply #5 on: January 26, 2021, 11:21:00 am »
Appreciate the response, but that doesn't actually help anything. I then have to manually position/resize the panel which is the problem I'm trying to avoid with the label.
You did not say what your requirements are. I suppose you want the label to be centered vertically, with a few pixels distance to the neighboring toolbuttons. And from your screenshot I guess that you primarily want the label to be to the right of a TEdit.

As I said, add a TPanel, remove its bevel and its caption. Add a label and an edit to the panel. Using the anchor editor, anchor the label and the edit vertically to the center of the panel (this way they will always be centered). Anchor the left side of the label to the left side of the panel. Anchor the left side of the edit to the right side of the label, and anchor the right side of the edit to the right side of the panel. Use the BorderSpacings of the label and the edit (accessible also from within the anchor editor) to define the distance between the label and the edit, as well as the left and right distances to adjacent tool buttons. Set the panel's AutoSize to true; this will shrink (or expand) the size of the panel so that it closely surrounds the contained controls, respecting their borderspacings. If you want to change the size of edit you must specify a value for its Constraints.MinWidth. If you change the ButtonHeight of the Toolbar and the panel does not center set the panel's Constraints.MinHeight to the ButtonHeight.

Using an auxiliary panel is the only way how to add additional controls to a toolbar with some control on their positioning.

If you never worked with the anchor editor before this will be a great exercise. Remember: the anchor editor is the most important tool for self-adjusting layouts needed for cross-platform and theme-independent development.

« Last Edit: January 26, 2021, 11:23:00 am by wp »

Soner

  • Sr. Member
  • ****
  • Posts: 305
Re: How to show a Label in a ToolBar
« Reply #6 on: January 26, 2021, 12:14:31 pm »
Generic solution is put a Panel and adjust width.

Abelisto

  • Jr. Member
  • **
  • Posts: 91
Re: How to show a Label in a ToolBar
« Reply #7 on: January 26, 2021, 10:48:35 pm »
For the label: set Align property to alLeft; set Height property to ToolBar.Height - 2; Set Layout property to tlCenter; Add some spaces to begin/end of the Caption text
« Last Edit: January 26, 2021, 10:52:12 pm by Abelisto »
OS: Linux Mint + MATE, Compiler: FPC trunk (yes, I am risky!), IDE: Lazarus trunk

 

TinyPortal © 2005-2018