Delphi Can
Özel bir TVertScrollBox - Baskı Önizleme

+- Delphi Can (https://www.delphican.com)
+-- Forum: Delphi (https://www.delphican.com/forumdisplay.php?fid=3)
+--- Forum: Mobil Platform - FireMonkey (FMX) (https://www.delphican.com/forumdisplay.php?fid=7)
+--- Konu Başlığı: Özel bir TVertScrollBox (/showthread.php?tid=3079)



Özel bir TVertScrollBox - narkotik - 28-12-2018

Merhaba ;
Mobil uygulamalarımda dinamik nesne oluşumlarında sürekli ihtiyaç duyduğum için ufak çaplı özel bir VertScrollBox yazdım.İki özelliği bulunmakta.

1-) Siz içerisine dinamik oluşturduğunuz nesleri ekledikçe flowpanel gibi ekleyerek gider. Farkı scroll otomatik çıkar. Margin değerleri verebilirsiniz. Kolon sayısını siz belirlersiniz.

2-) Responsive, Kolon değerini ve margin değerlerini vermezsiniz. İçerisine nesne ekledikçe nesnelerin boyunu otomatik ayarlar. Bunu yapmamın nedeni scrollsuz tam sığdırma yapar.

Not ; Gelliştirilebilir, çok vaktim olmadığı için üstüne koymuyorum. İlgilen arkadaşlar geliştirmeye devam edebilir. Bizde faydalanmış oluruz. 

Sample Proje Link

16DQ8b.png

grV37Q.png

unit NrVertScrollBox;

interface
 uses System.SysUtils, System.Types, System.UITypes, FMX.Controls, System.Classes, FMX.Layouts, Math;

 type
 TNrVertScrollBox = class(TVertScrollBox)
 private
   ObjectWidth  : Single;
   ObjectHeight : Single;
   FColumnCount: Integer;
   FRightMargin: Integer;
   FBottomMargin: Integer;
   FResponsive: Boolean;
   FSumWidth: Single;
   FSumHeight: Single;
   FItemCount: integer;
   procedure SetColumnCount(const Value: Integer);
   procedure SetRightMargin(const Value: Integer);
   procedure SetBottomMargin(const Value: Integer);
   procedure SetResponsive(const Value: Boolean);
   procedure ResWH;
   procedure SetSumHeight(const Value: Single);
   procedure SetSumWidth(const Value: Single);
   procedure SetItemCount(const Value: integer);
   { private declarations }
 protected
   { protected declarations }
 public
   constructor Create(AOwner: TComponent;AColumnCount,ARightMargin,ABottomMargin:Integer;AResponsive:Boolean);
   destructor  Destroy; override;
   procedure ItemsAdd(Control:TControl);
 published
   property ItemCount:integer read FItemCount write SetItemCount;
   property SumWidth:Single read FSumWidth write SetSumWidth;
   property SumHeight:Single read FSumHeight write SetSumHeight;
   property ColumnCount: Integer read FColumnCount write SetColumnCount;
   property RightMargin: Integer read FRightMargin write SetRightMargin;
   property BottomMargin: Integer read FBottomMargin write SetBottomMargin;
   property Responsive: Boolean read FResponsive write SetResponsive;
 end;

implementation

{ TNrVertScrollBox }

constructor TNrVertScrollBox.Create(AOwner: TComponent;AColumnCount,ARightMargin,ABottomMargin:Integer;AResponsive:Boolean);
begin
 inherited Create(AOwner);
 ColumnCount  := AColumnCount;
 RightMargin  := ARightMargin;
 BottomMargin := ABottomMargin;
 Responsive   := AResponsive;
 SumWidth     := 0; SumHeight    := 0; ItemCount    := 0; ObjectWidth  := 0; ObjectHeight := 0;
end;

destructor TNrVertScrollBox.Destroy;
begin
 //
 inherited;
end;

procedure TNrVertScrollBox.ResWH;
function X:Integer;
begin
  case ItemCount of
   0..1   : Result := 1;  2..4   : Result := 2;  5..12  : Result := 3;
   13..20 : Result := 4;  21..28 : Result := 5;  29..36 : Result := 6;
   37..44 : Result := 7;  45..52 : Result := 8;  53..60 : Result := 9;
   61..68 : Result := 10; 69..76 : Result := 11; 77..84 : Result := 12;
   85..94 : Result := 13; else     Result := 14;
  end;
end;
begin
ColumnCount  :=  X;
ObjectWidth  := (Width-1)  / ColumnCount;
ObjectHeight := (Height-1) / Ceil((ItemCount/ColumnCount));
end;

procedure TNrVertScrollBox.ItemsAdd(Control: TControl);
Var Ind : Integer;
begin
 if not Responsive then
 begin
   if ObjectWidth = 0 then
   begin
     ObjectWidth      := (Width-(Pred(ColumnCount)*RightMargin))/ColumnCount;
     ObjectHeight     := ObjectWidth;
   end;
   BeginUpdate;
   Control.BeginUpdate;
   Control.Width      := ObjectWidth;
   Control.Height     := ObjectHeight;
   Control.Parent     := Self;
   Control.Position.X := SumWidth;
   Control.Position.Y := SumHeight;
   if (Succ(ItemCount)) mod ColumnCount <> 0 then
     SumWidth  := SumWidth + ObjectWidth + RightMargin
   else
   begin
     SumWidth  := 0;
     SumHeight := SumHeight + ObjectHeight + BottomMargin;
   end;
   InsertComponent(Control);
   ItemCount := Succ(ItemCount);
   Control.EndUpdate;
   EndUpdate;
 end
 else
 begin
   ItemCount := Succ(ItemCount);
   ResWH;
   BeginUpdate;
   Control.Parent := Self;
   InsertComponent(Control);
   SumWidth  := 0; SumHeight := 0; ItemCount := 0;
   for Ind := 0 to Pred(ComponentCount) do
   begin
     if Components[Ind].ClassType = Control.ClassType then
     begin
       with TControl(Components[Ind]) do
       begin
         BeginUpdate;
         Width       := ObjectWidth;
         Height      := ObjectHeight;
         Position.X  := SumWidth;
         Position.Y  := SumHeight;
         if (Succ(ItemCount)) mod ColumnCount <> 0 then
           SumWidth  := SumWidth + ObjectWidth
         else
         begin
           SumWidth  := 0;
           SumHeight := SumHeight + ObjectHeight
         end;
         EndUpdate;
       end;
       ItemCount := Succ(ItemCount);
     end;
   end;
   EndUpdate;
 end;
end;

procedure TNrVertScrollBox.SetBottomMargin(const Value: Integer);
begin
 FBottomMargin := Value;
end;

procedure TNrVertScrollBox.SetColumnCount(const Value: Integer);
begin
 FColumnCount := Value;
end;

procedure TNrVertScrollBox.SetItemCount(const Value: integer);
begin
 FItemCount := Value;
end;

procedure TNrVertScrollBox.SetResponsive(const Value: Boolean);
begin
 FResponsive := Value;
end;

procedure TNrVertScrollBox.SetRightMargin(const Value: Integer);
begin
 FRightMargin := Value;
end;

procedure TNrVertScrollBox.SetSumHeight(const Value: Single);
begin
 FSumHeight := Value;
end;

procedure TNrVertScrollBox.SetSumWidth(const Value: Single);
begin
 FSumWidth := Value;
end;

end.



Özel bir TVertScrollBox - frmman - 28-12-2018

Teşekkürler elinize sağlık


Özel bir TVertScrollBox - klavye - 28-12-2018

Teşekkürler.


Cvp: Özel bir TVertScrollBox - CesuR - 18-02-2019

Elinize sağlık güzel olmuş. Fakat scroll çubuğu sağda en son eklenen nesnenin üzerine denk geliyor. Bunu şöyle düzelttim. Rightmargine +30 ekledim.
ObjectWidth      := (Width-(Pred(ColumnCount)*RightMargin+30))/ColumnCount;



nQNOyl.png


Özel bir TVertScrollBox - narkotik - 18-02-2019

Scroll Windows için böyle gözükebilir, mobil için derlediginizde tam çıkacaktır