From 37ddb8b962700e3e70934ba2d8bd432ade0100ec Mon Sep 17 00:00:00 2001 From: Jordan Russell Date: Fri, 29 Nov 2024 04:01:52 -0600 Subject: [PATCH] TNewTabSet: Auto-adjust Height. --- Components/NewTabSet.pas | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Components/NewTabSet.pas b/Components/NewTabSet.pas index 41ddbe70b..eb16bf232 100644 --- a/Components/NewTabSet.pas +++ b/Components/NewTabSet.pas @@ -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; @@ -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; @@ -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; @@ -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