unit uMyVisualLayout;
interface
uses
System.SysUtils, System.Classes, FMX.Types, FMX.Controls, FMX.Layouts, FMX.StdCtrls, FMX.Objects,
FMX.Graphics;
Type
TMyImage =
class(TImage)
private
FBackupImage: TBitmap;
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
end;
Type
TMySpeedbutton =
class(TSpeedButton)
private
FLabelText: TLabel;
function GetNewText:
String;
procedure SetNewText(
const Value:
String);
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
property NewText:
String read GetNewText
write SetNewText;
end;
Type
TMyLayout =
class(TLayout)
private
{ Private-Deklarationen }
Speedbutton1, Speedbutton2, Speedbutton3: TMySpeedbutton;
TopFlowLayout: TFlowLayout;
procedure ButtonClick(Sender: Tobject);
protected
{ Protected-Deklarationen }
public
constructor Create(AOwner: TComponent);
override;
{ Public-Deklarationen }
published
{ Published-Deklarationen }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
TestVisualComponent', [TMyLayout]);
end;
{ TMyLayout }
procedure TMyLayout.ButtonClick(Sender: Tobject);
begin
log.d(TSpeedButton(Sender).
Name + '
Clicked!');
end;
constructor TMyLayout.Create(AOwner: TComponent);
begin
inherited;
TopFlowLayout := TFlowLayout.Create(self);
TopFlowLayout.Parent := self;
TopFlowLayout.Align := TAlignLayout.MostTop;
Speedbutton1 := TMySpeedbutton.Create(self);
Speedbutton1.Parent := TopFlowLayout;
Speedbutton1.Align := TAlignLayout.Client;
Speedbutton1.NewText := '
Speedbutton1';
Speedbutton1.OnClick := ButtonClick;
Speedbutton2 := TMySpeedbutton.Create(self);
Speedbutton2.Parent := TopFlowLayout;
Speedbutton2.Align := TAlignLayout.Client;
Speedbutton2.NewText := '
Speedbutton2';
Speedbutton2.OnClick := ButtonClick;
Speedbutton3 := TMySpeedbutton.Create(self);
Speedbutton3.Parent := TopFlowLayout;
Speedbutton3.Align := TAlignLayout.Client;
Speedbutton3.NewText := '
Speedbutton3';
Speedbutton3.OnClick := ButtonClick;
end;
{ TMyImage }
constructor TMyImage.Create(AOwner: TComponent);
begin
inherited;
FBackupImage := TBitmap.Create;
end;
destructor TMyImage.Destroy;
begin
FBackupImage.Free;
inherited;
end;
{ TMySpeedbutton }
constructor TMySpeedbutton.Create(AOwner: TComponent);
begin
inherited;
FLabelText := TLabel.Create(self);
FLabelText.Parent := self;
FLabelText.Align := TAlignLayout.Client;
end;
destructor TMySpeedbutton.Destroy;
begin
FLabelText.Free;
inherited;
end;
function TMySpeedbutton.GetNewText:
String;
begin
Result := FLabelText.Text;
end;
procedure TMySpeedbutton.SetNewText(
const Value:
String);
begin
FLabelText.Text := Value;
end;
end.