TvPlanit: Support RTL in TSpkCheckbox and TSpkRadioButton

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8955 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2023-10-13 08:33:51 +00:00
parent c9940f44bf
commit d3bbef0991
2 changed files with 59 additions and 18 deletions

View File

@ -1074,6 +1074,7 @@ var
R: TRect;
SeparatorRect: TRect;
SeparatorLineColor: TColor;
ts: TTextStyle;
drawImgEnabled: Boolean = true;
begin
if FToolbarDispatch = nil then
@ -1081,6 +1082,10 @@ begin
if FAppearance = nil then
exit;
ts := ABuffer.Canvas.TextStyle;
ts.RightToLeft := IsRightToLeft;
ABuffer.Canvas.TextStyle := ts;
if (FButtonKind <> bkSeparator) then
begin
if (FRect.Width < 2*LargeButtonRadius) or (FRect.Height < 2*LargeButtonRadius) then
@ -1650,6 +1655,7 @@ var
leftEdgeOpen, rightEdgeOpen: Boolean;
drawImgEnabled: Boolean = true;
isRTL: Boolean;
ts: TTextStyle;
begin
if (FToolbarDispatch = nil) or (FAppearance = nil) then
exit;
@ -1675,6 +1681,9 @@ begin
isRTL := IsRightToLeft;
sgn := IfThen(isRTL, -1, +1);
ts := ABuffer.Canvas.TextStyle;
ts.RightToLeft := isRTL;
ABuffer.Canvas.TextStyle := ts;
delta := FAppearance.Element.HotTrackBrightnessChange;
case FAppearance.Element.Style of
@ -1896,13 +1905,13 @@ begin
if FButtonKind = bkDropdown then
begin
if isRTL then
R := Classes.Rect(FButtonRect.Left+1, FButtonRect.Top, FButtonRect.Left+dx, FButtonRect.Bottom)
R := Classes.Rect(FButtonRect.Left+1, FButtonRect.Top, FButtonRect.Left+dx+1, FButtonRect.Bottom)
else
R := Classes.Rect(FButtonRect.Right-dx, FButtonRect.Top, FButtonRect.Right, FButtonRect.Bottom);
end else
begin
if isRTL then
R := Classes.Rect(FDropDownRect.Left+1, FDropDownRect.Top, FDropDownRect.Left+dx, FDropDownRect.Bottom)
R := Classes.Rect(FDropDownRect.Left+1, FDropDownRect.Top, FDropDownRect.Left+dx+1, FDropDownRect.Bottom)
else
R := Classes.Rect(FDropdownRect.Right-dx, FDropdownRect.Top, FDropdownRect.Right, FDropdownRect.Bottom);
end;

View File

@ -124,7 +124,7 @@ begin
else
BtnWidth := BtnWidth + SmallButtonBorderWidth;
// Prawa krawêdŸ przycisku
// Right edge of the button
if (FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) then
BtnWidth := BtnWidth + SmallButtonHalfBorderWidth
else
@ -141,9 +141,13 @@ procedure TSpkCustomCheckbox.Draw(ABuffer: TBitmap; ClipRect: T2DIntRect);
var
fontColor: TColor;
x, y: Integer;
h: Integer;
w, h: Integer;
sgn: Integer;
te: TThemedElementDetails;
cornerRadius: Integer;
leftEdgeOpen, rightEdgeOpen: Boolean;
isRTL: Boolean;
ts: TTextStyle;
begin
if FToolbarDispatch = nil then
exit;
@ -152,6 +156,12 @@ begin
if (FRect.Width < 2*LargeButtonRadius) or (FRect.Height < 2*LargeButtonRadius) then
exit;
isRTL := IsRightToLeft;
sgn := IfThen(isRTL, -1, +1);
ts := ABuffer.Canvas.TextStyle;
ts.RightToLeft := isRTL;
ABuffer.Canvas.TextStyle := ts;
case FAppearance.Element.Style of
esRounded:
cornerRadius := SmallButtonRadius;
@ -162,6 +172,16 @@ begin
// Border
if (FButtonState = bsIdle) and (not(FHideFrameWhenIdle)) then
begin
if isRTL then
begin
leftEdgeOpen := (FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) or (FButtonKind = bkButtonDropdown);
rightEdgeOpen := (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]);
end else
begin
leftEdgeOpen := (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]);
rightEdgeOpen := (FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) or (FButtonKind = bkButtonDropdown);
end;
with FAppearance.Element do
TButtonTools.DrawButton(
ABuffer,
@ -172,8 +192,8 @@ begin
IdleGradientFromColor,
IdleGradientToColor,
IdleGradientType,
(FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]),
(FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) or (FButtonKind = bkButtonDropdown),
leftEdgeOpen,
rightEdgeOpen,
false,
false,
cornerRadius,
@ -192,8 +212,8 @@ begin
HotTrackGradientFromColor,
HotTrackGradientToColor,
HotTrackGradientType,
(FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]),
(FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) or (FButtonKind = bkButtonDropdown),
leftEdgeOpen,
rightEdgeOpen,
false,
false,
cornerRadius,
@ -212,8 +232,8 @@ begin
ActiveGradientFromColor,
ActiveGradientToColor,
ActiveGradientType,
(FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]),
(FGroupBehaviour in [gbBeginsGroup, gbContinuesGroup]) or (FButtonKind = bkButtonDropdown),
leftEdgeOpen,
rightEdgeOpen,
false,
false,
cornerRadius,
@ -226,13 +246,21 @@ begin
begin
te := ThemeServices.GetElementDetails(tbCheckboxCheckedNormal);
h := ThemeServices.GetDetailSize(te).cy;
w := ThemeServices.GetDetailSize(te).cx;
end else
begin
h := GetSystemMetrics(SM_CYMENUCHECK);
w := GetSystemMetrics(SM_CXMENUCHECK);
end;
if (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]) then
x := FButtonRect.Left + SmallButtonHalfBorderWidth + SmallButtonPadding
if isRTL then
x := FButtonRect.Right - w
else
x := FButtonRect.Left + SmallButtonBorderWidth + SmallButtonPadding;
x := FButtonRect.Left;
if (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]) then
inc(x, sgn * (SmallButtonHalfBorderWidth + SmallButtonPadding))
else
inc(x, sgn * (SmallButtonBorderWidth + SmallButtonPadding));
y := FButtonRect.Top + (FButtonRect.Height - h) div 2;
TGUITools.DrawCheckbox(
@ -250,18 +278,22 @@ begin
case FButtonState of
bsIdle : fontColor := FAppearance.Element.IdleCaptionColor;
bsBtnHottrack,
bsDropdownHottrack : fontColor := FAppearance.Element.HotTrackCaptionColor;
bsDropdownHotTrack : fontColor := FAppearance.Element.HotTrackCaptionColor;
bsBtnPressed,
bsDropdownPressed : fontColor := FAppearance.ELement.ActiveCaptionColor;
end;
if not(FEnabled) then
fontColor := TColorTools.ColorToGrayscale(fontColor);
if (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]) then
x := FButtonRect.Left + SmallButtonHalfBorderWidth
if isRTL then
x := FButtonRect.Right - ABuffer.Canvas.TextWidth(FCaption)
else
x := FButtonRect.Left + SmallButtonBorderWidth;
x := x + 2 * SmallButtonPadding + SmallButtonGlyphWidth;
x := FButtonRect.Left;
if (FGroupBehaviour in [gbContinuesGroup, gbEndsGroup]) then
inc(x, sgn * SmallButtonHalfBorderWidth)
else
inc(x, sgn * SmallButtonBorderWidth);
inc(x, sgn * (2 * SmallButtonPadding + SmallButtonGlyphWidth));
y := FButtonRect.Top + (FButtonRect.Height - ABuffer.Canvas.TextHeight('Wy')) div 2;
TGUITools.DrawText(ABuffer.Canvas, x, y, FCaption, fontColor, ClipRect);