Improve scaling of DateTimePicker. Leave GetDetailSize in places which are not fully tested yet.

This commit is contained in:
Juha 2023-04-29 17:21:31 +03:00
parent bd40a6028e
commit f99bd70b72
6 changed files with 22 additions and 19 deletions

View File

@ -2040,12 +2040,9 @@ function TCustomDateTimePicker.GetCheckBoxRect(IgnoreRightToLeft: Boolean): TRec
var var
Details: TThemedElementDetails; Details: TThemedElementDetails;
CSize: TSize; CSize: TSize;
begin begin
Details := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal); Details := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal);
CSize := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch); CSize := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch);
CSize.cx := ScaleScreenToFont(CSize.cx);
CSize.cy := ScaleScreenToFont(CSize.cy);
if IsRightToLeft and not IgnoreRightToLeft then begin if IsRightToLeft and not IgnoreRightToLeft then begin
Result.Right := ClientWidth - (BorderSpacing.InnerBorder + BorderWidth); Result.Right := ClientWidth - (BorderSpacing.InnerBorder + BorderWidth);
@ -2062,10 +2059,8 @@ end;
--------------- ---------------
Returns upper left corner of the rectangle where the text is written. Returns upper left corner of the rectangle where the text is written.
Also used in calculating our preferred size. } Also used in calculating our preferred size. }
function TCustomDateTimePicker.GetTextOrigin(IgnoreRightToLeft: Boolean function TCustomDateTimePicker.GetTextOrigin(IgnoreRightToLeft: Boolean): TPoint;
): TPoint; var
var
Re: TRect; Re: TRect;
B: Integer; B: Integer;
XL, XR: Integer; XL, XR: Integer;
@ -3105,6 +3100,7 @@ var
S: String; S: String;
const const
// Enabled, Checked, Mouse hover
CheckStates: array[Boolean, Boolean, Boolean] of TThemedButton = ( CheckStates: array[Boolean, Boolean, Boolean] of TThemedButton = (
((tbCheckBoxUncheckedDisabled, tbCheckBoxUncheckedDisabled), ((tbCheckBoxUncheckedDisabled, tbCheckBoxUncheckedDisabled),
(tbCheckBoxCheckedDisabled, tbCheckBoxCheckedDisabled)), (tbCheckBoxCheckedDisabled, tbCheckBoxCheckedDisabled)),

View File

@ -2398,8 +2398,8 @@ begin
ExpandRow(Index); ExpandRow(Index);
end; end;
end; end;
// WasValueClick param is only for Boolean checkboxes, toggled if user // WasValueClick param for SetItemIndexAndFocus is only for Boolean checkboxes,
// clicks the square. It has no effect for Boolean ComboBox editor. // toggled if user clicks the square. It has no effect for Boolean ComboBox editor.
Details := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal); Details := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal);
Sz := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch); Sz := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch);
SetItemIndexAndFocus(Index, (X>SplitterX) and (X<=SplitterX+Sz.cx)); SetItemIndexAndFocus(Index, (X>SplitterX) and (X<=SplitterX+Sz.cx));

View File

@ -519,7 +519,8 @@ begin
Details := ThemeServices.GetElementDetails(tbRadioButtonUncheckedNormal); Details := ThemeServices.GetElementDetails(tbRadioButtonUncheckedNormal);
details_chek:=ThemeServices.GetElementDetails(tbRadioButtonCheckedNormal); details_chek:=ThemeServices.GetElementDetails(tbRadioButtonCheckedNormal);
CSize := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch); // Maybe: CSize := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch);
CSize := ThemeServices.GetDetailSize(Details);
while (AY < DRect.Bottom) and (i<TRadioGroup(FControl).Items.Count) do while (AY < DRect.Bottom) and (i<TRadioGroup(FControl).Items.Count) do
@ -627,7 +628,8 @@ begin
i:=0; i:=0;
Details := ThemeServices.GetElementDetails(tbCheckBoxUncheckedNormal); Details := ThemeServices.GetElementDetails(tbCheckBoxUncheckedNormal);
CSize := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch); // Maybe: CSize := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch);
CSize := ThemeServices.GetDetailSize(Details);
aH:=Max(Canvas.TextHeight(Text) div 2, CSize.cy); aH:=Max(Canvas.TextHeight(Text) div 2, CSize.cy);
@ -1210,7 +1212,8 @@ var
details: TThemedElementDetails; details: TThemedElementDetails;
begin begin
Details := ThemeServices.GetElementDetails(GetCheckStyle(Checked)); Details := ThemeServices.GetElementDetails(GetCheckStyle(Checked));
CSize := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch); // Maybe: CSize := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch);
CSize := ThemeServices.GetDetailSize(Details);
PaintRect.Left := DRect.Left; PaintRect.Left := DRect.Left;
PaintRect.Top := (DRect.Top + DRect.Bottom - CSize.cy) div 2; PaintRect.Top := (DRect.Top + DRect.Bottom - CSize.cy) div 2;
PaintRect := Bounds(PaintRect.Left, PaintRect.Top, CSize.cx, CSize.cy); PaintRect := Bounds(PaintRect.Left, PaintRect.Top, CSize.cx, CSize.cy);

View File

@ -4353,8 +4353,8 @@ begin
soAscending: Details := ThemeServices.GetElementDetails(thHeaderSortArrowSortedUp); soAscending: Details := ThemeServices.GetElementDetails(thHeaderSortArrowSortedUp);
soDescending: Details := ThemeServices.GetElementDetails(thHeaderSortArrowSortedDown); soDescending: Details := ThemeServices.GetElementDetails(thHeaderSortArrowSortedDown);
end; end;
// Maybe: s := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch);
s := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch); s := ThemeServices.GetDetailSize(Details);
end else end else
s := Size(-1, -1); s := Size(-1, -1);
if s.cx>0 then // theme services support sorted arrows if s.cx>0 then // theme services support sorted arrows
@ -4839,7 +4839,8 @@ begin
end else end else
begin begin
Details := ThemeServices.GetElementDetails(arrtb[AState]); Details := ThemeServices.GetElementDetails(arrtb[AState]);
CSize := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch); // Maybe: CSize := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch);
CSize := ThemeServices.GetDetailSize(Details);
CSize.cx := MulDiv(CSize.cx, Font.PixelsPerInch, Screen.PixelsPerInch); CSize.cx := MulDiv(CSize.cx, Font.PixelsPerInch, Screen.PixelsPerInch);
CSize.cy := MulDiv(CSize.cy, Font.PixelsPerInch, Screen.PixelsPerInch); CSize.cy := MulDiv(CSize.cy, Font.PixelsPerInch, Screen.PixelsPerInch);
end; end;

View File

@ -89,10 +89,11 @@ begin
csDoubleClicks, csMenuEvents, csSetCaption, csParentBackground, csOpaque]; csDoubleClicks, csMenuEvents, csSetCaption, csParentBackground, csOpaque];
FFlat := True; FFlat := True;
Height := 32; Height := 32;
// ToDo: Test the scaling code. Widths are scaled in many places.
Details := ThemeServices.GetElementDetails(ttbSplitButtonDropDownNormal); Details := ThemeServices.GetElementDetails(ttbSplitButtonDropDownNormal);
FThemeDropDownWidth := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch).cx; FThemeDropDownWidth := ThemeServices.GetDetailSize(Details).cx;
Details := ThemeServices.GetElementDetails(ttbDropDownButtonNormal); Details := ThemeServices.GetElementDetails(ttbDropDownButtonNormal);
FThemeButtonDropWidth := ThemeServices.GetDetailSizeForPPI(Details, Font.PixelsPerInch).cx; FThemeButtonDropWidth := ThemeServices.GetDetailSize(Details).cx;
FButtonHeight := -1; FButtonHeight := -1;
FButtonWidth := -1; FButtonWidth := -1;
FDropDownWidth := -1; FDropDownWidth := -1;

View File

@ -241,7 +241,8 @@ begin
else else
Detail := tbCheckBoxUncheckedNormal; Detail := tbCheckBoxUncheckedNormal;
Details := ThemeServices.GetElementDetails(Detail); Details := ThemeServices.GetElementDetails(Detail);
aSize := ThemeServices.GetDetailSizeForPPI(Details, PixelsPerInch); // Maybe: aSize := ThemeServices.GetDetailSizeForPPI(Details, PixelsPerInch);
aSize := ThemeServices.GetDetailSize(Details);
NodeRect:=Node.DisplayRect(false); NodeRect:=Node.DisplayRect(false);
r:=Bounds(Node.DisplayIconLeft+(ImageList1.Width-aSize.cx) div 2, r:=Bounds(Node.DisplayIconLeft+(ImageList1.Width-aSize.cx) div 2,
NodeRect.Top+(NodeRect.Bottom-NodeRect.Top-aSize.cy) div 2, NodeRect.Top+(NodeRect.Bottom-NodeRect.Top-aSize.cy) div 2,
@ -392,7 +393,8 @@ begin
ButtonPanel1.OKButton.OnClick:=@OkButtonClick; ButtonPanel1.OKButton.OnClick:=@OkButtonClick;
Details := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal); Details := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal);
aSize := ThemeServices.GetDetailSizeForPPI(Details, PixelsPerInch); // Maybe: aSize := ThemeServices.GetDetailSizeForPPI(Details, PixelsPerInch);
aSize := ThemeServices.GetDetailSize(Details);
ImageList1.Width:=Max(16,aSize.cx); ImageList1.Width:=Max(16,aSize.cx);
ImageList1.Height:=Max(16,aSize.cy); ImageList1.Height:=Max(16,aSize.cy);
// add empty images // add empty images