Skip to content

Commit

Permalink
Improving PageLayout Structure
Browse files Browse the repository at this point in the history
Implementing NavigationMAnager;
Implementing Interfaces for View Layer;
Improving PageLayout source
  • Loading branch information
rafael-figueiredo-alves committed Nov 25, 2024
1 parent 4a5de37 commit 75cb000
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 43 deletions.
5 changes: 3 additions & 2 deletions eTasks.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ uses
eTasks.Components.ActionButton in 'src\Components\Buttons\eTasks.Components.ActionButton.pas' {ActionButton},
eTasks.Components.NavBar in 'src\Components\Bars\eTasks.Components.NavBar.pas' {NavBar},
eTasks.View.PageLayout in 'src\View\eTasks.View.PageLayout.pas' {PageLayout},
eTasks.View.Teste in 'src\View\eTasks.View.Teste.pas' {PageLayout1};
eTasks.View.Teste in 'src\View\eTasks.View.Teste.pas' {PageLayout1},
eTasks.View.Interfaces in 'src\View\eTasks.View.Interfaces.pas',
eTasks.View.NavigationManager in 'src\View\eTasks.View.NavigationManager.pas';

{$R *.res}

Expand All @@ -63,6 +65,5 @@ begin
{$ENDIF}

Application.CreateForm(TfMain, fMain);
Application.CreateForm(TPageLayout1, PageLayout1);
Application.Run;
end.
2 changes: 2 additions & 0 deletions eTasks.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@
<Form>PageLayout1</Form>
<FormType>fmx</FormType>
</DCCReference>
<DCCReference Include="src\View\eTasks.View.Interfaces.pas"/>
<DCCReference Include="src\View\eTasks.View.NavigationManager.pas"/>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
Expand Down
25 changes: 25 additions & 0 deletions src/View/eTasks.View.Interfaces.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
unit eTasks.View.Interfaces;

interface

uses
FMX.Layouts;

type

TPages = (pageTasks, pageShopping, pageNotes, pageFinances, pageReadings, pageGoals, pageSettings, pageAbout);

TUpdateScreenMethod = Procedure of object;

iPageLayout = interface
['{E22EAB87-8030-43F8-B0DC-AB57B067C0CD}']
function Layout: TLayout;
function IsMobile(const Value: boolean): iPageLayout;
end;

implementation

end.



15 changes: 9 additions & 6 deletions src/View/eTasks.View.Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface
FMX.Controls.Presentation,
FMX.StdCtrls, FMX.Layouts,
eTasks.Components.Interfaces,
FMX.MultiView, eTasks.View.PageLayout;
FMX.MultiView, eTasks.View.PageLayout, eTasks.View.Interfaces;

type
TTeste = procedure of Object;
Expand Down Expand Up @@ -73,8 +73,8 @@ procedure TfMain.Button1Click(Sender: TObject);
begin
if(Assigned(Teste))then
begin
if(ScreensLayout.ContainsObject(Teste._Layout))then
ScreensLayout.RemoveObject(Teste._Layout);
if(ScreensLayout.ContainsObject(Teste.Layout))then
ScreensLayout.RemoveObject(Teste.Layout);
end;

Teste := TPageLayout.New(ScreensLayout, ScreensLayoutChange);
Expand All @@ -85,8 +85,8 @@ procedure TfMain.Button2Click(Sender: TObject);
begin
if(Assigned(Teste))then
begin
if(ScreensLayout.ContainsObject(Teste._Layout))then
ScreensLayout.RemoveObject(Teste._Layout);
if(ScreensLayout.ContainsObject(Teste.Layout))then
ScreensLayout.RemoveObject(Teste.Layout);
end;

Teste := TPageLayout1.New(ScreensLayout, ScreensLayoutChange);
Expand Down Expand Up @@ -115,6 +115,9 @@ procedure TfMain.FormResize(Sender: TObject);

AppBar.ShowTitleBar(fMain.Width > MobileSizeWidth);
TitleBar.Resize(fMain.Width);

if(Assigned(Teste))then
Teste.IsMobile(fMain.Width <= MobileSizeWidth);
end;

procedure TfMain.OpenAvatarMenu(sender: TObject);
Expand Down Expand Up @@ -149,7 +152,7 @@ procedure TfMain.ScreensLayoutChange;
else
begin
if(Assigned(Teste))then
if(ScreensLayout.ContainsObject(Teste._Layout))then
if(ScreensLayout.ContainsObject(Teste.Layout))then
begin
ScreensLayout.Parent := fMain;
ScreensLayout.Align := TAlignLayout.Contents;
Expand Down
13 changes: 13 additions & 0 deletions src/View/eTasks.View.NavigationManager.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
unit eTasks.View.NavigationManager;

interface

type
TNavigationManager = class
private
public
end;

implementation

end.
16 changes: 12 additions & 4 deletions src/View/eTasks.View.PageLayout.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,33 @@ object PageLayout: TPageLayout
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object Layout1: TLayout
object PageViewLayout: TLayout
Align = Client
Size.Width = 640.000000000000000000
Size.Height = 480.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
object Rectangle1: TRectangle
object Background: TRectangle
Align = Contents
Fill.Color = claWhite
Size.Width = 640.000000000000000000
Size.Height = 480.000000000000000000
Size.PlatformDefault = False
Stroke.Kind = None
object Button1: TButton
Position.X = 88.000000000000000000
Position.Y = 240.000000000000000000
Position.X = 40.000000000000000000
Position.Y = 40.000000000000000000
TabOrder = 0
Text = 'Button1'
TextSettings.Trimming = None
OnClick = Button1Click
end
object Label1: TLabel
Position.X = 216.000000000000000000
Position.Y = 152.000000000000000000
Text = 'Label1'
TabOrder = 1
end
end
end
end
72 changes: 43 additions & 29 deletions src/View/eTasks.View.PageLayout.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts,
FMX.Controls.Presentation, FMX.StdCtrls, FMX.Objects;
FMX.Controls.Presentation, FMX.StdCtrls, FMX.Objects, eTasks.View.Interfaces;

type
iPageLayout = interface
['{E22EAB87-8030-43F8-B0DC-AB57B067C0CD}']
function _Layout: TLayout;
end;

TMetodoScreen = Procedure of object;

TPageLayout = class(TForm, iPageLayout)
Button1: TButton;
Layout1: TLayout;
Rectangle1: TRectangle;
PageViewLayout: TLayout;
Background: TRectangle;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
Layout: TLayout;
Metodo : TMetodoScreen;
MainLayout: TLayout;
UpdateScreenMethod : TUpdateScreenMethod;
procedure GoBack;
procedure RemovePageViewLayout;
public
{ Public declarations }
function _Layout: TLayout;
class function New(const pLayout: TLayout; met: TMetodoScreen) : iPageLayout;
function Layout: TLayout;
function IsMobile(const Value: boolean): iPageLayout;

class function New(const pLayout: TLayout; pUpdateScreenMethod: TUpdateScreenMethod) : iPageLayout;
destructor Destroy; override;
end;

Expand All @@ -42,38 +42,52 @@ implementation

procedure TPageLayout.Button1Click(Sender: TObject);
begin
// Remove Layout1 do Layout principal
if Assigned(Layout) and Layout.ContainsObject(Layout1) then
Layout.RemoveObject(Layout1);
GoBack;
end;

// Força a atualização do foco para o formulário principal
Application.ProcessMessages;
destructor TPageLayout.Destroy;
begin
RemovePageViewLayout;

Metodo;
inherited;
end;

destructor TPageLayout.Destroy;
procedure TPageLayout.GoBack;
begin
RemovePageViewLayout;

// Certifique-se de que Layout1 seja removido do layout pai antes de destruir
if Assigned(Layout) and Layout.ContainsObject(Layout1) then
Layout.RemoveObject(Layout1);
Application.ProcessMessages;

inherited;
UpdateScreenMethod;
end;

function TPageLayout.IsMobile(const Value: boolean): iPageLayout;
begin
Result := Self;
if(Value)then
Label1.Text := 'Mobile'
else
Label1.Text := 'Desktop';
end;

class function TPageLayout.New(const pLayout: TLayout; met: TMetodoScreen): iPageLayout;
class function TPageLayout.New(const pLayout: TLayout; pUpdateScreenMethod: TUpdateScreenMethod): iPageLayout;
begin
PageLayout := Self.Create(pLayout);
PageLayout.Layout := pLayout;
pLayout.AddObject(PageLayout.Layout1);
PageLayout.Metodo := met;
PageLayout.MainLayout := pLayout;
pLayout.AddObject(PageLayout.PageViewLayout);
PageLayout.UpdateScreenMethod := pUpdateScreenMethod;
Result := PageLayout;
end;

function TPageLayout._Layout: TLayout;
procedure TPageLayout.RemovePageViewLayout;
begin
if Assigned(MainLayout) and MainLayout.ContainsObject(PageViewLayout) then
MainLayout.RemoveObject(PageViewLayout);
end;

function TPageLayout.Layout: TLayout;
begin
Result := Self.Layout1;
Result := Self.PageViewLayout;
end;

end.
4 changes: 2 additions & 2 deletions src/View/eTasks.View.Teste.fmx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
inherited PageLayout1: TPageLayout1
Caption = 'PageLayout1'
DesignerMasterStyle = 0
inherited Layout1: TLayout
inherited Rectangle1: TRectangle
inherited PageViewLayout: TLayout
inherited Background: TRectangle
object Rectangle2: TRectangle
Fill.Color = xFFB90606
Position.X = 88.000000000000000000
Expand Down

0 comments on commit 75cb000

Please sign in to comment.