You've already forked lazarus-ccr
jvcllaz: Add/improve LCLscaling for TJvTabBar and TJvPageList. Publish TJvPageList.BorderSpacing and .ChildSizing.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7417 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -231,7 +231,9 @@ type
|
|||||||
property Align;
|
property Align;
|
||||||
property Anchors;
|
property Anchors;
|
||||||
property BiDiMode;
|
property BiDiMode;
|
||||||
|
property BorderSpacing;
|
||||||
property BorderWidth;
|
property BorderWidth;
|
||||||
|
property ChildSizing;
|
||||||
property DragCursor;
|
property DragCursor;
|
||||||
property DragKind;
|
property DragKind;
|
||||||
property OnStartDock;
|
property OnStartDock;
|
||||||
@ -365,6 +367,7 @@ end;
|
|||||||
procedure TJvCustomPage.DoPaint(ACanvas: TCanvas; ARect: TRect);
|
procedure TJvCustomPage.DoPaint(ACanvas: TCanvas; ARect: TRect);
|
||||||
var
|
var
|
||||||
S: string;
|
S: string;
|
||||||
|
margin: Integer;
|
||||||
begin
|
begin
|
||||||
ACanvas.Font := Font;
|
ACanvas.Font := Font;
|
||||||
ACanvas.Brush.Style := bsSolid;
|
ACanvas.Brush.Style := bsSolid;
|
||||||
@ -384,7 +387,8 @@ begin
|
|||||||
if S = '' then
|
if S = '' then
|
||||||
S := Name;
|
S := Name;
|
||||||
// make some space around the edges
|
// make some space around the edges
|
||||||
InflateRect(ARect, -4, -4);
|
margin := Scale96ToFont(4);
|
||||||
|
InflateRect(ARect, -margin, -margin);
|
||||||
if not Enabled then
|
if not Enabled then
|
||||||
begin
|
begin
|
||||||
SetBkMode(ACanvas.Handle, LCLType.TRANSPARENT);
|
SetBkMode(ACanvas.Handle, LCLType.TRANSPARENT);
|
||||||
@ -394,7 +398,7 @@ begin
|
|||||||
ACanvas.Font.Color := clGrayText;
|
ACanvas.Font.Color := clGrayText;
|
||||||
end;
|
end;
|
||||||
DrawText(ACanvas.Handle, PChar(S), Length(S), ARect, GetDesignCaptionFlags(PageList.ShowDesignCaption) or DT_SINGLELINE);
|
DrawText(ACanvas.Handle, PChar(S), Length(S), ARect, GetDesignCaptionFlags(PageList.ShowDesignCaption) or DT_SINGLELINE);
|
||||||
InflateRect(ARect, 4, 4);
|
InflateRect(ARect, +margin, +margin);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
if Assigned(FOnPaint) then
|
if Assigned(FOnPaint) then
|
||||||
|
@ -26,7 +26,7 @@ Known Issues:
|
|||||||
unit JvTabBar;
|
unit JvTabBar;
|
||||||
|
|
||||||
{$MODE objfpc}{$H+}
|
{$MODE objfpc}{$H+}
|
||||||
{.$DEFINE JVCLThemesEnabled}
|
{$DEFINE JVCLThemesEnabled}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
@ -47,20 +47,6 @@ type
|
|||||||
TJvGetModifiedEvent = procedure(Sender: TJvTabBarItem; var Modified: Boolean) of object;
|
TJvGetModifiedEvent = procedure(Sender: TJvTabBarItem; var Modified: Boolean) of object;
|
||||||
TJvGetEnabledEvent = procedure(Sender: TJvTabBarItem; var Enabled: Boolean) of object;
|
TJvGetEnabledEvent = procedure(Sender: TJvTabBarItem; var Enabled: Boolean) of object;
|
||||||
|
|
||||||
(*
|
|
||||||
IPageList = interface
|
|
||||||
['{6BB90183-CFB1-4431-9CFD-E9A032E0C94C}']
|
|
||||||
function CanChange(AIndex: Integer): Boolean;
|
|
||||||
procedure SetActivePageIndex(AIndex: Integer);
|
|
||||||
function GetPageCount: Integer;
|
|
||||||
function GetPageCaption(AIndex: Integer): string;
|
|
||||||
procedure AddPage(const ACaption: string);
|
|
||||||
procedure DeletePage(Index: Integer);
|
|
||||||
procedure MovePage(CurIndex, NewIndex: Integer);
|
|
||||||
procedure PageCaptionChanged(Index: Integer; const NewCaption: string);
|
|
||||||
end;
|
|
||||||
*)
|
|
||||||
|
|
||||||
TJvTabBarItem = class(TCollectionItem)
|
TJvTabBarItem = class(TCollectionItem)
|
||||||
private
|
private
|
||||||
FLeft: Integer; // used for calculating DisplayRect
|
FLeft: Integer; // used for calculating DisplayRect
|
||||||
@ -167,7 +153,6 @@ type
|
|||||||
function GetTabBar(ATab: TJvTabBarItem): TJvCustomTabBar;
|
function GetTabBar(ATab: TJvTabBarItem): TJvCustomTabBar;
|
||||||
function GetTabSize(Canvas: TCanvas; Tab: TJvTabBarItem): TSize; virtual; abstract;
|
function GetTabSize(Canvas: TCanvas; Tab: TJvTabBarItem): TSize; virtual; abstract;
|
||||||
function Options: TJvTabBarPainterOptions; virtual; abstract;
|
function Options: TJvTabBarPainterOptions; virtual; abstract;
|
||||||
function Scale96(AValue: Integer): Integer;
|
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -381,6 +366,12 @@ type
|
|||||||
|
|
||||||
procedure SetHint(const Value: TCaption); override;
|
procedure SetHint(const Value: TCaption); override;
|
||||||
|
|
||||||
|
// LCL scaling
|
||||||
|
{$IF LCL_FullVersion >= 1080000}
|
||||||
|
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
|
||||||
|
const AXProportion, AYProportion: Double); override;
|
||||||
|
{$IFEND}
|
||||||
|
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -514,6 +505,16 @@ const
|
|||||||
CLOSE_BUTTON_SIZE = 12; // size of the close button box
|
CLOSE_BUTTON_SIZE = 12; // size of the close button box
|
||||||
CROSS_MARGIN = 8; // Margin of the "x" inside the close button
|
CROSS_MARGIN = 8; // Margin of the "x" inside the close button
|
||||||
|
|
||||||
|
var
|
||||||
|
LeftMargin: Integer = LEFT_MARGIN;
|
||||||
|
RightMargin: Integer = RIGHT_MARGIN;
|
||||||
|
TextMarginLeft: Integer = TEXT_MARGIN_LEFT;
|
||||||
|
TextMarginRight: Integer = TEXT_MARGIN_RIGHT;
|
||||||
|
TopMargin: Integer = TOP_MARGIN;
|
||||||
|
BottomMargin: Integer = BOTTOM_MARGIN;
|
||||||
|
CloseButtonSize: Integer = CLOSE_BUTTON_SIZE;
|
||||||
|
CrossMargin: Integer = CROSS_MARGIN;
|
||||||
|
|
||||||
|
|
||||||
function DrawButtonFace(ACanvas: TCanvas; const ARect: TRect; AFlat: Boolean;
|
function DrawButtonFace(ACanvas: TCanvas; const ARect: TRect; AFlat: Boolean;
|
||||||
// BevelWidth: Integer; Style: TButtonStyle; IsRounded,
|
// BevelWidth: Integer; Style: TButtonStyle; IsRounded,
|
||||||
@ -1428,8 +1429,6 @@ end;
|
|||||||
procedure TJvCustomTabBar.CalculatePreferredSize(
|
procedure TJvCustomTabBar.CalculatePreferredSize(
|
||||||
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
|
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
|
||||||
var
|
var
|
||||||
// tabSize: TSize;
|
|
||||||
// imgSize: TSize;
|
|
||||||
h: Integer;
|
h: Integer;
|
||||||
{$IF LCL_FullVersion >= 1090000}
|
{$IF LCL_FullVersion >= 1090000}
|
||||||
imgRes: TScaledImageListResolution;
|
imgRes: TScaledImageListResolution;
|
||||||
@ -1459,13 +1458,13 @@ begin
|
|||||||
|
|
||||||
// Close button height
|
// Close button height
|
||||||
if FCloseButton then begin
|
if FCloseButton then begin
|
||||||
h := Scale96ToForm(CLOSE_BUTTON_SIZE);
|
h := CloseButtonSize;
|
||||||
if h > PreferredHeight then
|
if h > PreferredHeight then
|
||||||
PreferredHeight := h;
|
PreferredHeight := h;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Margins
|
// Margins
|
||||||
inc(PreferredHeight, Scale96ToForm(TOP_MARGIN) + Scale96ToForm(BOTTOM_MARGIN));
|
inc(PreferredHeight, TopMargin + BottomMargin);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJvCustomTabBar.Paint;
|
procedure TJvCustomTabBar.Paint;
|
||||||
@ -1823,6 +1822,27 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$IF LCL_FullVersion >= 1080000}
|
||||||
|
procedure TJvCustomTabBar.DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
|
||||||
|
const AXProportion, AYProportion: Double);
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
|
||||||
|
begin
|
||||||
|
FMargin := round(FMargin * AXProportion);
|
||||||
|
|
||||||
|
LeftMargin := round(LEFT_MARGIN * AXProportion);
|
||||||
|
RightMargin := round(RIGHT_MARGIN * AXProportion);
|
||||||
|
TextMarginLeft := round(TEXT_MARGIN_LEFT * AXProportion);
|
||||||
|
TextMarginRight := round(TEXT_MARGIN_RIGHT * AXProportion);
|
||||||
|
TopMargin := round(TOP_MARGIN * AYProportion);
|
||||||
|
BottomMargin := round(BOTTOM_MARGIN * AYProportion);
|
||||||
|
CloseButtonSize := round(CLOSE_BUTTON_SIZE * AXProportion);
|
||||||
|
CrossMargin := round(CROSS_MARGIN * AXProportion);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
{$IFEND}
|
||||||
|
|
||||||
//=== { TJvTabBarItem } ======================================================
|
//=== { TJvTabBarItem } ======================================================
|
||||||
|
|
||||||
constructor TJvTabBarItem.Create(ACollection: Classes.TCollection);
|
constructor TJvTabBarItem.Create(ACollection: Classes.TCollection);
|
||||||
@ -2233,6 +2253,8 @@ const
|
|||||||
var
|
var
|
||||||
details: TThemedElementDetails;
|
details: TThemedElementDetails;
|
||||||
{$ENDIF JVCLThemesEnabled}
|
{$ENDIF JVCLThemesEnabled}
|
||||||
|
var
|
||||||
|
dx, dy: Integer;
|
||||||
begin
|
begin
|
||||||
{$IFDEF JVCLThemesEnabled}
|
{$IFDEF JVCLThemesEnabled}
|
||||||
if ThemeServices.ThemesEnabled then begin
|
if ThemeServices.ThemesEnabled then begin
|
||||||
@ -2244,18 +2266,22 @@ begin
|
|||||||
DrawButtonFace(Canvas, R, TabBar.FlatScrollButtons, State = sbsPressed, false);
|
DrawButtonFace(Canvas, R, TabBar.FlatScrollButtons, State = sbsPressed, false);
|
||||||
if State = sbsPressed then
|
if State = sbsPressed then
|
||||||
OffsetRect(R, 1, 1);
|
OffsetRect(R, 1, 1);
|
||||||
|
{$IF LCL_FullVersion >= 1080000}
|
||||||
|
dx := TabBar.Scale96ToFont(4);
|
||||||
|
dy := TabBar.Scale96ToFont(7);
|
||||||
|
{$ELSE}
|
||||||
|
dx := MulDiv(4, GetPixelsPerInch, 96);
|
||||||
|
dy := MulDiv(7, GetPixelsPerInch, 96);
|
||||||
|
{$IFEND}
|
||||||
TabBar.DrawScrollBarGlyph(Canvas,
|
TabBar.DrawScrollBarGlyph(Canvas,
|
||||||
R.Left + (R.Right - R.Left - 4) div 2,
|
R.Left + (R.Right - R.Left - dx) div 2,
|
||||||
R.Top + (R.Bottom - R.Top - 7) div 2,
|
R.Top + (R.Bottom - R.Top - dy) div 2,
|
||||||
Button = sbScrollLeft, State = sbsDisabled);
|
Button = sbScrollLeft,
|
||||||
|
State = sbsDisabled
|
||||||
|
);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJvTabBarPainter.Scale96(AValue: Integer): Integer;
|
|
||||||
begin
|
|
||||||
Result := MulDiv(AValue, GetPixelsPerInch, 96);
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
//=== { TJvModernTabBarPainter } =============================================
|
//=== { TJvModernTabBarPainter } =============================================
|
||||||
|
|
||||||
@ -2436,8 +2462,8 @@ begin
|
|||||||
LineTo(R.Right - 1 - 1, R.Top);
|
LineTo(R.Right - 1 - 1, R.Top);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
inc(R.Left, Scale96(LEFT_MARGIN));
|
inc(R.Left, LeftMargin);
|
||||||
dec(R.Right, Scale96(RIGHT_MARGIN));
|
dec(R.Right, RightMargin);
|
||||||
|
|
||||||
if Tab.TabBar.CloseButton then
|
if Tab.TabBar.CloseButton then
|
||||||
begin
|
begin
|
||||||
@ -2471,7 +2497,7 @@ begin
|
|||||||
Pen.Width := 2;
|
Pen.Width := 2;
|
||||||
|
|
||||||
{ Draw close cross }
|
{ Draw close cross }
|
||||||
margin := Scale96(CROSS_MARGIN);
|
margin := CrossMargin;
|
||||||
Line(CloseR.Left + margin, CloseR.Top + margin, CloseR.Right - margin - 1, CloseR.Bottom - margin - 1);
|
Line(CloseR.Left + margin, CloseR.Top + margin, CloseR.Right - margin - 1, CloseR.Bottom - margin - 1);
|
||||||
Line(CloseR.Left + margin, CloseR.Bottom - margin - 1, CloseR.Right - margin - 1, CloseR.Top + margin);
|
Line(CloseR.Left + margin, CloseR.Bottom - margin - 1, CloseR.Right - margin - 1, CloseR.Top + margin);
|
||||||
{
|
{
|
||||||
@ -2479,7 +2505,7 @@ begin
|
|||||||
if Tab.Modified then
|
if Tab.Modified then
|
||||||
FillRect(Rect(CloseR.Left + 5, CloseR.Top + 4, CloseR.Right - 5, CloseR.Bottom - 4));
|
FillRect(Rect(CloseR.Left + 5, CloseR.Top + 4, CloseR.Right - 5, CloseR.Bottom - 4));
|
||||||
}
|
}
|
||||||
R.Right := CloseR.Left - Scale96(TEXT_MARGIN_RIGHT);
|
R.Right := CloseR.Left - TextMarginRight;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ Draw image from image list }
|
{ Draw image from image list }
|
||||||
@ -2498,7 +2524,7 @@ begin
|
|||||||
{$ELSE}
|
{$ELSE}
|
||||||
Tab.GetImages.Draw(Canvas, x, y, Tab.ImageIndex, Tab.Enabled);
|
Tab.GetImages.Draw(Canvas, x, y, Tab.ImageIndex, Tab.Enabled);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
Inc(R.Left, imgSize.CX + Scale96(TEXT_MARGIN_LEFT));
|
Inc(R.Left, imgSize.CX + TextMarginLeft);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if Tab.Enabled then
|
if Tab.Enabled then
|
||||||
@ -2525,8 +2551,8 @@ function TJvModernTabBarPainter.GetCloseRect(Canvas: TCanvas; Tab: TJvTabBarItem
|
|||||||
var
|
var
|
||||||
btnSize: TSize;
|
btnSize: TSize;
|
||||||
begin
|
begin
|
||||||
btnSize := Size(Scale96(CLOSE_BUTTON_SIZE), Scale96(CLOSE_BUTTON_SIZE));
|
btnSize := Size(CloseButtonSize, CloseButtonSize);
|
||||||
Result.Right := ATabRect.Right - Scale96(RIGHT_MARGIN);
|
Result.Right := ATabRect.Right - RightMargin;
|
||||||
Result.Left := Result.Right - btnSize.CX;
|
Result.Left := Result.Right - btnSize.CX;
|
||||||
Result.Top := (ATabRect.Top + ATabRect.Bottom - btnSize.CY) div 2;
|
Result.Top := (ATabRect.Top + ATabRect.Bottom - btnSize.CY) div 2;
|
||||||
Result.Bottom := Result.Top + btnSize.CY;
|
Result.Bottom := Result.Top + btnSize.CY;
|
||||||
@ -2562,12 +2588,12 @@ begin
|
|||||||
Result := Size(0, Canvas.TextHeight('Tg'))
|
Result := Size(0, Canvas.TextHeight('Tg'))
|
||||||
else
|
else
|
||||||
Result := Canvas.TextExtent(Tab.Caption);
|
Result := Canvas.TextExtent(Tab.Caption);
|
||||||
inc(Result.CX, Scale96(LEFT_MARGIN) + Scale96(RIGHT_MARGIN));
|
inc(Result.CX, LeftMargin + RightMargin);
|
||||||
|
|
||||||
// Extend width by close button
|
// Extend width by close button
|
||||||
if Tab.TabBar.CloseButton then begin
|
if Tab.TabBar.CloseButton then begin
|
||||||
w := Scale96(CLOSE_BUTTON_SIZE);
|
w := CloseButtonSize;
|
||||||
inc(Result.CX, w + Scale96(TEXT_MARGIN_RIGHT));
|
inc(Result.CX, w + TextMarginRight);
|
||||||
h := w;
|
h := w;
|
||||||
if Result.CY < h then
|
if Result.CY < h then
|
||||||
Result.CY := h;
|
Result.CY := h;
|
||||||
@ -2576,11 +2602,11 @@ begin
|
|||||||
// Extend width and height by image
|
// Extend width and height by image
|
||||||
if (Tab.ImageIndex <> -1) and (Tab.GetImages <> nil) then begin
|
if (Tab.ImageIndex <> -1) and (Tab.GetImages <> nil) then begin
|
||||||
imgSize := GetRealImageSize(Tab);
|
imgSize := GetRealImageSize(Tab);
|
||||||
inc(Result.CX, imgSize.CX + Scale96(TEXT_MARGIN_LEFT));
|
inc(Result.CX, imgSize.CX + TextMarginLeft);
|
||||||
if Result.CY < imgSize.CY then
|
if Result.CY < imgSize.CY then
|
||||||
Result.CY := imgSize.CY;
|
Result.CY := imgSize.CY;
|
||||||
end;
|
end;
|
||||||
inc(Result.CY, Scale96(TOP_MARGIN) + Scale96(BOTTOM_MARGIN));
|
inc(Result.CY, TopMargin + BottomMargin);
|
||||||
|
|
||||||
// Override width if TabWidth/TabHeight is fixed.
|
// Override width if TabWidth/TabHeight is fixed.
|
||||||
if TabWidth > 0 then
|
if TabWidth > 0 then
|
||||||
|
Reference in New Issue
Block a user