Search code examples
delphitextfiremonkey

Firemonkey: How can I detect the X position of a character in a memo


I'm trying to develop a method that justify my text in a memo/label. But I need to take the X position of a character. Is this possible? If not, how can I justify my texts in firemonkey? I know that this is possible on desktop using an VLC library, but I found nothing for firemonkey.


Solution

  • I haven't found anything for getting X coords of chars. You can create array of widths of characters for your font and make method to count absolute x and y of characters, something like this:

    for y := 0 to Memo.Lines.Count - 1 do
      for x := 0 to Memo.Lines[y].Length - 1 do 
      begin
        AbsoluteX := AbsoluteX + CharWidths[Memo.Lines[y][x]]; 
        AbsoluteY := AbsoluteY + CharHeights[Memo.Lines[y][x]]; 
        // Be careful, for crossplatform using you should use Copy(), not string[n]
      end;
    

    For text align you can use this(for label you also have VerTextAlign)

    Memo.TextAlign := TTextAlign.Trailing; // For right justify
    Memo.TextAlign := TTextAlign.Center; // For center justify
    Memo.TextAlign := TTextAlign.Leading; // For default left justify