Skip to content

Commit

Permalink
TNewTabSet: Auto-adjust Height.
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanrussell authored Nov 29, 2024
1 parent 0eb19b4 commit 37ddb8b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Components/NewTabSet.pas
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ TNewTabSet = class(TCustomControl)
procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;
procedure WMThemeChanged(var Message: TMessage); message WM_THEMECHANGED;
function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
Expand All @@ -69,6 +70,7 @@ TNewTabSet = class(TCustomControl)
property Theme: TTheme read FTheme write SetTheme;
published
property Align;
property AutoSize default True;
property Font;
property Hints: TStrings read FHints write SetHints;
property ParentFont;
Expand Down Expand Up @@ -178,17 +180,18 @@ constructor TNewTabSet.Create(AOwner: TComponent);
FTabPosition := tpBottom;
FHints := TStringList.Create;
TStringList(FHints).OnChange := HintsListChanged;
FHotIndex := -1;
ControlStyle := ControlStyle + [csOpaque];
Width := 129;
Height := 21;
FHotIndex := -1;
AutoSize := True;
end;

procedure TNewTabSet.CreateParams(var Params: TCreateParams);
begin
inherited;
with Params.WindowClass do
style := style and not (CS_HREDRAW or CS_VREDRAW);
style := style and not CS_HREDRAW;
end;

procedure TNewTabSet.CreateWnd;
Expand Down Expand Up @@ -279,6 +282,15 @@ procedure TNewTabSet.EnsureCurrentTabIsFullyVisible;
end;
end;

function TNewTabSet.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
begin
{ We need to manage our own height for correct results with non-default PPI }
Canvas.Font.Assign(Font);
NewHeight := Canvas.TextHeight('0') + (ToCurrentPPI(TabPaddingY) * 2) +
ToCurrentPPI(2);
Result := True;
end;

function TNewTabSet.GetTabRect(const Index: Integer;
const ApplyTabsOffset: Boolean = True): TRect;
var
Expand Down

0 comments on commit 37ddb8b

Please sign in to comment.