Jump to content
Sign in to follow this  
vinni

TTextLayout for Linux

Recommended Posts

Hey folks,

I'm using Delphi 11.3, and it looks like TTextLayout is completely unsupported for Linux. Are there any solutions? Delphi 12.x? FMXLinux? Anything else?

Thank you!

Share this post


Link to post

This is how it looks on Win 11 and Ubuntu 22.04:

image.png.5569a6e0d5864c2f4b9b24f060f62a10.png image.png.34848628a45cb4a5f3e8638a081188d3.png

 

Are there any solutions to make the same behavior for Linux?

The code:

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.Controls.Presentation, FMX.StdCtrls, FMX.TextLayout, System.Generics.Collections, System.Character, FMX.Objects;

type
  TMyLabel = class(TLabel)
end;

type
  TTextAccess = class(TText);

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    FLabel: TMyLabel;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.FormCreate(Sender: TObject);

  procedure AddAttr(ALayout: TTextLayout; const AStart, ALength: Integer; const AColor: TAlphaColor; const AFontStyle: TFontStyles = []);
  var
    TR: TTextRange;
    TA: TTextAttribute;
  begin
    TR := TTextRange.Create(AStart, ALength);
    ALayout.Font.Style := AFontStyle;
    TA := TTextAttribute.Create(ALayout.Font, AColor);
    ALayout.AddAttribute(TR, TA);
  end;

var
  Layout: TTextLayout;
begin
  FLabel := TMyLabel.Create(Self);
  FLabel.Parent := Self;
  FLabel.Text := 'Red Green Blue';
  Layout := TTextAccess(FLabel.TextObject).Layout;
  AddAttr(Layout, 0, 3, TAlphaColors.Red);
  AddAttr(Layout, 4, 5, TAlphaColors.Green);
  AddAttr(Layout, 10, 4, TAlphaColors.Blue);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FLabel.Free;
end;

end.

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×