mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-05 21:26:18 +02:00
LCL/TSpeedButton: New property Alignment for left/right aligned or centered caption.
This commit is contained in:
parent
ad41c897b7
commit
1f92d4fde1
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user