Skip to content

Commit

Permalink
Improving first components
Browse files Browse the repository at this point in the history
  • Loading branch information
rafael-figueiredo-alves committed Oct 8, 2024
1 parent 228ae5f commit ec25538
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 60 deletions.
1 change: 1 addition & 0 deletions src/Components/Bars/eTasks.Components.AppBar.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ object AppBar: TAppBar
Size.Width = 40.000000000000000000
Size.Height = 40.000000000000000000
Size.PlatformDefault = False
OnClick = BtnMainMenuClick
end
object BtnThemeChanger: TImage
MultiResBitmap = <
Expand Down
32 changes: 22 additions & 10 deletions src/Components/Bars/eTasks.Components.AppBar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ TAppBar = class(TForm, iAppBar)
ImgDark: TImageList;
ImgAvatar: TImageList;
procedure BtnThemeChangerClick(Sender: TObject);
procedure BtnMainMenuClick(Sender: TObject);
private
fThemeChangerClick: TEventoClick;
fMenuButtonClick: TEventoClick;

{ Private declarations }
function ImgSource(const size: TSizeF; index: integer; isDarkMode: boolean): TBitmap;
Expand All @@ -33,9 +35,9 @@ TAppBar = class(TForm, iAppBar)
function ChangeTitle(const Title: string): iAppBar;
function ShowTitleBar(const value: Boolean): TRectangle;
function Render: TRectangle;
function ThemeChangerClick(const Evento: TEventoClick): iAppBar;
function isDarkMode(const value: boolean): iAppBar;
class function New(const Form: TForm): iAppBar;
function SetButtonAppBarAction(const ButtonAppBar: TButtonAppBar; const Action: TEventoClick): iAppBar;
class function New(const Form: TForm; const Layout: TLayout): iAppBar;
end;

var
Expand All @@ -50,6 +52,12 @@ implementation

{ TAppBar }

procedure TAppBar.BtnMainMenuClick(Sender: TObject);
begin
if(Assigned(fMenuButtonClick))then
fMenuButtonClick(sender);
end;

procedure TAppBar.BtnThemeChangerClick(Sender: TObject);
begin
if(Assigned(fThemeChangerClick))then
Expand Down Expand Up @@ -83,27 +91,31 @@ function TAppBar.isDarkMode(const value: boolean): iAppBar;
Avatar.Fill.Bitmap.Bitmap := AvatarImg.Bitmap;
end;

class function TAppBar.New(const Form: TForm): iAppBar;
class function TAppBar.New(const Form: TForm; const Layout: TLayout): iAppBar;
begin
Result := self.Create(Form);
Form.AddObject(Result.Render);
Layout.AddObject(Result.Render);
end;

function TAppBar.Render: TRectangle;
begin
Result := Self.TopBar;
end;

function TAppBar.ShowTitleBar(const value: Boolean): TRectangle;
function TAppBar.SetButtonAppBarAction(const ButtonAppBar: TButtonAppBar; const Action: TEventoClick): iAppBar;
begin
self.TitleBar.Visible := value;
Result := self.TitleBar;
Result := Self;

case ButtonAppBar of
ThemeBtn: fThemeChangerClick := Action;
MenuBtn: fMenuButtonClick := Action;
end;
end;

function TAppBar.ThemeChangerClick(const Evento: TEventoClick): iAppBar;
function TAppBar.ShowTitleBar(const value: Boolean): TRectangle;
begin
fThemeChangerClick := Evento;
Result := Self;
self.TitleBar.Visible := value;
Result := self.TitleBar;
end;

end.
6 changes: 3 additions & 3 deletions src/Components/Bars/eTasks.Components.TitleBar.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ object TitleBar: TTitleBar
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object Layout1: TLayout
object LayoutTitleBar: TLayout
Align = Top
Size.Width = 640.000000000000000000
Size.Height = 40.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
object Rectangle3: TRectangle
object TitleBar: TRectangle
Align = Left
Fill.Color = xFF336699
Margins.Left = -15.000000000000000000
Expand All @@ -28,7 +28,7 @@ object TitleBar: TTitleBar
Stroke.Kind = None
XRadius = 15.000000000000000000
YRadius = 15.000000000000000000
object Label3: TLabel
object TitleBarText: TLabel
Align = Right
AutoSize = True
StyledSettings = [Style]
Expand Down
40 changes: 24 additions & 16 deletions src/Components/Bars/eTasks.Components.TitleBar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,60 @@ interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.StdCtrls, FMX.Objects, FMX.Layouts;
FMX.Controls.Presentation, FMX.StdCtrls, FMX.Objects, FMX.Layouts,
eTasks.Components.Interfaces;

type
iTitleBar = interface
['{CCA6D914-787E-495F-ADE7-F9472A0FBC45}']
function Layout : TLayout;
function ChangeTitle(const Title: string): iTitleBar;
end;


TTitleBar = class(TForm, iTitleBar)
Layout1: TLayout;
Rectangle3: TRectangle;
Label3: TLabel;
LayoutTitleBar: TLayout;
TitleBar: TRectangle;
TitleBarText: TLabel;
private
{ Private declarations }
public
{ Public declarations }
function Layout : TLayout;
function Render : TLayout;
function ChangeTitle(const Title: string): iTitleBar;
class function New(const Form: TForm): iTitleBar;
function isDarkMode(const value: boolean): iTitleBar;
class function New(const Form: TForm; const Layout: TLayout): iTitleBar;
end;

var
TitleBar : TTitleBar ;

implementation

uses
eTasks.Components.ColorPallete;

{$R *.fmx}

{ TTitleBar }

function TTitleBar.ChangeTitle(const Title: string): iTitleBar;
begin
Result := self;
self.Label3.text := Title;
self.TitleBarText.text := Title;
end;

function TTitleBar.Layout: TLayout;
function TTitleBar.Render: TLayout;
begin
Result := self.Layout1;
Result := self.LayoutTitleBar;
end;

function TTitleBar.isDarkMode(const value: boolean): iTitleBar;
begin
Result := self;
Self.TitleBar.Fill.Color := tColorPallete.GetColor(Primary, value);
Self.TitleBarText.FontColor := tColorPallete.GetColor(Text, not value);
end;

class function TTitleBar.New(const Form: TForm): iTitleBar;
class function TTitleBar.New(const Form: TForm; const Layout: TLayout): iTitleBar;
begin
Result := self.create(Form);
Form.AddObject(Result.Layout);
Layout.AddObject(Result.Render);
end;

end.
16 changes: 11 additions & 5 deletions src/Components/eTasks.Components.Builder.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,30 @@ interface

uses
eTasks.Components.Interfaces,
FMX.Forms;
FMX.Forms, FMX.Layouts;

type

TComponentBars = class
class function AppBar(const Form: TForm) : iAppBar;
class function AppBar(const Form: TForm; const Layout: TLayout) : iAppBar;
class function TitleBar(const Form: TForm; const Layout: TLayout) : iTitleBar;
end;

implementation

uses
eTasks.Components.AppBar;
eTasks.Components.AppBar, eTasks.Components.TitleBar;

{ TComponentBars }

class function TComponentBars.AppBar(const Form: TForm): iAppBar;
class function TComponentBars.AppBar(const Form: TForm; const Layout: TLayout): iAppBar;
begin
Result := tAppBar.New(Form);
Result := tAppBar.New(Form, Layout);
end;

class function TComponentBars.TitleBar(const Form: TForm; const Layout: TLayout): iTitleBar;
begin
Result := tTitleBar.New(Form, Layout);
end;

end.
14 changes: 12 additions & 2 deletions src/Components/eTasks.Components.Interfaces.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@
interface

uses
FMX.Objects;
FMX.Objects,
FMX.Layouts;

type
TButtonAppBar = (ThemeBtn, MenuBtn);

TEventoClick = procedure(sender: TObject) of object;

iTitleBar = interface
['{CCA6D914-787E-495F-ADE7-F9472A0FBC45}']
function Render : TLayout;
function ChangeTitle(const Title: string): iTitleBar;
function isDarkMode(const value: boolean): iTitleBar;
end;

iAppBar = interface
['{D3781F3B-96FF-4017-9F8E-5472178C9ABB}']
function ChangeTitle(const Title: string): iAppBar;
function ShowTitleBar(const value: Boolean): TRectangle;
function Render: TRectangle;
function ThemeChangerClick(const Evento: TEventoClick): iAppBar;
function isDarkMode(const value: boolean): iAppBar;
function SetButtonAppBarAction(const ButtonAppBar: TButtonAppBar; const Action: TEventoClick): iAppBar;
end;

implementation
Expand Down
38 changes: 32 additions & 6 deletions src/View/eTasks.View.Main.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,38 @@ object fMain: TfMain
OnCreate = FormCreate
OnResize = FormResize
DesignerMasterStyle = 0
object Button1: TButton
Position.X = 112.000000000000000000
Position.Y = 320.000000000000000000
object MainLayout: TLayout
Align = Client
Size.Width = 360.000000000000000000
Size.Height = 480.000000000000000000
Size.PlatformDefault = False
TabOrder = 1
end
object MultiView1: TMultiView
DrawerOptions.Placement = Right
Mode = Drawer
NavigationPaneOptions.CollapsedWidth = 209.000000000000000000
ClipParent = True
Size.Width = 328.000000000000000000
Size.Height = 480.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
Text = 'Button1'
TextSettings.Trimming = None
OnClick = Button1Click
object Layout1: TLayout
Align = Client
Size.Width = 328.000000000000000000
Size.Height = 480.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
object Rectangle1: TRectangle
Align = Client
ClipChildren = True
Corners = [TopLeft]
Size.Width = 328.000000000000000000
Size.Height = 480.000000000000000000
Size.PlatformDefault = False
XRadius = 75.000000000000000000
YRadius = 75.000000000000000000
end
end
end
end
44 changes: 26 additions & 18 deletions src/View/eTasks.View.Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@ interface
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Effects,
FMX.Objects, FMX.Controls.Presentation, FMX.StdCtrls, FMX.Layouts,
eTasks.Components.TitleBar,
eTasks.Components.Interfaces;
eTasks.Components.Interfaces, FMX.MultiView;

type
TTeste = procedure of Object;

TfMain = class(TForm)
Button1: TButton;
MultiView1: TMultiView;
MainLayout: TLayout;
Layout1: TLayout;
Rectangle1: TRectangle;
procedure FormResize(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
AppBar : iAppBar;
TitleBar : iTitleBar;
fDarkMode : Boolean;
procedure SetTheme(sender : TObject);
procedure OpenMenu(sender: TObject);
public
{ Public declarations }
end;
Expand All @@ -37,21 +40,13 @@ implementation

{$R *.fmx}

procedure TfMain.Button1Click(Sender: TObject);
begin
fDarkMode := not fDarkMode;
TitleBar.ChangeTitle('Meu Teste');
AppBar.ChangeTitle('Outro teste');
AppBar.isDarkMode(fDarkMode);
Self.Fill.Color := TColorPallete.GetColor(Background, fDarkMode);
end;

procedure TfMain.FormCreate(Sender: TObject);
begin
fDarkMode := False;
AppBar := TComponentBars.AppBar(fMain).isDarkMode(fDarkMode);
TitleBar := TTitleBar.New(fMain);
AppBar.ThemeChangerClick(Button1Click);
AppBar := TComponentBars.AppBar(fMain, MainLayout).isDarkMode(fDarkMode);
TitleBar := TComponentBars.TitleBar(fMain, MainLayout);
AppBar.SetButtonAppBarAction(ThemeBtn, SetTheme);
AppBar.SetButtonAppBarAction(MenuBtn, OpenMenu);
end;

procedure TfMain.FormResize(Sender: TObject);
Expand All @@ -65,13 +60,26 @@ procedure TfMain.FormResize(Sender: TObject);
if(fMain.Width <= 768)then
begin
AppBar.ShowTitleBar(false);
TitleBar.Layout.Visible := true;
TitleBar.Render.Visible := true;
end
else
begin
AppBar.ShowTitleBar(True);
TitleBar.Layout.Visible := false;
TitleBar.Render.Visible := false;
end;
end;

procedure TfMain.OpenMenu(sender: TObject);
begin
MultiView1.ShowMaster;
end;

procedure TfMain.SetTheme(sender: TObject);
begin
fDarkMode := not fDarkMode;
AppBar.isDarkMode(fDarkMode);
TitleBar.isDarkMode(fDarkMode);
Self.Fill.Color := TColorPallete.GetColor(Background, fDarkMode);
end;

end.

0 comments on commit ec25538

Please sign in to comment.