Browse Source

Added AutoSize to bcmaterialdesignbutton.pas

lainz 9 years ago
parent
commit
be9cf4bccf
1 changed files with 23 additions and 5 deletions
  1. 23 5
      bcmaterialdesignbutton.pas

+ 23 - 5
bcmaterialdesignbutton.pas

@@ -53,6 +53,8 @@ type
     procedure SetFTextSize(AValue: integer);
     procedure SetFTextSize(AValue: integer);
     procedure SetFTextStyle(AValue: TFontStyles);
     procedure SetFTextStyle(AValue: TFontStyles);
   protected
   protected
+    procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;
+      {%H-}WithThemeSpace: boolean); override;
     procedure OnStartTimer({%H-}Sender: TObject);
     procedure OnStartTimer({%H-}Sender: TObject);
     procedure OnTimer({%H-}Sender: TObject);
     procedure OnTimer({%H-}Sender: TObject);
     procedure Paint; override;
     procedure Paint; override;
@@ -138,7 +140,6 @@ var
   OutTxtSize: TSize;
   OutTxtSize: TSize;
   OutX, OutY: integer;
   OutX, OutY: integer;
 begin
 begin
-
   bmpOut := TBGRABitmap.Create(AWidth, AHeight);
   bmpOut := TBGRABitmap.Create(AWidth, AHeight);
   bmpOut.FontAntialias := True;
   bmpOut.FontAntialias := True;
   bmpOut.FontHeight := AFontHeight;
   bmpOut.FontHeight := AFontHeight;
@@ -296,6 +297,23 @@ begin
   Invalidate;
   Invalidate;
 end;
 end;
 
 
+procedure TBCMaterialDesignButton.CalculatePreferredSize(
+  var PreferredWidth, PreferredHeight: integer; WithThemeSpace: boolean);
+var
+  ts: TSize;
+begin
+  inherited CalculatePreferredSize(PreferredWidth, PreferredHeight,
+    WithThemeSpace);
+  FBGRA.FontQuality := FTextQuality;
+  FBGRA.FontName := FTextFont;
+  FBGRA.FontStyle := FTextStyle;
+  FBGRA.FontHeight := FTextSize;
+  FBGRA.FontAntialias := True;
+  ts := FBGRA.TextSize(Caption);
+  Inc(PreferredWidth, ts.cx + 26);
+  Inc(PreferredHeight, ts.cy + 10);
+end;
+
 procedure TBCMaterialDesignButton.SetFNormalColor(AValue: TColor);
 procedure TBCMaterialDesignButton.SetFNormalColor(AValue: TColor);
 begin
 begin
   if FNormalColor = AValue then
   if FNormalColor = AValue then
@@ -355,10 +373,10 @@ begin
 
 
   if Caption <> '' then
   if Caption <> '' then
   begin
   begin
-    temp := DrawTextShadow(Width, Height - FShadowSize, Caption, FTextSize,
-      FTextColor, FTextShadowColor,
-      FTextShadowOffsetX, FTextShadowOffsetY, FTextShadowSize,
-      FTextStyle, FTextFont, FTextShadow, FTextQuality) as TBGRABitmap;
+    temp := DrawTextShadow(Width, Height - FShadowSize, Caption,
+      FTextSize, FTextColor, FTextShadowColor, FTextShadowOffsetX,
+      FTextShadowOffsetY, FTextShadowSize, FTextStyle, FTextFont,
+      FTextShadow, FTextQuality) as TBGRABitmap;
     FBGRA.PutImage(0, 0, temp, dmDrawWithTransparency);
     FBGRA.PutImage(0, 0, temp, dmDrawWithTransparency);
     temp.Free;
     temp.Free;
   end;
   end;