From 4a5de375b0bda64bfbf2fb8c39d0eb7648a7e3ca Mon Sep 17 00:00:00 2001 From: Rafael de Figueiredo Alves Date: Fri, 22 Nov 2024 22:32:14 -0300 Subject: [PATCH] PageLayout is working properly now Fixed PageLayout behavior and now it's working properly. Now I have to work on improve it to be able to continue with the project. --- eTasks.dpr | 4 +++- eTasks.dproj | 4 ++++ src/View/eTasks.View.Main.fmx | 12 ++++++++-- src/View/eTasks.View.Main.pas | 34 ++++++++++++++++++++++------- src/View/eTasks.View.PageLayout.pas | 21 ++++++++---------- src/View/eTasks.View.Teste.fmx | 16 ++++++++++++++ src/View/eTasks.View.Teste.pas | 26 ++++++++++++++++++++++ 7 files changed, 94 insertions(+), 23 deletions(-) create mode 100644 src/View/eTasks.View.Teste.fmx create mode 100644 src/View/eTasks.View.Teste.pas diff --git a/eTasks.dpr b/eTasks.dpr index dff3e5f..102c366 100644 --- a/eTasks.dpr +++ b/eTasks.dpr @@ -44,7 +44,8 @@ uses eTasks.Components.Menu in 'src\Components\Offcanvas\eTasks.Components.Menu.pas' {OffcanvasMenu}, 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.PageLayout in 'src\View\eTasks.View.PageLayout.pas' {PageLayout}, + eTasks.View.Teste in 'src\View\eTasks.View.Teste.pas' {PageLayout1}; {$R *.res} @@ -62,5 +63,6 @@ begin {$ENDIF} Application.CreateForm(TfMain, fMain); + Application.CreateForm(TPageLayout1, PageLayout1); Application.Run; end. diff --git a/eTasks.dproj b/eTasks.dproj index 3094739..1d5cb63 100644 --- a/eTasks.dproj +++ b/eTasks.dproj @@ -286,6 +286,10 @@
PageLayout
fmx + +
PageLayout1
+ fmx +
Base diff --git a/src/View/eTasks.View.Main.fmx b/src/View/eTasks.View.Main.fmx index b11beaf..fd717d1 100644 --- a/src/View/eTasks.View.Main.fmx +++ b/src/View/eTasks.View.Main.fmx @@ -31,13 +31,21 @@ object fMain: TfMain Size.PlatformDefault = False TabOrder = 0 object Button1: TButton - Position.X = 104.000000000000000000 + Position.X = 96.000000000000000000 Position.Y = 80.000000000000000000 - TabOrder = 0 + TabOrder = 1 Text = 'Button1' TextSettings.Trimming = None OnClick = Button1Click end + object Button2: TButton + Position.X = 96.000000000000000000 + Position.Y = 200.000000000000000000 + TabOrder = 0 + Text = 'Button2' + TextSettings.Trimming = None + OnClick = Button2Click + end end object ScreensLayout: TLayout Align = Right diff --git a/src/View/eTasks.View.Main.pas b/src/View/eTasks.View.Main.pas index dbaf73d..1dcee18 100644 --- a/src/View/eTasks.View.Main.pas +++ b/src/View/eTasks.View.Main.pas @@ -30,9 +30,11 @@ TfMain = class(TForm) ScreensLayout: TLayout; Button1: TButton; Circle1: TCircle; + Button2: TButton; procedure FormResize(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); + procedure Button2Click(Sender: TObject); private { Private declarations } AppBar : iAppBar; @@ -41,7 +43,7 @@ TfMain = class(TForm) AvatarMenu : iAvatarMenu; ActionButton : iActionButton; fDarkMode : Boolean; - Teste : TLayout; + Teste : iPageLayout; procedure SetTheme(sender : TObject); procedure SetLanguage(sender : TObject); procedure TranslateUI; @@ -63,7 +65,7 @@ implementation eTasks.Components.ColorPallete, eTasks.Components.Builder, eTasks.Shared.Consts, - eTranslate4Pascal; + eTranslate4Pascal, eTasks.View.Teste; {$R *.fmx} @@ -71,11 +73,23 @@ procedure TfMain.Button1Click(Sender: TObject); begin if(Assigned(Teste))then begin - //Teste.Release; - Teste := nil; + if(ScreensLayout.ContainsObject(Teste._Layout))then + ScreensLayout.RemoveObject(Teste._Layout); end; - Teste := TPageLayout.New(ScreensLayout); + Teste := TPageLayout.New(ScreensLayout, ScreensLayoutChange); + ScreensLayoutChange; +end; + +procedure TfMain.Button2Click(Sender: TObject); +begin + if(Assigned(Teste))then + begin + if(ScreensLayout.ContainsObject(Teste._Layout))then + ScreensLayout.RemoveObject(Teste._Layout); + end; + + Teste := TPageLayout1.New(ScreensLayout, ScreensLayoutChange); ScreensLayoutChange; end; @@ -124,24 +138,28 @@ procedure TfMain.RestrictScreenSize; procedure TfMain.ScreensLayoutChange; begin - ScreensLayout.Width := fMain.Width / 2; if(fMain.Width > MobileSizeWidth)then begin ScreensLayout.Parent := ContentLayout; ScreensLayout.Align := TAlignLayout.Right; + ScreensLayout.Width := fMain.Width / 2; ScreensLayout.Visible := True; end else begin if(Assigned(Teste))then - if(Assigned(Teste))then - if(ScreensLayout.ContainsObject(Teste))then + if(ScreensLayout.ContainsObject(Teste._Layout))then begin ScreensLayout.Parent := fMain; ScreensLayout.Align := TAlignLayout.Contents; ScreensLayout.Visible := True; end + else + begin + ScreensLayout.Parent := nil; + ScreensLayout.Visible := False; + end else begin ScreensLayout.Parent := nil; diff --git a/src/View/eTasks.View.PageLayout.pas b/src/View/eTasks.View.PageLayout.pas index d2ef59c..bd648ed 100644 --- a/src/View/eTasks.View.PageLayout.pas +++ b/src/View/eTasks.View.PageLayout.pas @@ -13,6 +13,8 @@ interface function _Layout: TLayout; end; + TMetodoScreen = Procedure of object; + TPageLayout = class(TForm, iPageLayout) Button1: TButton; Layout1: TLayout; @@ -21,10 +23,11 @@ TPageLayout = class(TForm, iPageLayout) private { Private declarations } Layout: TLayout; + Metodo : TMetodoScreen; public { Public declarations } function _Layout: TLayout; - class function New(const pLayout: TLayout) : TLayout; + class function New(const pLayout: TLayout; met: TMetodoScreen) : iPageLayout; destructor Destroy; override; end; @@ -39,8 +42,6 @@ implementation procedure TPageLayout.Button1Click(Sender: TObject); begin - if Assigned(Self) then - begin // Remove Layout1 do Layout principal if Assigned(Layout) and Layout.ContainsObject(Layout1) then Layout.RemoveObject(Layout1); @@ -48,9 +49,7 @@ procedure TPageLayout.Button1Click(Sender: TObject); // Força a atualização do foco para o formulário principal Application.ProcessMessages; - // Use Release em vez de Free para evitar problemas de memória e foco - PageLayout.Release; - end; + Metodo; end; destructor TPageLayout.Destroy; @@ -63,15 +62,13 @@ destructor TPageLayout.Destroy; inherited; end; -class function TPageLayout.New(const pLayout: TLayout): TLayout; +class function TPageLayout.New(const pLayout: TLayout; met: TMetodoScreen): iPageLayout; begin - if(Assigned(PageLayout))then - PageLayout.Release; - - PageLayout := Self.Create(nil); + PageLayout := Self.Create(pLayout); PageLayout.Layout := pLayout; pLayout.AddObject(PageLayout.Layout1); - Result := PageLayout.Layout1; + PageLayout.Metodo := met; + Result := PageLayout; end; function TPageLayout._Layout: TLayout; diff --git a/src/View/eTasks.View.Teste.fmx b/src/View/eTasks.View.Teste.fmx new file mode 100644 index 0000000..558e86b --- /dev/null +++ b/src/View/eTasks.View.Teste.fmx @@ -0,0 +1,16 @@ +inherited PageLayout1: TPageLayout1 + Caption = 'PageLayout1' + DesignerMasterStyle = 0 + inherited Layout1: TLayout + inherited Rectangle1: TRectangle + object Rectangle2: TRectangle + Fill.Color = xFFB90606 + Position.X = 88.000000000000000000 + Position.Y = 88.000000000000000000 + Size.Width = 50.000000000000000000 + Size.Height = 50.000000000000000000 + Size.PlatformDefault = False + end + end + end +end diff --git a/src/View/eTasks.View.Teste.pas b/src/View/eTasks.View.Teste.pas new file mode 100644 index 0000000..8c2b43a --- /dev/null +++ b/src/View/eTasks.View.Teste.pas @@ -0,0 +1,26 @@ +unit eTasks.View.Teste; + +interface + +uses + System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, + FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, + eTasks.View.PageLayout, FMX.Controls.Presentation, FMX.Objects, FMX.Layouts; + +type + TPageLayout1 = class(TPageLayout) + Rectangle2: TRectangle; + private + { Private declarations } + public + { Public declarations } + end; + +var + PageLayout1: TPageLayout1; + +implementation + +{$R *.fmx} + +end.