Forum > Graphics

[SOLVED] TLabeledEdit.EditLabel.Layout not working

(1/5) > >>


On the image below one can see 3 TLabeledEdit with 0 code, just setup in the Object's Inspector with Alignment : taLeftJustify, taCenter, taRightJustify and everything's well working.

But trying with EditLabel.Layout and using tlBottom (led1) or tlCenter (led2) or tlTop (led3), I cannot see the EditLabel moving up and down...

Same behaviour in Linux Debian Bullseye 11.8 and Windows Seven64 bits, with FPC 3.2.2, Lazarus 2.2.6 and Gtk 2.8.

What can I do ?


I just tested it with my Lazarus 2.2.6 GTK2 on Ubuntu Mate 23.10, same result. Changing the Layout had no effect. I think it is a bug.

I would not call it a bug, but the price to be paid for the laziness to position an edit and a label in a single operation. And vertical centering a label at the left or right of the edit is the most natural way to do it. This way it is hard-coded in the TCustomLabeledEdit, and showing the Layout property in the object inspector is just because it is published by TLabel, but it has no effect any more due to anchoring.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TCustomLabeledEdit.DoPositionLabel;begin  ...  case FLabelPosition of    ...    lpLeft :       begin        FEditLabel.AnchorToCompanion(akRight,FLabelSpacing,Self);        FEditLabel.AnchorVerticalCenterTo(Self);       end;     lpRight:      begin        FEditLabel.AnchorToCompanion(akLeft,FLabelSpacing,Self);        FEditLabel.AnchorVerticalCenterTo(Self);       end;   end;  ...end; If you want full control over positions you still can use separate TLabel and TEdit controls.

Well, thanks for your answers.

--- Quote from: wp on December 05, 2023, 11:10:25 am ---If you want full control over positions you still can use separate TLabel and TEdit controls.
--- End quote ---
it is not what I want.
What I want ("What God wants" sings Roger Waters, lol) is... read that, found in the Objects' Inspector little help :

--- Quote ---Layout is a TTextLayout property with the vertical alignment used for the text displayed in the control. The default value for the property is tlTop. Changing the value in Layout causes the Invalidate method to be called to redraw the control.

Use the Alignment property to control the horizontal alignment for the text in the control.
--- End quote ---
Both sentences come together as if they were God's speech but the first is wrong, and both are displayed without writing one word 'bout the problem.

So please update that help and we will no more spend (loose ?) time trying to work with something broken.
EDIT : or better, modify a little bit the component and hide that option and the related help. /EDIT

Since it would be more work to document the removal of the Layout property of the EditLabel (since removing a published property is a code-breaking change) than to fix the issue, I decided to remove the vertical anchoring of the label to the edit's center and to change the default of EditLabel.Layout to tlCenter so that there is no change to the current visual situation. Now EditLabel.Layout is working.

And while doing this I noticed that there is no Alignment property for the label to allow horizontal adjustment when the label is above or below the edit. This was also an easy change. (TLabeledEdit.EditLabel.Alignment is independent of TLabeledEdit.Alignment)

Please test with Laz/main, it should work. See the attached screenshot.

But still: TLabeledEdit is a component that I would not use. Look what happens when the label is above/below the edit and is longer than the edit's width. Or when the label is at the left/right and consists of multiple lines. Or when you use the Anchor Editor to anchor the top of a LabeledEdit (with top label) to the top of its parent...


[0] Message Index

[#] Next page

Go to full version