mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-10 14:38:18 +02:00
LCL/SpeedButton: Fix autosizing of TSpeedButton. Issue #41119, based on patch by michalgw
This commit is contained in:
parent
936c19caf3
commit
d216b7144d
@ -262,6 +262,8 @@ begin
|
|||||||
if FMargin <> Value then
|
if FMargin <> Value then
|
||||||
begin
|
begin
|
||||||
FMargin := Value;
|
FMargin := Value;
|
||||||
|
InvalidatePreferredSize;
|
||||||
|
AdjustSize;
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -295,6 +297,8 @@ begin
|
|||||||
if FSpacing <> Value then
|
if FSpacing <> Value then
|
||||||
begin
|
begin
|
||||||
FSpacing := Value;
|
FSpacing := Value;
|
||||||
|
InvalidatePreferredSize;
|
||||||
|
AdjustSize;
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -569,6 +573,11 @@ var
|
|||||||
begin
|
begin
|
||||||
r:=Rect(0,0,0,0);
|
r:=Rect(0,0,0,0);
|
||||||
MeasureDraw(false,r,PreferredWidth,PreferredHeight);
|
MeasureDraw(false,r,PreferredWidth,PreferredHeight);
|
||||||
|
if WithThemeSpace then
|
||||||
|
begin
|
||||||
|
inc(PreferredWidth, 6); // like TButton
|
||||||
|
inc(PreferredHeight, 6);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomSpeedButton.MeasureDraw(Draw: boolean;
|
procedure TCustomSpeedButton.MeasureDraw(Draw: boolean;
|
||||||
@ -627,6 +636,15 @@ begin
|
|||||||
InflateRect(TextRect,-Margin,-Margin);
|
InflateRect(TextRect,-Margin,-Margin);
|
||||||
if HasGlyph then
|
if HasGlyph then
|
||||||
begin
|
begin
|
||||||
|
{
|
||||||
|
if (Spacing >= 0) then S := Spacing else S := 0;
|
||||||
|
case CurLayout of
|
||||||
|
blGlyphLeft: inc(TextRect.Left, GlyphWidth + S);
|
||||||
|
blGlyphRight: dec(TextRect.Right, GlyphWidth + S);
|
||||||
|
blGlyphTop: inc(TextRect.Top, GlyphHeight + S);
|
||||||
|
blGlyphBottom: dec(TextRect.Bottom, GlyphHeight + S);
|
||||||
|
end;
|
||||||
|
}
|
||||||
if (Spacing>=0) then
|
if (Spacing>=0) then
|
||||||
if CurLayout in [blGlyphLeft,blGlyphRight] then
|
if CurLayout in [blGlyphLeft,blGlyphRight] then
|
||||||
dec(TextRect.Right,Spacing)
|
dec(TextRect.Right,Spacing)
|
||||||
@ -636,6 +654,7 @@ begin
|
|||||||
dec(TextRect.Right,GlyphWidth)
|
dec(TextRect.Right,GlyphWidth)
|
||||||
else
|
else
|
||||||
dec(TextRect.Bottom,GlyphHeight);
|
dec(TextRect.Bottom,GlyphHeight);
|
||||||
|
|
||||||
end;
|
end;
|
||||||
if not FixedWidth then
|
if not FixedWidth then
|
||||||
begin
|
begin
|
||||||
@ -669,12 +688,14 @@ begin
|
|||||||
else
|
else
|
||||||
S:= 0;
|
S:= 0;
|
||||||
M:=Margin;
|
M:=Margin;
|
||||||
|
|
||||||
if not Draw then
|
if not Draw then
|
||||||
begin
|
begin
|
||||||
if M<0 then M:=2;
|
if M<0 then M:=2;
|
||||||
if S<0 then S:=M;
|
if S<0 then S:=M;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
// Calculate caption and glyph layout
|
// Calculate caption and glyph layout
|
||||||
if M < 0 then begin
|
if M < 0 then begin
|
||||||
// auto compute margin to center content
|
// auto compute margin to center content
|
||||||
@ -688,7 +709,7 @@ begin
|
|||||||
M:= (ClientSize.cy - TotalSize.cy) div 3;
|
M:= (ClientSize.cy - TotalSize.cy) div 3;
|
||||||
S:= M;
|
S:= M;
|
||||||
end else begin
|
end else begin
|
||||||
// fixed Spacing and center content
|
// fixed Spacing, center content
|
||||||
TotalSize.cx:= GlyphWidth + S + TextSize.cx;
|
TotalSize.cx:= GlyphWidth + S + TextSize.cx;
|
||||||
TotalSize.cy:= GlyphHeight + S + TextSize.cy;
|
TotalSize.cy:= GlyphHeight + S + TextSize.cy;
|
||||||
if Layout in [blGlyphLeft, blGlyphRight] then
|
if Layout in [blGlyphLeft, blGlyphRight] then
|
||||||
@ -726,7 +747,8 @@ begin
|
|||||||
if Spacing >= 0 then
|
if Spacing >= 0 then
|
||||||
OffsetCap.X := OffsetGlyph.X + GlyphWidth + S
|
OffsetCap.X := OffsetGlyph.X + GlyphWidth + S
|
||||||
else
|
else
|
||||||
OffsetCap.X := (OffsetGlyph.X + ClientSize.CX - TextSize.CX) div 2;
|
OffsetCap.X := (OffsetGlyph.X + GlyphWidth + ClientSize.CX - TextSize.CX) div 2;
|
||||||
|
//OffsetCap.X := (OffsetGlyph.X + ClientSize.CX - TextSize.CX) div 2;
|
||||||
end;
|
end;
|
||||||
OffsetCap.Y:= (ClientSize.cy - TextSize.cy) div 2;
|
OffsetCap.Y:= (ClientSize.cy - TextSize.cy) div 2;
|
||||||
end;
|
end;
|
||||||
@ -789,7 +811,7 @@ begin
|
|||||||
TextRect.Right := PaintRect.Right;
|
TextRect.Right := PaintRect.Right;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TextFlags := DT_TOP or cAlignment[BidiFlipAlignment(FAlignment, UseRightToLeftAlignment)];
|
TextFlags := DT_TOP or cAlignment[BidiFlipAlignment(FAlignment, UseRightToLeftAlignment)]; // or DT_NOCLIP;
|
||||||
if UseRightToLeftReading then
|
if UseRightToLeftReading then
|
||||||
TextFlags := TextFlags or DT_RTLREADING;
|
TextFlags := TextFlags or DT_RTLREADING;
|
||||||
|
|
||||||
@ -1036,7 +1058,8 @@ begin
|
|||||||
if Value <> FLayout then
|
if Value <> FLayout then
|
||||||
begin
|
begin
|
||||||
FLayout:= Value;
|
FLayout:= Value;
|
||||||
Invalidate;
|
InvalidatePreferredSize;
|
||||||
|
AdjustSize;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user