mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-18 09:09:29 +02:00
LazControls: Fix DividerBevel for vertical layout / Ensure correct values for very small/thin bevels
This commit is contained in:
parent
689ef2119f
commit
dd49f320f4
@ -50,6 +50,7 @@ type
|
|||||||
procedure CalcSize;
|
procedure CalcSize;
|
||||||
procedure Paint; override;
|
procedure Paint; override;
|
||||||
procedure FontChanged(Sender: TObject); override;
|
procedure FontChanged(Sender: TObject); override;
|
||||||
|
procedure BoundsChanged; override;
|
||||||
procedure SetAutoSize(Value: Boolean); override;
|
procedure SetAutoSize(Value: Boolean); override;
|
||||||
procedure TextChanged; override;
|
procedure TextChanged; override;
|
||||||
procedure CalculatePreferredSize(
|
procedure CalculatePreferredSize(
|
||||||
@ -178,15 +179,25 @@ procedure TDividerBevel.CalcSize;
|
|||||||
begin
|
begin
|
||||||
if not FNeedCalcSize then exit;
|
if not FNeedCalcSize then exit;
|
||||||
FNeedCalcSize := False;
|
FNeedCalcSize := False;
|
||||||
if Caption = '' then
|
|
||||||
FTextExtent := Canvas.TextExtent(' ')
|
if FBevelWidth < 0 then begin
|
||||||
else
|
if Orientation = trHorizontal then
|
||||||
FTextExtent := Canvas.TextExtent(Caption);
|
Canvas.Font.Orientation := 0
|
||||||
if FBevelWidth < 0 then
|
else
|
||||||
|
Canvas.Font.Orientation := 900;
|
||||||
|
if Caption = '' then
|
||||||
|
FTextExtent := Canvas.TextExtent(' ')
|
||||||
|
else
|
||||||
|
FTextExtent := Canvas.TextExtent(Caption);
|
||||||
FBevelHeight := Max(3, FTextExtent.cy div 5)
|
FBevelHeight := Max(3, FTextExtent.cy div 5)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
FBevelHeight := FBevelWidth;
|
FBevelHeight := FBevelWidth;
|
||||||
FBevelTop := Max((FTextExtent.cy - FBevelHeight) div 2, 0);
|
|
||||||
|
if FOrientation = trHorizontal then
|
||||||
|
FBevelTop := Max((1 + ClientHeight - FBevelHeight) div 2, 0)
|
||||||
|
else
|
||||||
|
FBevelTop := Max((1 + ClientWidth - FBevelHeight) div 2, 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TDividerBevel.Paint;
|
procedure TDividerBevel.Paint;
|
||||||
@ -227,8 +238,9 @@ var
|
|||||||
gsHorLines: begin
|
gsHorLines: begin
|
||||||
aRect.TopLeft := PaintRect.TopLeft;
|
aRect.TopLeft := PaintRect.TopLeft;
|
||||||
aRect.Right := PaintRect.Right;
|
aRect.Right := PaintRect.Right;
|
||||||
l := (PaintRect.Bottom - aRect.Top + 1) div 3;
|
l := Max((PaintRect.Bottom - aRect.Top + 1) div 3, 1);
|
||||||
inc(aRect.Top);
|
if l > 1 then
|
||||||
|
inc(aRect.Top);
|
||||||
Canvas.Pen.Color := clBtnShadow;
|
Canvas.Pen.Color := clBtnShadow;
|
||||||
for w := 0 to l - 1 do
|
for w := 0 to l - 1 do
|
||||||
Canvas.Line(aRect.Left, aRect.Top + w * 3, aRect.Right, aRect.Top + w * 3);
|
Canvas.Line(aRect.Left, aRect.Top + w * 3, aRect.Right, aRect.Top + w * 3);
|
||||||
@ -239,9 +251,10 @@ var
|
|||||||
end;
|
end;
|
||||||
gsVerLines: begin
|
gsVerLines: begin
|
||||||
aRect.TopLeft := PaintRect.TopLeft;
|
aRect.TopLeft := PaintRect.TopLeft;
|
||||||
l := (PaintRect.Right - aRect.Left + 1) div 3;
|
|
||||||
aRect.Bottom := PaintRect.Bottom + 1;
|
aRect.Bottom := PaintRect.Bottom + 1;
|
||||||
inc(aRect.Left);
|
l := Max((PaintRect.Right - aRect.Left + 1) div 3, 1);
|
||||||
|
if l > 1 then
|
||||||
|
inc(aRect.Left);
|
||||||
Canvas.Pen.Color := clBtnShadow;
|
Canvas.Pen.Color := clBtnShadow;
|
||||||
for w := 0 to l - 1 do
|
for w := 0 to l - 1 do
|
||||||
Canvas.Line(aRect.Left + w * 3, aRect.Top, aRect.Left + w * 3, aRect.Bottom);
|
Canvas.Line(aRect.Left + w * 3, aRect.Top, aRect.Left + w * 3, aRect.Bottom);
|
||||||
@ -352,12 +365,14 @@ begin
|
|||||||
Canvas.Brush.Style := bsClear;
|
Canvas.Brush.Style := bsClear;
|
||||||
j := Max((FBevelHeight - FTextExtent.cy) div 2, 0);
|
j := Max((FBevelHeight - FTextExtent.cy) div 2, 0);
|
||||||
if aHorizontal then begin
|
if aHorizontal then begin
|
||||||
|
j := Max((ClientHeight - FTextExtent.cy) div 2, 0);
|
||||||
Canvas.Font.Orientation := 0;
|
Canvas.Font.Orientation := 0;
|
||||||
if not IsRightToLeft then
|
if not IsRightToLeft then
|
||||||
Canvas.TextOut(aIndent, j, Caption)
|
Canvas.TextOut(aIndent, j, Caption)
|
||||||
else
|
else
|
||||||
Canvas.TextOut(Width - FTextExtent.cx - aIndent, j, Caption);
|
Canvas.TextOut(Width - FTextExtent.cx - aIndent, j, Caption);
|
||||||
end else begin
|
end else begin
|
||||||
|
j := Max((ClientWidth - FTextExtent.cy) div 2, 0);
|
||||||
Canvas.Font.Orientation := 900;
|
Canvas.Font.Orientation := 900;
|
||||||
Canvas.TextOut(j, aIndent + FTextExtent.cx, Caption);
|
Canvas.TextOut(j, aIndent + FTextExtent.cx, Caption);
|
||||||
end;
|
end;
|
||||||
@ -370,6 +385,12 @@ begin
|
|||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TDividerBevel.BoundsChanged;
|
||||||
|
begin
|
||||||
|
inherited BoundsChanged;
|
||||||
|
FNeedCalcSize := True;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TDividerBevel.SetAutoSize(Value: Boolean);
|
procedure TDividerBevel.SetAutoSize(Value: Boolean);
|
||||||
begin
|
begin
|
||||||
inherited SetAutoSize(Value);
|
inherited SetAutoSize(Value);
|
||||||
@ -389,8 +410,15 @@ end;
|
|||||||
procedure TDividerBevel.CalculatePreferredSize(var PreferredWidth, PreferredHeight: Integer;
|
procedure TDividerBevel.CalculatePreferredSize(var PreferredWidth, PreferredHeight: Integer;
|
||||||
WithThemeSpace: Boolean);
|
WithThemeSpace: Boolean);
|
||||||
begin
|
begin
|
||||||
FNeedCalcSize := True;
|
if Orientation = trHorizontal then
|
||||||
CalcSize;
|
Canvas.Font.Orientation := 0
|
||||||
|
else
|
||||||
|
Canvas.Font.Orientation := 900;
|
||||||
|
if Caption = '' then
|
||||||
|
FTextExtent := Canvas.TextExtent(' ')
|
||||||
|
else
|
||||||
|
FTextExtent := Canvas.TextExtent(Caption);
|
||||||
|
|
||||||
if Orientation = trHorizontal then begin
|
if Orientation = trHorizontal then begin
|
||||||
PreferredHeight := Max(FTextExtent.cy, FBevelHeight);
|
PreferredHeight := Max(FTextExtent.cy, FBevelHeight);
|
||||||
PreferredWidth := 0;
|
PreferredWidth := 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user