This repository has been archived by the owner on May 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
DALLE.FrameMessage.pas
149 lines (130 loc) · 3.83 KB
/
DALLE.FrameMessage.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
unit DALLE.FrameMessage;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
FMX.Objects, FMX.Memo.Types, FMX.Layouts, FMX.Controls.Presentation,
FMX.ScrollBox, FMX.Memo;
type
TFrameMessage = class(TFrame)
RectangleBG: TRectangle;
Layout1: TLayout;
RectangleUser: TRectangle;
Path1: TPath;
RectangleBot: TRectangle;
Path2: TPath;
LayoutContent: TLayout;
LayoutContentItems: TLayout;
FlowLayoutImages: TFlowLayout;
MemoText: TMemo;
procedure MemoTextChange(Sender: TObject);
procedure FrameResize(Sender: TObject);
private
FIsUser: Boolean;
FText: string;
FIsError: Boolean;
FImages: TArray<string>;
procedure UpdateContentSize;
procedure SetIsUser(const Value: Boolean);
procedure SetText(const Value: string);
procedure SetIsError(const Value: Boolean);
procedure SetImages(const Value: TArray<string>);
public
property Text: string read FText write SetText;
property Images: TArray<string> read FImages write SetImages;
property IsUser: Boolean read FIsUser write SetIsUser;
property IsError: Boolean read FIsError write SetIsError;
constructor Create(AOwner: TComponent); override;
end;
implementation
uses
System.Math, FMX.Memo.Style, DALLE.FrameImage;
{$R *.fmx}
procedure TFrameMessage.UpdateContentSize;
begin
//Memo
MemoText.Height := Max(MemoText.ContentBounds.Height, 30);
//Flow
var ItemW := Min(256, Max(Trunc(FlowLayoutImages.Width / FlowLayoutImages.ControlsCount), 48));
if ItemW = 48 then
ItemW := Trunc(FlowLayoutImages.Width / Trunc(FlowLayoutImages.Width / 48));
var H: Single := 0;
for var Control in FlowLayoutImages.Controls do
begin
Control.Size.Size := TSizeF.Create(ItemW, ItemW);
H := Max(Control.Position.Y + Control.Height, H);
end;
if FlowLayoutImages.Height <> H then
FlowLayoutImages.Height := H;
//Frame
H := Padding.Top + Padding.Bottom;
for var Control in LayoutContentItems.Controls do
if Control.Visible then
H := H + Control.Height + Control.Margins.Top + Control.Margins.Bottom;
if Height <> H then
Height := H;
end;
constructor TFrameMessage.Create(AOwner: TComponent);
begin
inherited;
Name := '';
{$IFDEF ANDROID}
MemoText.HitTest := False;
{$ENDIF}
MemoText.Visible := False;
end;
procedure TFrameMessage.FrameResize(Sender: TObject);
begin
LayoutContent.Width := Min(Width - (Padding.Left + Padding.Right), 650);
UpdateContentSize;
end;
procedure TFrameMessage.MemoTextChange(Sender: TObject);
begin
UpdateContentSize;
end;
procedure TFrameMessage.SetImages(const Value: TArray<string>);
begin
FImages := Value;
while FlowLayoutImages.ControlsCount > 0 do
FlowLayoutImages.Controls[0].Free;
for var Item in FImages do
begin
var Frame := TFrameImage.Create(FlowLayoutImages);
Frame.Parent := FlowLayoutImages;
Frame.Image := Item;
end;
UpdateContentSize;
end;
procedure TFrameMessage.SetIsError(const Value: Boolean);
begin
FIsError := Value;
MemoText.FontColor := $FFEF4444;
end;
procedure TFrameMessage.SetIsUser(const Value: Boolean);
begin
FIsUser := Value;
RectangleUser.Visible := FIsUser;
RectangleBot.Visible := not FIsUser;
if FIsUser then
begin
RectangleBG.Fill.Color := $00FFFFFF;
MemoText.FontColor := $FFECECF1;
end
else
begin
RectangleBG.Fill.Color := $14FFFFFF;
MemoText.FontColor := $FFD1D5E3;
end;
end;
procedure TFrameMessage.SetText(const Value: string);
begin
MemoText.Visible := not Value.IsEmpty;
if not Value.IsEmpty then
FText := Value
else
FText := '';
MemoText.Text := FText.Trim([' ', #13, #10]);
(MemoText.Presentation as TStyledMemo).InvalidateContentSize;
(MemoText.Presentation as TStyledMemo).PrepareForPaint;
end;
end.