Skip to content

Commit 6bc592c

Browse files
Merge pull request #41 from digao-dalpiaz/dpi-and-fmx-font
Dpi and fmx font
2 parents 318504c + 969abf9 commit 6bc592c

File tree

4 files changed

+126
-71
lines changed

4 files changed

+126
-71
lines changed

CompInstall.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ IniVersion=2
33

44
[General]
55
Name=Digao Dalpiaz - Dam component
6-
Version=6.4
6+
Version=6.5
77
DelphiVersions=XE3;XE4;XE5;XE6;XE7;XE8;10;10.1;10.2;10.3;10.4;11;12
88
Packages=DamCommonPackage;DamPackage_VCL;DamPackage_FMX;DamDesignPackage_VCL;DamDesignPackage_FMX
99
AddLibrary=1

README.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,18 @@
3636

3737
## What's New
3838

39-
- 02/23/2024 (Version 6.4)
39+
- 03/10/2024 (Version 6.5)
4040

41-
- Fixed included files path in Design packages (the files was referencing "Design" folder twice).
41+
- New ButtonsFont property (and ButtonsFontColor when FMX).
42+
- Fixed adjusting DPI when first display dialog in VCL.
4243

4344
<details>
4445
<summary>Click here to view the entire changelog</summary>
4546

47+
- 02/23/2024 (Version 6.4)
48+
49+
- Fixed included files path in Design packages (the files was referencing "Design" folder twice).
50+
4651
- 02/22/2024 (Version 6.3)
4752

4853
- Fixed Lazarus Design Package compiling.
@@ -435,37 +440,41 @@ MsgInfo('This is a %p message number %p at time %p', ['test', 123, Now]);
435440

436441
## TDam properties
437442

443+
`ButtonsColor: TColor` = Define background color of buttons area on message dialog.
444+
445+
`ButtonsFont: TFont` = Defines the text font of dialog buttons
446+
447+
`ButtonsFontColor: TAlphaColor` = Defines the text font color of dialog buttons *(Only available in FMX environment)*
448+
438449
`CenterButtons: Boolean` = Define if the buttons at message form will be aligned at center. If this property is false, the buttons will be aligned at right of form.
439450

440451
`DamDefault: Boolean` = Defines if this TDam will be used to fire quick messages (please read Quick Messages section). You only can have one defined as Default in the application.
441452

442453
`DamUnitName: String` = Specify the unit name to be created with all message methods in the project folder. Do not specify file extension, because the component will complete the name automatically with ".pas" extension.
443454

455+
`DialogBorder: Boolean` = Defines if the window of message dialog will contain borders. You can disable this property to create modern dialog themes.
456+
444457
`DialogPosition: TDamDlgPosition` = Defines the dialog form start position:
445458
- dpScreenCenter: center the window based on the screen
446459
- dpMainFormCenter: center the window based on the main window
447460
- dpActiveFormCenter: center the window based on the active window
448461

449-
`DialogBorder: Boolean` = Defines if the window of message dialog will contain borders. You can disable this property to create modern dialog themes.
450-
451462
`HandleExceptions: Boolean` = Defines this TDam to handle all application exceptions, showing the error message with the same dialog as all other Dam messages. Only one TDam can be set to handle exceptions in the application.
452463

464+
`HideIcon: Boolean` = If True, the icon on the message dialog will be suppressed.
465+
453466
`Images: TCustomImageList` = Allows you to set an ImageList, using tag `<img:idx>` in the message text, where `idx` is image index.
454467

455468
`Language: TDamLanguage` = Defines the language used by message buttons and message form title. *When you place an instance of TDam component, this property will be initialized according to the system current language. If there is no language available according to the system, English language will be set. This property has no default value, precisely because it should store the language being defined.*
456469

470+
`MessageColor: TColor` = Define background color of message area on message dialog.
471+
457472
`MessageFont: TFont` = Defines the text font of messages
458473

459474
`MessageFontColor: TAlphaColor` = Defines the text font color of messages *(Only available in FMX environment)*
460475

461476
`PlaySounds: Boolean` = Enable system sounds when showing messages of Warning, Question and Error kinds.
462477

463-
`MessageColor: TColor` = Define background color of message area on message dialog.
464-
465-
`ButtonsColor: TColor` = Define background color of buttons area on message dialog.
466-
467-
`HideIcon: Boolean` = If True, the icon on the message dialog will be suppressed.
468-
469478
## TDam events
470479

471480
`OnLinkClick(Sender: TObject; Msg: TDamMsg; const Target: string; var Handled: Boolean; var CloseMsg: Boolean; var MsgResult: TDamMsgRes)`

Source/Vcl.DamDialog.pas

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ implementation
4848
type
4949
TBoxComps = {$IFDEF FMX}TRectangle{$ELSE}TPanel{$ENDIF};
5050

51+
TBmp =
52+
{$IFDEF FPC}
53+
Graphics
54+
{$ELSE}
55+
{$IFDEF FMX}
56+
FMX.{$IFDEF USE_NEW_UNITS}Graphics{$ELSE}Types{$ENDIF}
57+
{$ELSE}
58+
Vcl.Graphics
59+
{$ENDIF}
60+
{$ENDIF}.TBitmap;
61+
5162
type
5263
TFrmDamDialogDyn = class(TForm)
5364
private
@@ -62,6 +73,8 @@ TFrmDamDialogDyn = class(TForm)
6273
DamResult: TDamMsgRes;
6374
LangStrs: TDamLanguageDefinition;
6475

76+
VirtualBmp: TBmp;
77+
6578
procedure BuildControls;
6679

6780
function GetCurrentMonitorWidth: Integer;
@@ -90,11 +103,11 @@ TFrmDamDialogDyn = class(TForm)
90103
procedure OnBtnClick(Sender: TObject);
91104
public
92105
constructor CreateNew; reintroduce;
106+
destructor Destroy; override;
93107
end;
94108

95109
const
96110
BRD_SPACE = 8;
97-
BTN_HEIGHT = 25;
98111
{$IFDEF FMX}
99112
BRUSH_KIND_NONE = TBrushKind.{$IFDEF USE_NEW_ENUMS}None{$ELSE}bkNone{$ENDIF};
100113
{$ENDIF}
@@ -114,30 +127,6 @@ function GetControlRight(C: TControl): TPixels;
114127
Result := GetControlLeft(C) + C.Width;
115128
end;
116129

117-
function CalcButtonWidth(Btn: TButton): TPixels;
118-
type TBmp =
119-
{$IFDEF FPC}
120-
Graphics
121-
{$ELSE}
122-
{$IFDEF FMX}
123-
FMX.{$IFDEF USE_NEW_UNITS}Graphics{$ELSE}Types{$ENDIF}
124-
{$ELSE}
125-
Vcl.Graphics
126-
{$ENDIF}
127-
{$ENDIF}.TBitmap;
128-
var
129-
B: TBmp;
130-
begin
131-
B := TBmp.Create{$IFDEF USE_FMX_OLD_ENV}(1, 1){$ENDIF};
132-
try
133-
B.Canvas.Font.Assign(Btn.Font);
134-
135-
Result := Max(B.Canvas.TextWidth(Btn.{$IFDEF FMX}Text{$ELSE}Caption{$ENDIF})+20, 75);
136-
finally
137-
B.Free;
138-
end;
139-
end;
140-
141130
//
142131

143132
constructor TFrmDamDialogDyn.CreateNew;
@@ -150,6 +139,14 @@ constructor TFrmDamDialogDyn.CreateNew;
150139
{$IFDEF USE_DPICHANGE}
151140
OnAfterMonitorDpiChanged := OnAfterDpiChanged;
152141
{$ENDIF}
142+
143+
VirtualBmp := TBmp.Create{$IFDEF USE_FMX_OLD_ENV}(1, 1){$ENDIF};
144+
end;
145+
146+
destructor TFrmDamDialogDyn.Destroy;
147+
begin
148+
VirtualBmp.Free;
149+
inherited;
153150
end;
154151

155152
function RunDamDialog(DamMsg: TDamMsg; const aText: string): TDamMsgRes;
@@ -169,6 +166,9 @@ function RunDamDialog(DamMsg: TDamMsg; const aText: string): TDamMsgRes;
169166
F.BuildButtons;
170167

171168
F.SetIcon;
169+
{$IFDEF USE_DPICHANGE}
170+
F.ScaleForCurrentDPI;
171+
{$ENDIF}
172172
F.CalcFormBounds;
173173

174174
F.ShowModal;
@@ -183,6 +183,7 @@ function RunDamDialog(DamMsg: TDamMsg; const aText: string): TDamMsgRes;
183183
procedure TFrmDamDialogDyn.BuildControls;
184184
var
185185
Action: TAction;
186+
BtnHeight: TPixels;
186187
begin
187188
ActionList := TActionList.Create(Self);
188189

@@ -226,8 +227,11 @@ procedure TFrmDamDialogDyn.BuildControls;
226227
{$ENDIF}
227228
LbMsg.GeneratePlainText := True;
228229

230+
VirtualBmp.Canvas.Font.Assign(DamMsg.Dam.ButtonsFont);
231+
BtnHeight := VirtualBmp.Canvas.TextHeight('A')+8;
232+
229233
BoxButtons := TBoxComps.Create(Self);
230-
BoxButtons.Height := BRD_SPACE+BTN_HEIGHT+BRD_SPACE;
234+
BoxButtons.Height := BRD_SPACE+BtnHeight+BRD_SPACE;
231235
BoxButtons.Parent := Self;
232236
{$IFDEF FMX}
233237
BoxButtons.Align := TAlignLayout.{$IFDEF USE_NEW_ENUMS}Bottom{$ELSE}alBottom{$ENDIF};
@@ -239,7 +243,7 @@ procedure TFrmDamDialogDyn.BuildControls;
239243
{$ENDIF}
240244

241245
BoxFloatBtns := TBoxComps.Create(Self);
242-
BoxFloatBtns.SetBounds(0, BRD_SPACE, 0, BTN_HEIGHT);
246+
BoxFloatBtns.SetBounds(0, BRD_SPACE, 0, BtnHeight);
243247
BoxFloatBtns.Parent := BoxButtons;
244248
{$IFDEF FMX}
245249
BoxFloatBtns.Stroke.Kind := BRUSH_KIND_NONE; //remove border
@@ -249,10 +253,11 @@ procedure TFrmDamDialogDyn.BuildControls;
249253
{$ENDIF}
250254

251255
BtnHelp := TSpeedButton.Create(Self);
252-
BtnHelp.SetBounds(BRD_SPACE, BRD_SPACE, BTN_HEIGHT{width same as height}, BTN_HEIGHT);
256+
BtnHelp.SetBounds(BRD_SPACE, BRD_SPACE, VirtualBmp.Canvas.TextWidth('?')+20, BtnHeight);
253257
BtnHelp.Parent := BoxButtons;
254258
BtnHelp.{$IFDEF FMX}Text{$ELSE}Caption{$ENDIF} := '?';
255259
BtnHelp.OnClick := BtnHelpClick;
260+
BtnHelp.Font.Assign(DamMsg.Dam.ButtonsFont);
256261
end;
257262

258263
procedure TFrmDamDialogDyn.LoadTextProps(const MsgText: string);
@@ -358,6 +363,7 @@ procedure TFrmDamDialogDyn.BuildButtons;
358363
X: TPixels;
359364
Btn: TButton;
360365
Names: array[1..3] of string;
366+
BtnText: string;
361367
begin
362368
case DamMsg.Buttons of
363369
dbOne, dbOK: NumButtons := 1;
@@ -386,13 +392,22 @@ procedure TFrmDamDialogDyn.BuildButtons;
386392
X := 0;
387393
for I := 1 to NumButtons do
388394
begin
395+
BtnText := Names[I];
396+
389397
Btn := TButton.Create(Self);
390398
Btn.Parent := BoxFloatBtns;
391-
Btn.{$IFDEF FMX}Text{$ELSE}Caption{$ENDIF} := Names[I];
399+
Btn.{$IFDEF FMX}Text{$ELSE}Caption{$ENDIF} := BtnText;
392400
Btn.OnClick := OnBtnClick;
393401
Btn.Tag := I;
394-
395-
Btn.SetBounds(X, 0, CalcButtonWidth(Btn), BoxFloatBtns.Height);
402+
{$IFDEF FMX}
403+
Btn.TextSettings.Font.Assign(DamMsg.Dam.ButtonsFont);
404+
Btn.TextSettings.FontColor := DamMsg.Dam.ButtonsFontColor;
405+
Btn.StyledSettings := [];
406+
{$ELSE}
407+
Btn.Font.Assign(DamMsg.Dam.ButtonsFont);
408+
{$ENDIF}
409+
410+
Btn.SetBounds(X, 0, Max(VirtualBmp.Canvas.TextWidth(BtnText)+20, 75), BoxFloatBtns.Height);
396411
X := X + Btn.Width + BRD_SPACE;
397412

398413
ButtonsList.Add(Btn);

0 commit comments

Comments
 (0)