Recent

Author Topic: Lazarus 2.1.0 svn, TLabel problems in designer  (Read 1735 times)

wp

  • Hero Member
  • *****
  • Posts: 8099
Re: Lazarus 2.1.0 svn, TLabel problems in designer
« Reply #15 on: January 10, 2021, 10:42:21 am »
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][+][-]
  1. // AAngle is in radians, counter-clockwise = positive. But: y points down!
  2. function RotatePoint(const APoint: TPoint; AAngle: Double): TPoint;
  3. var
  4.   sa, ca: Double;
  5. begin
  6.   sa := sin(AAngle);
  7.   ca := cos(AAngle);
  8.   Result.X := Round( ca * APoint.X + sa * APoint.Y);
  9.   Result.Y := Round(-sa * APoint.X + ca * APoint.Y);
  10. end;
  11.  
  12. procedure GetMinMax(x: Integer; var min, max: Integer);
  13. begin
  14.   if x < min then min := x;
  15.   if x > max then max := x;
  16. end;
  17.  
  18. function RotateRect(AWidth, AHeight: Integer; AAngle: Double): TRect;
  19. var
  20.   P1, P2, P3: TPoint;
  21. begin
  22.   if AAngle = 0 then
  23.     Result := Rect(0, 0, AWidth, AHeight)
  24.   else
  25.   begin
  26.     P1 := RotatePoint(Point(AWidth, 0), AAngle);
  27.     P2 := RotatePoint(Point(0, AHeight), AAngle);
  28.     P3 := Point(P1.X+P2.X, P1.Y+P2.Y);
  29.  
  30.     Result := Rect(0, 0, 0, 0);
  31.     GetMinMax(P1.X, Result.Left, Result.Right);
  32.     GetMinMax(P2.X, Result.Left, Result.Right);
  33.     GetMinMax(P3.X, Result.Left, Result.Right);
  34.     GetMinMax(P1.Y, Result.Top, Result.Bottom);
  35.     GetMinMax(P2.Y, Result.Top, Result.Bottom);
  36.     GetMinMax(P3.Y, Result.Top, Result.Bottom);
  37.   end;
  38. end;
« Last Edit: January 10, 2021, 11:08:45 am by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

jamie

  • Hero Member
  • *****
  • Posts: 4189
Re: Lazarus 2.1.0 svn, TLabel problems in designer
« Reply #16 on: January 10, 2021, 12:49:56 pm »
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..
« Last Edit: January 10, 2021, 12:57:56 pm by jamie »
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 8099
Re: Lazarus 2.1.0 svn, TLabel problems in designer
« Reply #17 on: January 10, 2021, 01:27:14 pm »
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.

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..
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.
« Last Edit: January 10, 2021, 01:32:42 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

jamie

  • Hero Member
  • *****
  • Posts: 4189
Re: Lazarus 2.1.0 svn, TLabel problems in designer
« Reply #18 on: January 10, 2021, 02:41:47 pm »
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 ?
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 8099
Re: Lazarus 2.1.0 svn, TLabel problems in designer
« Reply #19 on: January 10, 2021, 03:50:48 pm »
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.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

jamie

  • Hero Member
  • *****
  • Posts: 4189
Re: Lazarus 2.1.0 svn, TLabel problems in designer
« Reply #20 on: January 10, 2021, 04:21:58 pm »
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.


The only true wisdom is knowing you know nothing

funlw65

  • Jr. Member
  • **
  • Posts: 59
    • Visual Pin Configurator for Nucleo-L152RE
Re: Lazarus 2.1.0 svn, TLabel problems in designer
« Reply #21 on: January 17, 2021, 10:52:24 pm »
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!

 

TinyPortal © 2005-2018