-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfMain.pas
executable file
·115 lines (99 loc) · 2.82 KB
/
fMain.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
unit fMain;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, FMX.Layouts,
System.Actions, FMX.ActnList, FMX.Gestures;
type
TfrmMain = class(TForm)
lytDrawer: TLayout;
lytMain: TLayout;
ToolBar1: TToolBar;
ActionList1: TActionList;
actOpenDrawer: TAction;
btnDrawer: TButton;
GestureManager1: TGestureManager;
procedure FormResize(Sender: TObject);
procedure actOpenDrawerExecute(Sender: TObject);
procedure actOpenDrawerUpdate(Sender: TObject);
private
FDrawerVisible: boolean;
{ Private declarations }
function IsPad : boolean;
function IsLandscape : boolean;
procedure LayoutForm;
procedure SetDrawerVisible(const Value: boolean);
public
{ Public declarations }
property DrawerVisible : boolean read FDrawerVisible write SetDrawerVisible;
end;
var
frmMain: TfrmMain;
implementation
uses
{$IFDEF IOS}
iOSapi.UIKit,
{$ENDIF }
{$IFDEF ANDROID}
FMX.Platform.Android, Androidapi.JNI.GraphicsContentViewText,
{$ENDIF }
FMX.Platform;
{$R *.fmx}
procedure TfrmMain.actOpenDrawerExecute(Sender: TObject);
begin
DrawerVisible := not DrawerVisible;
end;
procedure TfrmMain.actOpenDrawerUpdate(Sender: TObject);
begin
actOpenDrawer.Visible := not (IsPad and IsLandscape);
end;
procedure TfrmMain.FormResize(Sender: TObject);
begin
LayoutForm;
end;
function TfrmMain.IsLandscape: boolean;
begin
Result := self.Width > self.Height;
end;
function TfrmMain.IsPad: boolean;
begin
{$IFDEF IOS}
Result := TUIDevice.Wrap(TUIDevice.OCClass.currentDevice).userInterfaceIdiom = UIUserInterfaceIdiomPad;
{$ENDIF}
{$IFDEF ANDROID}
Result := (MainActivity.getResources.getConfiguration.screenLayout and TJConfiguration.JavaClass.SCREENLAYOUT_SIZE_MASK)
>= TJConfiguration.JavaClass.SCREENLAYOUT_SIZE_LARGE;
{$ENDIF}
end;
procedure TfrmMain.LayoutForm;
begin
lytMain.Height := self.Height;
lytDrawer.Height := self.Height;
if IsPad and IsLandscape then
begin
lytDrawer.Align := TAlignLayout.alLeft;
lytMain.Align := TAlignLayout.alClient;
end
else
begin
lytDrawer.Align := TAlignLayout.alNone;
lytMain.Align := TAlignLayout.alNone;
lytMain.Width := self.Width;
if DrawerVisible then
lytMain.Position.X := lytDrawer.Position.X + lytDrawer.Width
else
lytMain.Position.X := 0;
end;
end;
procedure TfrmMain.SetDrawerVisible(const Value: boolean);
begin
if FDrawerVisible <> Value then
begin
FDrawerVisible := Value;
if DrawerVisible then
lytMain.AnimateFloat('Position.X', lytDrawer.Position.X + lytDrawer.Width)
else
lytMain.AnimateFloat('Position.X', 0);
end;
end;
end.