TAtSynEdit - Get Total Height in Pixels of All Wrapped Text

TomC
Posts: 13
Joined: 29.05.2022 05:11

TAtSynEdit - Get Total Height in Pixels of All Wrapped Text

Post by TomC »

I have a TPanel, with a Child TAtSynEdit set to alClient

I would like to adjust the TPanel height, just enough, to show all text in AtSynEdit, without any extra blank space at bottom.

So, I need to figure out total height of TAtSynEdit Text, even if it's Wrapped...

Here's what I have so far, but, not able to get the right calculation:

Code: Select all

procedure AdjustPanelHeightToShowAllText;
var LineCount: Integer;
begin
    Syn.Text:=Trim(Syn.Text);
    // LineCount:=Syn.Strings.Count;  { Better Get Count from Next Line? }
    LineCount:=Syn.WrapInfo.Count; //-1;
    Panel.Height:=Abs(Syn.Font.Height) * LineCount;
end;
Any Ideas?

Thank You Sincerely.
main Alexey
Posts: 2549
Joined: 25.08.2021 18:15

Re: TAtSynEdit - Get Total Height in Pixels of All Wrapped Text

Post by main Alexey »

1. try to change Abs(Font.Height) to FEditor.TextCharSize.Y.
2. if idea 1 don't help: use FEditor.CaretPosToClientPos for text position (0, FEditor.Strings.Count-1). you will get coord of top-of-last-line. Add there FEditor.TextCharSize.Y.

Idea 2 is best if user has interline gaps (Gaps object), also idea 2 is best if user has folded lines (e.g. from lexer).
TomC
Posts: 13
Joined: 29.05.2022 05:11

Re: TAtSynEdit - Get Total Height in Pixels of All Wrapped Text

Post by TomC »

by main Alexey:

1. try to change Abs(Font.Height) to FEditor.TextCharSize.Y.
2. if idea 1 don't help: use FEditor.CaretPosToClientPos for text position (0, FEditor.Strings.Count-1).
You will get coord of top-of-last-line. Add there FEditor.TextCharSize.Y.

Idea 2 is best if user has interline gaps (Gaps object), also idea 2 is best if user has folded lines (e.g. from lexer).
Thank You!
Idea 2, appears to be working well.

Out of curiosity, is there any type of "Line Spacing" property for space between lines?
main Alexey
Posts: 2549
Joined: 25.08.2021 18:15

Re: TAtSynEdit - Get Total Height in Pixels of All Wrapped Text

Post by main Alexey »

Of course,
property OptSpacingY.
main Alexey
Posts: 2549
Joined: 25.08.2021 18:15

Re: TAtSynEdit - Get Total Height in Pixels of All Wrapped Text

Post by main Alexey »

One correction: CaretPosToClientPos must be called for position at the very end. to consider that last line is wrapped too.
Pos:

Code: Select all

N = FEditor.Strings.Count-1;
PosEnd = Point(FEditor.Strings.LinesLen[N], N);
TomC
Posts: 13
Joined: 29.05.2022 05:11

Re: TAtSynEdit - Get Total Height in Pixels of All Wrapped Text

Post by TomC »

main Alexey wrote: 16.06.2024 09:17 One correction: CaretPosToClientPos must be called for position at the very end. to consider that last line is wrapped too.
Pos:

Code: Select all

N = FEditor.Strings.Count-1;
PosEnd = Point(FEditor.Strings.LinesLen[N], N);
Thank you for the reply.
I know my following procedure is not correct..

Code: Select all

procedure TFMain.AdjustTopHeight;
var LC, LH, TH: Integer; P: TAtPoint;
begin with SynTop do begin
  P:=Default(TAtPoint);
  Text:=Trim(Text);
  LC:=Strings.Count-1; {Line Count}
  LH:=TextCharSize.Y; {Line Height}
  P:=CaretPosToClientPos(Point(Strings.LinesLen[LC],LC)); {Point at the End of the Text}
  PanTop.Height:=P.y;
end; end;
I can see that P.x is Line Length of last line, and P.y is vertical position of last line..
But, how to set Height of Parent Panel, I could only think of P.y
main Alexey
Posts: 2549
Joined: 25.08.2021 18:15

Re: TAtSynEdit - Get Total Height in Pixels of All Wrapped Text

Post by main Alexey »

I did not understand the question.
how to set the height of parent panel? use P.Y, and maybe add there LH (height of one line).
TomC
Posts: 13
Joined: 29.05.2022 05:11

Re: TAtSynEdit - Get Total Height in Pixels of All Wrapped Text

Post by TomC »

main Alexey wrote: 16.06.2024 10:40 I did not understand the question.
how to set the height of parent panel? use P.Y, and maybe add there LH (height of one line).
Correct, My intention is to size AtSynEdit's Parent Panel, so AtSynEdit (aligned as alClient) can show all of it's text.

I will give (P.Y + LH) a try.

Thank You,
Sincerely.
main Alexey
Posts: 2549
Joined: 25.08.2021 18:15

Re: TAtSynEdit - Get Total Height in Pixels of All Wrapped Text

Post by main Alexey »

(maybe add 2 pixels for the border, if ATSynedit shows the border)
TomC
Posts: 13
Joined: 29.05.2022 05:11

Re: TAtSynEdit - Get Total Height in Pixels of All Wrapped Text

Post by TomC »

Quote: (maybe add 2 pixels for the border, if ATSynedit shows the border)

Good Thinking..

Hey, I wonder for
LineHeight:=TextCharSize.y;
would it be better to do:
LineHeight:=TextCharSize.y+OptSpacingY;
Post Reply