ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 layer size text
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

AndNit

Brazil
81 Posts

Posted - Jun 07 2024 :  12:48:09  Show Profile  Reply
Good afternoon,

I have a text layer with predefined size X, Y, Width and Height. I can only type on this layer, up to its limit. How to identify that you have reached the end of it and prevent the user from continuing typing?

Thanks

AndNit

Brazil
81 Posts

Posted - Jun 07 2024 :  14:47:35  Show Profile  Reply
I don't know if I understood you correctly, sorry.

I would like the user to be able to type only up to the maximum size of the text layer, in height and width. Not allowing it to increase or decrease the layer.
Go to Top of Page

AndNit

Brazil
81 Posts

Posted - Jun 07 2024 :  14:53:26  Show Profile  Reply
As if it were Word, when it reaches the end of the line, it skips the line, and when it reaches the end of the page, it skips the page, in this case, I need to know when the text reached the end of the layer (Width X Height)

for vertical, I use WordWrap = True, which automatically wraps the line, but for vertical, there is nothing that tells me the end of the Layer.
Go to Top of Page

xequte

38459 Posts

Posted - Jun 07 2024 :  16:13:19  Show Profile  Reply
Hi

There is no built in functionality for that. You would need to reset the Key parameter of the TImageEnView.OnTextEditorKeyDown event:

https://www.imageen.com/help/TImageEnView.OnTextEditorKeyDown.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

AndNit

Brazil
81 Posts

Posted - Jun 07 2024 :  16:21:58  Show Profile  Reply
I was seeing this event, I managed to understand how it works, but I can't imagine how to change the Key parameter, to identify the end of the text layer. Can you help me with some way?

Thanks
Go to Top of Page

xequte

38459 Posts

Posted - Jun 07 2024 :  21:03:40  Show Profile  Reply
Hi

Here is a better method:

// Prevent user from entering too much text
procedure Tfmain.ImageEnView1LayerNotifyEx(Sender: TObject; layer: Integer; event: TIELayerEvent);
const
  Maximum_Text_Length = 10;
var
  editor: TIEEdit;
  pos: Integer;
  s: string;
begin
  if ( Maximum_Text_Length > 0 ) and  ( event =  ielTextEditorChange ) then
  begin
    if ImageEnView1.LayersTextEditor is TIEEdit then
    begin
      editor := TIEEdit( ImageEnView1.LayersTextEditor );
      if Length( editor.Text ) > Maximum_Text_Length then
      begin
        pos := editor.SelStart;
        s := editor.Text;
        SetLength( s, Maximum_Text_Length );
        editor.Text := s;
        editor.SelStart := pos;
      end;
    end;
  end;
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

AndNit

Brazil
81 Posts

Posted - Jun 08 2024 :  05:38:31  Show Profile  Reply
Firstly thanks for the help, but it seems that this way I limit the text by the number of letters and I needed to limit it by the space of the text layer, which in each situation will be of a different size, I don't have the total number of words in advance.
Go to Top of Page

xequte

38459 Posts

Posted - Jun 10 2024 :  00:23:45  Show Profile  Reply
Hi

Yes, there is not really an easy way to do that, unfortunately.

If the text layer has AutoSize enabled, then you could check the TextEditor width and height and if its too big, delete the last character. Alternatively calculating the width and height of the text yourself (i.e. using Canvas.TextWidth/TextHeight).





Nigel
Xequte Software
www.imageen.com
Go to Top of Page

AndNit

Brazil
81 Posts

Posted - Sep 02 2024 :  15:12:36  Show Profile  Reply
How can I calculate the width and height of the text using Canvas?
Go to Top of Page

xequte

38459 Posts

Posted - Sep 02 2024 :  17:36:32  Show Profile  Reply
Please see:

https://docwiki.embarcadero.com/Libraries/Athens/en/Vcl.Graphics.TCanvas.TextExtent

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: