Recent

Author Topic: The problem of drawing lines under strings  (Read 10967 times)

jianwt

  • Full Member
  • ***
  • Posts: 164
Re: The problem of drawing lines under strings
« Reply #30 on: February 01, 2024, 02:42:17 am »
@rvk,Thank you very much for your help.

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: The problem of drawing lines under strings
« Reply #31 on: February 01, 2024, 05:27:38 am »
@rvk:
Now I am beginning to understand why I got nowhere with my attempts  :)

Your approach (just as mine) doesn't seem to do anything for me (Linux gtk2) except for some small horizontal lies in the right border of the control (where the scrollbar usually is located). I got similar results with my attempts with memo and synedit.

The lines that do show at the right side only start appearing when the cursor reached the bottom of the memo control, before that even these lines are not visible. Setting the background to another color also does not seem to do anything.
Today is tomorrow's yesterday.

jianwt

  • Full Member
  • ***
  • Posts: 164
Re: The problem of drawing lines under strings
« Reply #32 on: February 01, 2024, 07:45:22 am »
@rvk
As TRon said, my drawing line is not visible under linux "gtk2", and the error occurs when closing the form.

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: The problem of drawing lines under strings
« Reply #33 on: February 01, 2024, 08:03:22 am »
@The lines that do show at the right side only start appearing when the cursor reached the bottom of the memo control, before that even these lines are not visible. Setting the background to another color also does not seem to do anything.
Then it looks like the TRichMemo.Transpatent doesn't work cross-platform. I thought I read somewhere that it should work cross-platform.

Back to the drawing board  ::)

I thought about drawing on top of the richmemo but in Windows the riched20 dll doesn't seem to allow that. I also was looking at catching the WM_PAINT but then it's not cross-platform anymore.

Guess I need to dive deep into the WidgetClass world of Lazarus for this  %)

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: The problem of drawing lines under strings
« Reply #34 on: February 01, 2024, 08:50:47 am »
Then it looks like the TRichMemo.Transpatent doesn't work cross-platform. I thought I read somewhere that it should work cross-platform.
I did not notice anything in the object inspector, however I just came across this:

Quote
Note that the property might not affect "border" style of the the richmemo. You need to set BorderStyle to bsNone in order to disable it. For macOS this also hides the focus ring (when the control is focused)

    Supported by Win32, Qt5 and Cocoa
:-X

Quote
Guess I need to dive deep into the WidgetClass world of Lazarus for this  %)
I ended up diving into things at a level  that I was not comfortable with anymore (e.g. no idea anymore WTF I'm doing  :) ). (not that my knowledge on certain components and LCL is anything to write/brag about)
Today is tomorrow's yesterday.

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: The problem of drawing lines under strings
« Reply #35 on: February 01, 2024, 09:07:47 am »
Then it looks like the TRichMemo.Transpatent doesn't work cross-platform. I thought I read somewhere that it should work cross-platform.
I did not notice anything in the object inspector, however I just came across this:
"Supported by Win32, Qt5 and Cocoa"
Aaaargh.... no gtk2 there   ::)

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: The problem of drawing lines under strings
« Reply #36 on: February 01, 2024, 09:46:28 am »
Your approach (just as mine) doesn't seem to do anything for me (Linux gtk2) except for some small horizontal lies in the right border of the control (where the scrollbar usually is located). I got similar results with my attempts with memo and synedit.
I haven't looked at SynEdit yet but shouldn't it be a lot easier there?
Doesn't SynEdit have a plugin system where it exposes the canvas (after which you can draw to it)??

I didn't look at that yet because I thought TS needed variable font sizes etc.

@jianwt Do you indeed need variable font sizes and bold, color etc?
Or is a TMemo or TSynEdit also enough? (where font sizes are static and lineheights are all equal) ?
We didn't get the reason or use-case for the underlining yet (or what characteristic the text might possibly have).
« Last Edit: February 01, 2024, 09:56:16 am by rvk »

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: The problem of drawing lines under strings
« Reply #37 on: February 01, 2024, 09:55:56 am »
I'm probably just missing something here but TSynEdit even has a OnPaint event.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.SynEdit1Paint(Sender: TObject; ACanvas: TCanvas);
  2. var
  3.   Y: Integer;
  4. begin
  5.   // first line
  6.   ACanvas.Pen.Color := clBlue;
  7.   ACanvas.Pen.Width := 1;
  8.   Y := 1; // we begin at the top
  9.   while Y < TSynEdit(Sender).Height do
  10.   begin
  11.     ACanvas.Line(1, Y, TSynEdit(Sender).Width - 1, Y);
  12.     Y := Y + TSynEdit(Sender).LineHeight;
  13.   end;
  14. end;
  15.  
  16. procedure TForm1.FormCreate(Sender: TObject);
  17. var
  18.   I: Integer;
  19. begin
  20.   SynEdit1.Clear;
  21.   for I := 1 to 26 do
  22.   begin
  23.     SynEdit1.Lines.Add(StringOfChar(chr(64 + I), 10));
  24.   end;
  25. end;

But again... I'm probably missing something  :D

As said... this doesn't support variable letter font (changing in size).
So TMemo and TSynEdit would be out because of this ???

TRon

  • Hero Member
  • *****
  • Posts: 4377
Re: The problem of drawing lines under strings
« Reply #38 on: February 01, 2024, 09:59:48 am »
@rvk, It can't hurt to ask/verify and for jianwt to (re)confirm and to make sure the intention/idea/request is clear, but from post #11

Due to the limitations of stringgrid (for example, one line cannot automatically replace the next line when the input is full, instead of a simple carriage return), the input interface is not only used for input, but also needs to take string data for the next operation (such as setting the font and color of each paragraph). As I am a beginner, I still do not know much about stringgrid operation. It is estimated that it will not achieve the effect you want, but thank you for the advice of 2 masters.
I want to see if there are any other options. I found that the RichViewEdit control can do this, but it is not supported on linux systems.

In case that is literally per paragraph (no font size/color changing in a single paragraph) then that might perhaps be solvable in another manner.

And you are most probably right about synedit but I did not manage to get up to such a point (I am not familiar with synedit internals) and jainwt dismissed using that option (now that is one post in this thread that I seem unable to find that quickly during edit  :)

I'm probably just missing something here but TSynEdit even has a OnPaint event.
No, you're not. I got stuck on the different font sizes with different (line) spacing  :)
« Last Edit: February 01, 2024, 10:03:53 am by TRon »
Today is tomorrow's yesterday.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12345
  • Debugger - SynEdit - and more
    • wiki
Re: The problem of drawing lines under strings
« Reply #39 on: February 01, 2024, 10:21:19 am »
In SynEdit you can use SpecialLineMarkup

Code: Pascal  [Select][+][-]
  1. //  SynEdit1.OnSpecialLineMarkup := @GetLineMarkup;
  2.  
  3. procedure TForm1.GetLineMarkup(Sender: TObject; Line: integer; var Special: boolean; Markup: TSynSelectedColor);
  4. begin
  5.   Special := True;
  6.   Markup.Clear;
  7.   Markup.FrameEdges := sfeBottom;
  8.   Markup.FrameColor := clBlue;
  9. end;

That is all you need.

But ...
I've been experimenting with some of synedit's features today, and I've found that synedit doesn't really suit my needs. The main thing is that its wordwrap (Chinese garbled code) limits its use.

Not sure what "wordwrap" means here. Since Synedit doesn't wrap.


Maybe that means overlapping chars / glyphs?
(I may be limited by my European thinking "glyph = char", but in Chinese each glyph is a word?)

If it is overlapping chars => you need a monospaced font. SynEdit only works with monospaced fonts.


« Last Edit: February 01, 2024, 10:25:21 am by Martin_fr »

jianwt

  • Full Member
  • ***
  • Posts: 164
Re: The problem of drawing lines under strings
« Reply #40 on: February 01, 2024, 11:27:47 am »
@rvk

“@jianwt Do you indeed need variable font sizes and bold, color etc?
Or is a TMemo or TSynEdit also enough?  (where font sizes are static and lineheights are all equal) ?”


I just need to change the font size and color.  font sizes are static and lineheights are all equal。

I've experimented with SynEdit and it doesn't seem to be a fully effective line wrap (" wordwrap ") at the moment, my requirement is that the scroll bar move up and down, but not left and right (fixed width). But the SynEdit scroll bar, no matter how you set it, can still move its width from side to side.
When you type a string into a line in SynEdit, it doesn't wrap unless you press Enter to force a line wrap, which I can't accept.


I also tried this method, automatic line wrapping is very uncomfortable, Chinese will be garbled.
https://forum.lazarus.freepascal.org/index.php?topic=61258.0
« Last Edit: February 01, 2024, 11:38:35 am by jianwt »

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: The problem of drawing lines under strings
« Reply #41 on: February 01, 2024, 11:33:01 am »
I just need to change the font size and color.  font sizes are static and lineheights are all equal。
Wait... that I don't understand  %)
When font sizes change for a paragraph... the lineheights also change and font size isn't static in that case.

So either font size change (dynamic) or font size stay the same (static).

Or do you mean that you need one font size per memo-edit. And for another memo-edit you need another font-size?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12345
  • Debugger - SynEdit - and more
    • wiki
Re: The problem of drawing lines under strings
« Reply #42 on: February 01, 2024, 11:49:34 am »
I also tried this method, automatic line wrapping is very uncomfortable, Chinese will be garbled.
https://forum.lazarus.freepascal.org/index.php?topic=61258.0

Yes that is still experimental...  (and will still be for a while)

It currently has hardcode
Code: Pascal  [Select][+][-]
  1.   BREAKCHARS = [#9, #32, '.', ',', ':', ';', '=', '-', '+', '*', '/', '(', ')', '{', '}', '[', ']', '!', '<', '>'];

So it will break at those chars. There are all the unicode space missing. And I don't know anything about how word wrap should act on Chinese text.

jianwt

  • Full Member
  • ***
  • Posts: 164
Re: The problem of drawing lines under strings
« Reply #43 on: February 01, 2024, 12:44:44 pm »

@ rvk

I want the input and display to look like this.

rvk

  • Hero Member
  • *****
  • Posts: 7014
Re: The problem of drawing lines under strings
« Reply #44 on: February 01, 2024, 01:44:54 pm »
I want the input and display to look like this.
All font size seem the same there.

So it would only be the wordwrap that you are missing for TSynEdit.

Original TSynEdit (from Delphi) has wordwrap implemented via plugin.
But unfortunately that was done after the fork to Lazarus  :-\

I'm still searching for a way to put something (canvas) "over" richmemo (for Linux) but that doesn't seem to be easy.


 

TinyPortal © 2005-2018