Lazarus 2.1.0 svn, TLabel problems in designer lazarus / 31-LCL ---------------------------------------------------------------------- funlw65 · 2021-01-07 08:24 I made a video clip that shows the problem, maybe devs know about it already... https://youtu.be/v-a7QVfvuKU Edit: I have to add that is Lazarus with Qt5 widgets. ---------------------------------------------------------------------- trev · 2021-01-07 09:28 You really need to log this in the Bugtracker. ---------------------------------------------------------------------- wp · 2021-01-07 09:35 I doubt that it ever worked in older versions, and even if it did it will not work in other widgetsets. The TLabel (and TStaticText) simply were not designed having totated text in mind. The rotation occurs around the top/left corner of the text and thus move the text out of the original bounds when the text is put vertically (I don't understand why QT5 does display at least part of the text - it should not). It is not difficult to fix -- see the attached demo. Instead of modifying the original TLabel I introduced a new TVertLabel which inherits from TLabel and thus has everything you know from TLabel (except for multiple lines and right-to-left). I override the Paint procedure to place the text at the correct position, and I override the CalculatePreferredSize method which does the AutoSize calculation (simly exchange Width and Height here). The TVertLabel also supports the Alignment and Layout properties. There is some ambiguity with what they mean in relation to rotated text. I decided to see them from the text perspective rather than from the screen perspective. P.S. Next time when you post a message please don't waste your time creating a video. It is certainly faster to type here all the text what you typed into the video, and when you add one or two screenshots everything is clear. The main objection against the video, however, is that it is stored outside the forum and will certainly be gone after some time. Since all your description is contained in this video the forum post will not be understandable any more for every user seeing your post after the video has disappeared from youtube. For those user who see this post: The video shows that vertical text is not displayed in a TLabel. ---------------------------------------------------------------------- funlw65 · 2021-01-07 10:26 Quote from: wp on January 07, 2021, 10:35:13 amI doubt that it ever worked in older versions, and even if it did it will not work in other widgetsets. The TLabel (and TStaticText) simply were not designed having in mind rotated text. The rotation occurs around the top/left corner of the text and thus move the text out of the original bounds when the text is put vertically. It is not difficult to fix -- see the attached demo. Instead of modifying the original TLabel I introduced a new TVertLabel which inherits from TLabel and thus has everything you know from TLabel. I override the Paint procedure to place the text at the correct position, and I override the CalculatePreferredSize method which does the AutoSize calculation (simly exchange Width and Height here). P.S. Next time when you post a message please don't waste your time creating a video. It is certainly faster to type here all the text what you typed into the video, and when you add one or two screenshots everything is clear. The main objection against the video, however, is that it is stored outside the forum and will certainly be gone after some time. Since all your description is contained in this video the forum post will not be understandable any more for every user seeing your post after the video has disappeared from youtube. For those user who see this post: The video shows that vertical text is not displayed in a TLabel. 1. Initially, I designed the form using gtk2 layer. It works perfectly in 2.0.10 both in 900 and 2600 rotation - two years of usage. In Lazarus 2.0.10 with Qt5 at least, the vertical labels designed previously in gtk2 are correctly displayed, without clipping the text as it does in 2.1.0. You can also resize the rectangle without the text to be clipped - this seems to be specific only to Lazarus 2.1.0 SVN so there are new bugs introduced. In 2.0.10 using Qt5 is the same problem with alignment (Top, Bottom, Center). Temporary solution is to continue using Lazarus 2.0.10, designing using gtk2 based components and compiling the project for Qt5. 2. Thank you for the code solution, it is highly appreciated and might be of use also to others but I have my reasons to use the visual components as they are (for that specific app of mine), the functionality is already there in those based on gtk2. 3. The movie will stay then, I see your point and this is how I do usually. Somehow, I was afraid that someone already exposed this TLabel bad behavior. But I completely disagree with you regarding the clarity of presentation. It is said that a picture values more than a thousand words, imagine how much value is in an entire animation that shows the problem more accurately. You know, English is not my native language, in video there is presented complex behavior, I would have done a lousy job trying to describe that with my own words and some screenshots (I know how hard is to show people what I want to say - I know, I've already posted two threads ). ---------------------------------------------------------------------- funlw65 · 2021-01-07 11:22 Quote from: trev on January 07, 2021, 10:28:12 amYou really need to log this in the Bugtracker. I don't even know where to categorize it... LazarusIDE? LCL? ---------------------------------------------------------------------- balazsszekely · 2021-01-07 12:11 @funlw65 Quote2. Thank you for the code solution, it is highly appreciated and might be of use also to others but I have my reasons to use the visual components as they are (for that specific app of mine), the functionality is already there in those based on gtk2. Using @wp's solution, create a new component(TLabelEx for example) then add it to a package. After the package is installed into the IDE, with a text editor replace TLabel to TLabelEx (*.dfm). Now you have a new visual component, an extended label with all the functionality you need. ---------------------------------------------------------------------- funlw65 · 2021-01-07 12:28 Thank you @GetMem this open source project is supposed to use standard components, without forcing the users (that might not know Pascal and Lazarus) to install additional packages. The users will know at least C language, used to program microcontrollers. There are few reasons why I used procedural programming: 1. Speed. I had to present an working prototype fast, to honor a promise I made on ST Microelectronics forum (I chose Lazarus as it offers a Borland like Visual Component interface which in my opinion is the most advanced in the world); 2. The portability of the entire idea, that could be implemented in any RAD application (no matter the language) so, no specific objectual code. 3. Last time I used pascal objectual programing was with Turbo 7.0 and TurboVision - long time ago. ---------------------------------------------------------------------- funlw65 · 2021-01-07 16:52 Quote from: wp on January 07, 2021, 10:35:13 amThe TLabel (and TStaticText) simply were not designed having rotated text in mind. I've seen this statement two years ago, when I was looking for vertical labels... I understand that if there already is the basic thing implemented (and by that I mean all the functionality the original TLabel offers), then it does not hurt having also extra properties/behavior. I mean, I see the meaning of offering support for Delphi programs that must be converted to Lazarus but not the other way around. If you don't play the dominant male game, you will never be the dominant male. I don't know if Embarcadero facilitates any migration from them to whatever alien tool. So I don't see the logic of that statement. MSEGUI has nice support for vertical labels, it works wonders. So there is native support for a future LCL TLabel based on MSEGUI. That would be awesome if CustomDrawn means too much work. ---------------------------------------------------------------------- wp · 2021-01-07 17:24 My Delphi 7 does not even have an Orientation field in TFont. XE2 has it, but the TLabel does not work when the font is rotated, similar to the LCL. Only in the most recent version that I have, XE 10.3, rotation works correctly, even for arbitrary angles, however only for single-line labels. In the multi-line case, it goes crazy again. ---------------------------------------------------------------------- JuhaManninen · 2021-01-07 17:51 Quote1. Initially, I designed the form using gtk2 layer. It works perfectly in 2.0.10 both in 900 and 2600 rotation - two years of usage. In Lazarus 2.0.10 with Qt5 at least, the vertical labels designed previously in gtk2 are correctly displayed, without clipping the text as it does in 2.1.0. You can also resize the rectangle without the text to be clipped - this seems to be specific only to Lazarus 2.1.0 SVN so there are new bugs introduced. Quote from: funlw65 on January 07, 2021, 12:22:13 pmI don't even know where to categorize it... LazarusIDE? LCL? It would be LCL. I understood there is a regression with widgetset QT5. It should be fixed. When a bug report is for a specific widgetset, it should be mentioned also in the header. Otherwise it may get buried in attributes. The best scenario is that somebody bisects the guilty revision causing a bug, but that is a laborous process with a long commit history. ---------------------------------------------------------------------- funlw65 · 2021-01-07 18:57 Thank you Juha in helping me doing my part! Now I don't know if I did it right, but I did it https://bugs.freepascal.org/view.php?id=38328 ---------------------------------------------------------------------- wp · 2021-01-09 12:20 I fixed the issue. Please test the new label and close the bug report if it is ok. I tested on Windows, but since it is widgetset- independent code it must work for all widgetsets. ---------------------------------------------------------------------- trev · 2021-01-09 22:53 Tested OK on macOS (Cocoa widgetset) ---------------------------------------------------------------------- wp · 2021-01-10 00:05 Thanks for testing. ---------------------------------------------------------------------- jamie · 2021-01-10 01:37 I haven't yet looked but is the label's area using the Sqrt(X^ + Y^) etc for the max reach on the angles? ---------------------------------------------------------------------- wp · 2021-01-10 09:42 No, this is too simple because I also need the location of the rotation center inside the bounding rectangle. The rotation center (point a) is the top/left corner of the rectangle enclosing the unrotated text. I am rotating the other points (b, c, d) around a which results in the rotated points B, C, D. Then the bounding rectangle of the rotated text is given by Left = Min(A.X, B.X, C.X, D.X), Right = Max(A.X, B.X, C.X, D.X), Top = Min(A.Y, B.Y, C.Y, D.Y), Bottom = Max(A.Y, B.Y, C.Y, D.Y). The text start point must be offset by the left and top coordinated relative to the top/left corner of the rotated bounding rectangle. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // AAngle is in radians, counter-clockwise = positive. But: y points down!function RotatePoint(const APoint: TPoint; AAngle: Double): TPoint;var  sa, ca: Double;begin  sa := sin(AAngle);  ca := cos(AAngle);  Result.X := Round( ca * APoint.X + sa * APoint.Y);  Result.Y := Round(-sa * APoint.X + ca * APoint.Y);end; procedure GetMinMax(x: Integer; var min, max: Integer);begin  if x < min then min := x;  if x > max then max := x;end; function RotateRect(AWidth, AHeight: Integer; AAngle: Double): TRect;var  P1, P2, P3: TPoint;begin  if AAngle = 0 then    Result := Rect(0, 0, AWidth, AHeight)  else  begin    P1 := RotatePoint(Point(AWidth, 0), AAngle);    P2 := RotatePoint(Point(0, AHeight), AAngle);    P3 := Point(P1.X+P2.X, P1.Y+P2.Y);     Result := Rect(0, 0, 0, 0);    GetMinMax(P1.X, Result.Left, Result.Right);    GetMinMax(P2.X, Result.Left, Result.Right);    GetMinMax(P3.X, Result.Left, Result.Right);    GetMinMax(P1.Y, Result.Top, Result.Bottom);    GetMinMax(P2.Y, Result.Top, Result.Bottom);    GetMinMax(P3.Y, Result.Top, Result.Bottom);  end;end; ---------------------------------------------------------------------- jamie · 2021-01-10 11:49 ok, looking at some experiments I just did it would appear a label being flipped 180 degrees is moving its starting point to the right now instead of the left ?  So this means the starting point of the label will be changed ?  I guess that is ok for design time and static formation at runtime but does a rotation change at runtime also follows ? P.S.   I just tested that and I think you should look at that theory again..    The X,Y rotation point is moving on the screen.   most software that rotates their text will expect the starting point of the text to be in the same location always. I know I do the same and this will not work for me.. ---------------------------------------------------------------------- wp · 2021-01-10 12:27 The starting point (left/top of the first character) MUST move relative to the bounds of the control because otherwise you would rotate the text out of the bounds - that was the situation before the recent changes. My understanding of the text positioning with Alignment and Layout within some bounds rectangle is that the text direction defines how the text is displayed within the text-enclosing rect, and Alignment and Layout define where this text-enclosing rect is positioned within the bounds-rectangle (hard to explain...). This is the same mechanism as used by Delphi. Quote from: jamie on January 10, 2021, 12:49:56 pmmost software that rotates their text will expect the starting point of the text to be in the same location always. I know I do the same and this will not work for me.. TLabel is not a text component as used by graphics software. For this it would need more properties to define the rotation center. Currently the fixed point is given by anchoring. By default the label has left and top anchors, i.e. the left/top corner of the control stays at the same location for all text directions -- but this is not necesssarily the same as the top/left corner of the text. ---------------------------------------------------------------------- jamie · 2021-01-10 13:41 You are correct in that assertion, Delphi does do it the same way but does not make it correct.. as they have done mistakes themselves..  if you use a Label in a cad program it is expected to be oriented always from the left,top axes which I believe one of the concerns here was that it was simply just hiding because of the bounding rectangle..  What does this mean? I means the person that brought up the issue now has another issue, the axes is moving and thus no longer follows the paths of the settings..  You may think a TLABEL is just a design static thing but its not, it's actually used dynamically too and in cases like this it's going to cause an issue.. So basically what's left is the user will need to devise their own label output to make it work correctly..  is it possible to have an option ENUM in there or property to select this behavior, because I can see problems still brewing with this ? ---------------------------------------------------------------------- wp · 2021-01-10 14:50 I'd say 95% of all applications use horizontal labels. 4.9% use vertical labels, 0.1% use rotation by some odd angle. So, 95% of all labels worked correctly before the change, additional 4.9% will work correctly after the change, 0.1% will have to think about the origin at which they have to place the label. Why bloat TLabel with another property which is probably for 0.1% of all users, and this only if they don't think. The person who brought this up, uses vertical labels, he can anchor the labels to the pins of his Integrated Circuit image, and the labels will remain there on all platforms and for all form sizes. So he will be happy. ---------------------------------------------------------------------- jamie · 2021-01-10 15:21 Ok, then I guess I will have to make my own label control because I have been using the label for some time now in different orientations since that feature came into being only I was doing it via the OS level in the old Delphi because it didn't have a orientation option in it so I was adjusting the rectangle to fix the angle which works great..  so since I saw that in the LCL this option was there and it seem to work well I was simply adjusting the rectangle so it would show at runtime because the labels I use are runtime items along with other things I drag and drop on the drawing area..  That's fine, I'll just have to create a custom control and replace what I have now, as we already have static text labels but now I guess we have two. ---------------------------------------------------------------------- funlw65 · 2021-01-17 21:52 After the Lazarus IDE recompilation, loading the project, I can see the vertical labels showing correctly. Thank you @wp and I appologise for the lack of response, I have some family problems!