LCL/TSpeedButton: New property Alignment for left/right aligned or centered caption.

This commit is contained in:
wp_xyz 2022-02-07 16:04:47 +01:00
parent ad41c897b7
commit 1f92d4fde1
2 changed files with 23 additions and 4 deletions

View File

@ -333,12 +333,14 @@ type
FDragging: Boolean;
FFlat: Boolean;
FMouseInControl: Boolean;
FAlignment: TAlignment;
function GetGlyph: TBitmap;
procedure ImageListChange(Sender: TObject);
function IsGlyphStored: Boolean;
procedure SetShowCaption(const AValue: boolean);
procedure UpdateExclusive;
function GetTransparent: Boolean;
procedure SetAlignment(Value: TAlignment);
procedure SetAllowAllUp(Value: Boolean);
procedure SetGlyph(Value: TBitmap);
procedure SetLayout(const Value: TButtonLayout);
@ -406,6 +408,7 @@ type
procedure LoadGlyphFromResourceName(Instance: THandle; const AName: String);
procedure LoadGlyphFromLazarusResource(const AName: String);
public
property Alignment: TAlignment read FAlignment write SetAlignment default taCenter;
property AllowAllUp: Boolean read FAllowAllUp write SetAllowAllUp default false;
property Color default clBtnFace;
property DisabledImageIndex: TImageIndex index bsDisabled read GetImageIndex write SetImageIndex default -1;
@ -435,6 +438,7 @@ type
published
property Action;
property Align;
property Alignment;
property AllowAllUp;
property Anchors;
property AutoSize;

View File

@ -56,6 +56,7 @@ begin
FMargin := -1;
Color := clBtnFace;
FShowCaption := true;
FAlignment := taCenter;
end;
{------------------------------------------------------------------------------
@ -114,6 +115,15 @@ begin
inherited Click;
end;
procedure TCustomSpeedButton.SetAlignment(Value: TAlignment);
begin
if FAlignment <> Value then
begin
FAlignment := Value;
Invalidate;
end;
end;
{------------------------------------------------------------------------------
Method: TCustomSpeedButton.SetAllowAllUp
Params: Value:
@ -563,6 +573,8 @@ end;
procedure TCustomSpeedButton.MeasureDraw(Draw: boolean;
PaintRect: TRect; out PreferredWidth, PreferredHeight: integer);
const
cAlignment: array[TAlignment] of Longint = (DT_LEFT, DT_RIGHT, DT_CENTER);
var
GlyphWidth, GlyphHeight: Integer;
Offset, OffsetCap: TPoint;
@ -719,13 +731,13 @@ begin
blGlyphTop : begin
Offset.X:= (ClientSize.cx - GlyphWidth) div 2;
Offset.Y:= M;
OffsetCap.X:= 0;
OffsetCap.X:= M;
OffsetCap.Y:= Offset.Y + GlyphHeight + S;
end;
blGlyphBottom : begin
Offset.X:= (ClientSize.cx - GlyphWidth) div 2;
Offset.Y:= ClientSize.cy - M - GlyphHeight;
OffsetCap.X:= 0;
OffsetCap.X:= M;
OffsetCap.Y:= Offset.Y - S - TextSize.cy;
end;
end;
@ -739,16 +751,19 @@ begin
Left := Left + OffsetCap.X;
Top := Top + OffsetCap.Y;
case CurLayout of
blGlyphLeft: Right := Left + TextSize.CX;
blGlyphLeft:
Right := Left + TextSize.CX;
blGlyphRight:
begin
Right := ClientSize.cx - M - GlyphWidth - S;
Left := Right - TextSize.CX;
end;
blGlyphTop, blGlyphBottom:
Right := ClientSize.cx - M;
end;
end;
TextFlags := DT_TOP or DT_CENTER;
TextFlags := DT_TOP or cAlignment[BidiFlipAlignment(FAlignment, UseRightToLeftAlignment)];
if UseRightToLeftReading then
TextFlags := TextFlags or DT_RTLREADING;