Skip to content

Commit

Permalink
custom image lists added to TChromeTab
Browse files Browse the repository at this point in the history
  • Loading branch information
landrix committed Nov 29, 2020
1 parent a346a0c commit 31cf05f
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Lib/ChromeTabs.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ function TCustomChromeTabs.ControlReady: Boolean;

procedure TCustomChromeTabs.DoOnChange(ATab: TChromeTab; TabChangeType: TTabChangeType);
var
i: Integer;
//i: Integer;
NewTabControl: TChromeTabControl;
NewTabLeft, LastVisibleTabIndex: Integer;
begin
Expand Down
60 changes: 60 additions & 0 deletions Lib/ChromeTabsClasses.pas
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ TChromeTabsLookAndFeelStyle = class;
function GetSpinnerState: TChromeTabSpinnerState;
function GetHideCloseButton: Boolean;
function GetData: Pointer;
function GetCustomImages: TCustomImageList;
function GetCustomImagesOverlay: TCustomImageList;
function GetCustomImagesSpinnerDownload: TCustomImageList;
function GetCustomImagesSpinnerUpload: TCustomImageList;
procedure SetData(const Value: Pointer);
property Data: Pointer read GetData write SetData;
end;
Expand Down Expand Up @@ -126,6 +130,10 @@ TChromeTab = class(TCollectionItem, IChromeTab)
FMarkedForDeletion: Boolean;
FSpinnerState: TChromeTabSpinnerState;
FHideCloseButton: Boolean;
FCustomImages: TCustomImageList;
FCustomImagesOverlay: TCustomImageList;
FCustomImagesSpinnerDownload: TCustomImageList;
FCustomImagesSpinnerUpload: TCustomImageList;

procedure SetActive(Value: boolean);
procedure SetCaption(Value: TCaption);
Expand Down Expand Up @@ -155,6 +163,14 @@ TChromeTab = class(TCollectionItem, IChromeTab)
function GetSpinnerState: TChromeTabSpinnerState;
function GetHideCloseButton: Boolean;
function GetData: Pointer;
procedure SetCustomImages(const Value: TCustomImageList);
procedure SetCustomImagesOverlay(const Value: TCustomImageList);
procedure SetCustomImagesSpinnerDownload(const Value: TCustomImageList);
procedure SetCustomImagesSpinnerUpload(const Value: TCustomImageList);
function GetCustomImages: TCustomImageList;
function GetCustomImagesOverlay: TCustomImageList;
function GetCustomImagesSpinnerDownload: TCustomImageList;
function GetCustomImagesSpinnerUpload: TCustomImageList;
protected
procedure DoChanged(ChangeType: TTabChangeType = tcPropertyUpdated); virtual;
function GetDisplayName: string; override;
Expand All @@ -175,6 +191,10 @@ TChromeTab = class(TCollectionItem, IChromeTab)
property Caption: TCaption read GetCaption write SetCaption;
property Active: boolean read GetActive write SetActive;
property Tag: integer read GetTag write SetTag;
property CustomImages: TCustomImageList read GetCustomImages write SetCustomImages;
property CustomImagesOverlay: TCustomImageList read GetCustomImagesOverlay write SetCustomImagesOverlay;
property CustomImagesSpinnerUpload: TCustomImageList read GetCustomImagesSpinnerUpload write SetCustomImagesSpinnerUpload;
property CustomImagesSpinnerDownload: TCustomImageList read GetCustomImagesSpinnerDownload write SetCustomImagesSpinnerDownload;
property ImageIndex: {$IF CompilerVersion >= 23.0}System.UITypes.{$IFEND}TImageIndex read GetImageIndex write SetImageIndex;
property ImageIndexOverlay: {$IF CompilerVersion >= 23.0}System.UITypes.{$IFEND}TImageIndex read GetImageIndexOverlay write SetImageIndexOverlay;
property Pinned: Boolean read GetPinned write SetPinned;
Expand Down Expand Up @@ -1239,6 +1259,46 @@ destructor TChromeTab.Destroy;
FTabControl.Free;
end;

procedure TChromeTab.SetCustomImages(const Value: TCustomImageList);
begin
FCustomImages := Value;
end;

procedure TChromeTab.SetCustomImagesOverlay(const Value: TCustomImageList);
begin
FCustomImagesOverlay := Value;
end;

procedure TChromeTab.SetCustomImagesSpinnerDownload(const Value: TCustomImageList);
begin
FCustomImagesSpinnerDownload := Value;
end;

procedure TChromeTab.SetCustomImagesSpinnerUpload(const Value: TCustomImageList);
begin
FCustomImagesSpinnerUpload := Value;
end;

function TChromeTab.GetCustomImages : TCustomImageList;
begin
Result := FCustomImages;
end;

function TChromeTab.GetCustomImagesOverlay : TCustomImageList;
begin
Result := FCustomImagesOverlay;
end;

function TChromeTab.GetCustomImagesSpinnerDownload : TCustomImageList;
begin
Result := FCustomImagesSpinnerDownload;
end;

function TChromeTab.GetCustomImagesSpinnerUpload : TCustomImageList;
begin
Result := FCustomImagesSpinnerUpload;
end;

procedure TChromeTab.SetPinned(const Value: Boolean);
var
LastPinned: Integer;
Expand Down
54 changes: 40 additions & 14 deletions Lib/ChromeTabsControls.pas
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ TChromeTabControl = class(TBaseChromeTabsControl)
procedure CalculateRects(var ImageRect, TextRect, CloseButtonRect,
CloseButtonCrossRect: TRect; var NormalImageVisible, OverlayImageVisible, SpinnerVisible,
TextVisible: Boolean);
function GetImageList: TCustomImageList;
function GetImageListOverlay: TCustomImageList;
function GetSpinnerImageList: TCustomImageList;
protected
procedure SetCloseButtonState(const Value: TDrawState); virtual;
Expand Down Expand Up @@ -638,6 +640,20 @@ function TChromeTabControl.GetHitTestArea(MouseX, MouseY: Integer): THitTestArea
end;
end;

function TChromeTabControl.GetImageList: TCustomImageList;
begin
Result := ChromeTab.GetCustomImages;
if Result = nil then
Result := ChromeTabs.GetImages;
end;

function TChromeTabControl.GetImageListOverlay: TCustomImageList;
begin
Result := ChromeTab.GetCustomImagesOverlay;
if Result = nil then
Result := ChromeTabs.GetImagesOverlay;
end;

function TChromeTabControl.AnimateModified: Boolean;
var
TickCount: Cardinal;
Expand Down Expand Up @@ -685,8 +701,18 @@ function TChromeTabControl.AnimateModified: Boolean;
function TChromeTabControl.GetSpinnerImageList: TCustomImageList;
begin
case ChromeTab.GetSpinnerState of
tssImageUpload: Result := ChromeTabs.GetImagesSpinnerUpload;
tssImageDownload: Result := ChromeTabs.GetImagesSpinnerDownload;
tssImageUpload:
begin
Result := ChromeTab.GetCustomImagesSpinnerUpload;
if Result = nil then
Result := ChromeTabs.GetImagesSpinnerUpload;
end;
tssImageDownload:
begin
Result := ChromeTab.GetCustomImagesSpinnerDownload;
if Result = nil then
Result := ChromeTabs.GetImagesSpinnerDownload;
end
else
Result := nil;
end;
Expand Down Expand Up @@ -971,8 +997,8 @@ procedure TChromeTabControl.CalculateRects(var ImageRect, TextRect,
LeftOffset := ControlRect.Left +
ChromeTabs.ScaledPixels(ChromeTabs.GetOptions.Display.Tabs.ContentOffsetLeft);

NormalImageVisible := ImageVisible(ChromeTabs.GetImages, ChromeTab.GetImageIndex);
OverlayImageVisible := ImageVisible(ChromeTabs.GetImagesOverlay, ChromeTab.GetImageIndexOverlay);
NormalImageVisible := ImageVisible(GetImageList, ChromeTab.GetImageIndex);
OverlayImageVisible := ImageVisible(GetImageListOverlay, ChromeTab.GetImageIndexOverlay);
SpinnerVisible := (ChromeTab.GetSpinnerState <> tssNone) and (not (csDesigning in ChromeTabs.GetComponentState));

ImageWidth := 0;
Expand All @@ -997,20 +1023,20 @@ procedure TChromeTabControl.CalculateRects(var ImageRect, TextRect,
(NormalImageVisible) or
(OverlayImageVisible) then
begin
if ChromeTabs.ScaledPixels(ChromeTabs.GetImages.Width) > ImageWidth then
ImageWidth := ChromeTabs.ScaledPixels(ChromeTabs.GetImages.Width);
if ChromeTabs.ScaledPixels(GetImageList.Width) > ImageWidth then
ImageWidth := ChromeTabs.ScaledPixels(GetImageList.Width);

if ChromeTabs.ScaledPixels(ChromeTabs.GetImages.Height) > ImageHeight then
ImageHeight := ChromeTabs.ScaledPixels(ChromeTabs.GetImages.Height);
if ChromeTabs.ScaledPixels(GetImageList.Height) > ImageHeight then
ImageHeight := ChromeTabs.ScaledPixels(GetImageList.Height);
end;

if OverlayImageVisible then
begin
if ChromeTabs.ScaledPixels(ChromeTabs.GetImagesOverlay.Width) > ChromeTabs.ScaledPixels(ChromeTabs.GetImages.Width) then
ImageWidth := ChromeTabs.ScaledPixels(ChromeTabs.GetImagesOverlay.Width);
if ChromeTabs.ScaledPixels(GetImageListOverlay.Width) > ChromeTabs.ScaledPixels(GetImageList.Width) then
ImageWidth := ChromeTabs.ScaledPixels(GetImageListOverlay.Width);

if ChromeTabs.ScaledPixels(ChromeTabs.GetImagesOverlay.Height) > ChromeTabs.ScaledPixels(ChromeTabs.GetImages.Height) then
ImageHeight := ChromeTabs.ScaledPixels(ChromeTabs.GetImagesOverlay.Height);
if ChromeTabs.ScaledPixels(GetImageListOverlay.Height) > ChromeTabs.ScaledPixels(GetImageList.Height) then
ImageHeight := ChromeTabs.ScaledPixels(GetImageListOverlay.Height);
end;

// Does the image fit between the left margin and the close button?
Expand Down Expand Up @@ -1521,10 +1547,10 @@ procedure TChromeTabControl.DrawTo(TabCanvas: TGPGraphics; MouseX, MouseY: Integ
(not ChromeTabs.GetOptions.Display.TabSpinners.HideImagesWhenSpinnerVisible) then
begin
if NormalImageVisible then
DrawImage(ChromeTabs.GetImages, ChromeTab.GetImageIndex, ImageRect, itTabImage);
DrawImage(GetImageList, ChromeTab.GetImageIndex, ImageRect, itTabImage);

if OverlayImageVisible then
DrawImage(ChromeTabs.GetImagesOverlay, ChromeTab.GetImageIndexOverlay, ImageRect, itTabImageOverlay);
DrawImage(GetImageListOverlay, ChromeTab.GetImageIndexOverlay, ImageRect, itTabImageOverlay);
end;

// Draw the spinner image
Expand Down

0 comments on commit 31cf05f

Please sign in to comment.