SpkToolbar: Support RTL in Tab and MenuButton layout of SpkToolbar

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8958 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-10-13 10:08:22 +00:00
parent 130a06d6dd
commit b5c1e6aeb3

View File

@ -1645,10 +1645,14 @@ procedure TSpkToolbar.ValidateBuffer;
x, y: integer; x, y: integer;
TabRect: T2DIntRect; TabRect: T2DIntRect;
clr: TColor; clr: TColor;
ts: TTextStyle;
begin begin
TabRect := FTabRects[index]; TabRect := FTabRects[index];
FBuffer.canvas.font.Assign(AFont); FBuffer.Canvas.Font.Assign(AFont);
ts := FBuffer.Canvas.TextStyle;
ts.RightToLeft := IsRightToLeft;
FBuffer.Canvas.TextStyle := ts;
if AOverrideTextColor <> clNone then if AOverrideTextColor <> clNone then
clr := AOverrideTextColor else clr := AOverrideTextColor else
@ -1861,7 +1865,8 @@ procedure TSpkToolbar.ValidateBuffer;
CurrentAppearance := FAppearance; CurrentAppearance := FAppearance;
if CurrentAppearance.Tab.GradientType = bkSolid then if CurrentAppearance.Tab.GradientType = bkSolid then
delta := 0 else delta := 0
else
delta := 50; delta := 50;
//TabRect := FTabRects[i]; //TabRect := FTabRects[i];
@ -1951,7 +1956,6 @@ procedure TSpkToolbar.ValidateBuffer;
FMenuButtonRect.Left + aCornerRadius - 1, FMenuButtonRect.Left + aCornerRadius - 1,
FMenuButtonRect.Top + aCornerRadius, FMenuButtonRect.Top + aCornerRadius,
FMenuButtonRect.Right - aCornerRadius + 1 + 1, FMenuButtonRect.Right - aCornerRadius + 1 + 1,
// FMenuButtonRect.Bottom + 1
FMenuButtonRect.Bottom FMenuButtonRect.Bottom
); );
@ -1995,8 +1999,8 @@ procedure TSpkToolbar.ValidateBuffer;
// Draw left vertical line of Menu Button // Draw left vertical line of Menu Button
if DrawRounded then if DrawRounded then
TGuiTools.DrawVLine(FBuffer, TGuiTools.DrawVLine(FBuffer,
FMenuButtonRect.left + aCornerRadius - 1, FMenuButtonRect.Left + aCornerRadius - 1,
FMenuButtonRect.top + aCornerRadius, FMenuButtonRect.Top + aCornerRadius,
FMenuButtonRect.Bottom - 1, FMenuButtonRect.Bottom - 1,
BorderColor, BorderColor,
FTabClipRect) FTabClipRect)
@ -2083,15 +2087,15 @@ procedure TSpkToolbar.ValidateBuffer;
Case FMenuButtonStyle of Case FMenuButtonStyle of
mbsCaption: mbsCaption:
begin begin
x := FMenuButtonRect.left + (FMenuButtonRect.Width - FBuffer.Canvas.textwidth( x := FMenuButtonRect.Left + (FMenuButtonRect.Width - FBuffer.Canvas.textwidth(
FMenuButtonCaption)) div 2; FMenuButtonCaption)) div 2;
y := FMenuButtonRect.top + (FMenuButtonRect.Height - FBuffer.Canvas.Textheight('Wy')) div 2; y := FMenuButtonRect.Top + (FMenuButtonRect.Height - FBuffer.Canvas.Textheight('Wy')) div 2;
end; end;
mbsCaptionDropdown: mbsCaptionDropdown:
begin begin
x := FMenuButtonRect.left + (FMenuButtonRect.Width - FBuffer.Canvas.textwidth( x := FMenuButtonRect.Left + (FMenuButtonRect.Width - FBuffer.Canvas.textwidth(
FMenuButtonCaption) - SmallButtonDropdownWidth) div 2; FMenuButtonCaption) - SmallButtonDropdownWidth) div 2;
y := FMenuButtonRect.top + (FMenuButtonRect.Height - FBuffer.Canvas.Textheight('Wy')) div 2; y := FMenuButtonRect.Top + (FMenuButtonRect.Height - FBuffer.Canvas.Textheight('Wy')) div 2;
end; end;
end; end;
@ -2233,6 +2237,8 @@ var
AdditionalPadding: Boolean; AdditionalPadding: Boolean;
MenuButtonTextWidth: Integer; MenuButtonTextWidth: Integer;
ToolbarHeight: Integer; ToolbarHeight: Integer;
sgn: Integer;
isRTL: Boolean;
{$IFDEF LCLCocoa} {$IFDEF LCLCocoa}
scalefactor: Double; scalefactor: Double;
{$ENDIF} {$ENDIF}
@ -2254,6 +2260,9 @@ begin
{$ENDIF} {$ENDIF}
SetBounds(Left, Top, FBuffer.Width, ToolbarHeight); SetBounds(Left, Top, FBuffer.Width, ToolbarHeight);
isRTL := IsRightToLeft;
sgn := IfThen(isRTL, -1, +1);
// *** Tabs *** // *** Tabs ***
TabAppearance := FAppearance; TabAppearance := FAppearance;
@ -2315,20 +2324,32 @@ begin
end; end;
// Set Menu Button rect // Set Menu Button rect
FMenuButtonRect.Left := 0; if isRTL then
begin
FMenuButtonRect.Right := Width;
FMenuButtonRect.Left := Width - MenuButtonWidth;
end else
begin
FMenuButtonRect.Left := 0;
FMenuButtonRect.Right := MenuButtonWidth;
end;
FMenuButtonRect.Top := 0; FMenuButtonRect.Top := 0;
FMenuButtonRect.Right := MenuButtonWidth;
FMenuButtonRect.Bottom := FAppearance.Tab.CalcCaptionHeight; FMenuButtonRect.Bottom := FAppearance.Tab.CalcCaptionHeight;
// Rects of tabs headings (containg top frame of component) // Rects of tabs headings (containg top frame of component)
Setlength(FTabRects, FTabs.Count); Setlength(FTabRects, FTabs.Count);
if FTabs.Count > 0 then if FTabs.Count > 0 then
begin begin
if isRTL then
x := Width
else
x := 0;
// Add left space for Menu Button before Tabs if FShowMenuButton = True // Add left space for Menu Button before Tabs if FShowMenuButton = True
if FShowMenuButton then if FShowMenuButton then
x := ToolbarCornerRadius + (FMenuButtonRect.Right - FMenuButtonRect.Left) + 2 inc(x, sgn * (ToolbarCornerRadius + (FMenuButtonRect.Right - FMenuButtonRect.Left) + 2))
else else
x := ToolbarCornerRadius + 1; inc(x, sgn * (ToolbarCornerRadius + 1));
for i := 0 to FTabs.Count - 1 do for i := 0 to FTabs.Count - 1 do
if FTabs[i].Visible then if FTabs[i].Visible then
begin begin
@ -2348,12 +2369,19 @@ begin
FBuffer.Canvas.TextWidth(FTabs.Items[i].Caption)); FBuffer.Canvas.TextWidth(FTabs.Items[i].Caption));
// Breadth of text // Breadth of text
FTabRects[i].Left := x; if isRTL then
FTabRects[i].Right := x + TabWidth - 1; begin
FTabRects[i].Right := x;
FTabRects[i].Left := x - TabWidth + 1;
x := FTabRects[i].Left - 1;
end else
begin
FTabRects[i].Left := x;
FTabRects[i].Right := x + TabWidth - 1;
x := FTabRects[i].Right + 1;
end;
FTabRects[i].Top := 0; FTabRects[i].Top := 0;
FTabRects[i].Bottom := TabAppearance.Tab.CalcCaptionHeight; FTabRects[i].Bottom := TabAppearance.Tab.CalcCaptionHeight;
x := FTabRects[i].right + 1;
end end
else else
begin begin