Skip to content

Commit

Permalink
Fix SCI_SETMARGINLEFT not being redone after DPI change + add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnlaan committed Jun 15, 2024
1 parent 9ba320b commit a99e8c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
8 changes: 6 additions & 2 deletions Projects/Src/CompForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3376,6 +3376,7 @@ procedure TCompileForm.UpdateOccurrenceIndicators(const AMemo: TCompScintEdit);
end;

procedure TCompileForm.UpdateOutputTabSetListsItemHeightAndDebugTimeWidth;
{ Should be called at startup and after DPI changes }
begin
CompilerOutputList.Canvas.Font.Assign(CompilerOutputList.Font);
CompilerOutputList.ItemHeight := CompilerOutputList.Canvas.TextHeight('0') + 1;
Expand Down Expand Up @@ -3406,6 +3407,7 @@ destructor TBitmapWithBits.Destroy;
end;

procedure TCompileForm.UpdateMarginsIcons;
{ Should be called at startup and after theme and DPI changes }

type
TMarkerBitmaps = TObjectDictionary<Integer, TBitmapWithBits>;
Expand Down Expand Up @@ -3502,13 +3504,15 @@ procedure TCompileForm.UpdateMarginsIcons;

procedure TCompileForm.UpdateMarginsWidths;
{ Update the width of our two margins. Note: the width of the line numbers
margin is fully handled by TScintEdit. }
margin is fully handled by TScintEdit. Should be called at startup and after
DPI change. }
begin
var IconMarkersWidth := ToCurrentPPI(18); { 3 pixel margin on both sides of the icon }
var BaseChangeHistoryWidth := ToCurrentPPI(6); { 6 = 2 pixel bar with 2 pixel margin on both sides because: "SC_MARK_BAR ... takes ... 1/3 of the margin width" }
var LeftBlankMarginWidth := ToCurrentPPI(2); { 2 pixel margin between gutter and the main text }

for var Memo in FMemos do
Memo.UpdateMarginsWidths(IconMarkersWidth, BaseChangeHistoryWidth);
Memo.UpdateMarginsWidths(IconMarkersWidth, BaseChangeHistoryWidth, LeftBlankMarginWidth, 0);
end;

procedure TCompileForm.SplitPanelMouseMove(Sender: TObject;
Expand Down
15 changes: 9 additions & 6 deletions Projects/Src/CompScintEdit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ TCompScintEdit = class(TScintEdit)
property Used: Boolean read FUsed write FUsed;
procedure UpdateIndicators(const Ranges: TScintRangeList;
const IndicatorNumber: TCompScintIndicatorNumber);
procedure UpdateMarginsWidths(const IconMarkersWidth, BaseChangeHistoryWidth: Integer);
procedure UpdateMarginsWidths(const IconMarkersWidth, BaseChangeHistoryWidth,
LeftBlankMarginWidth, RightBlankMarginWidth: Integer);
procedure UpdateThemeColorsAndStyleAttributes;
end;

Expand Down Expand Up @@ -225,10 +226,6 @@ procedure TCompScintEdit.CreateWnd;
Call(SCI_SETMARGINMASKN, 2, not (SC_MASK_FOLDERS or mmIconsMask));
Call(SCI_SETMARGINCURSORN, 2, SC_CURSORARROW);

{ Set 2 pixel margin between gutter and the main text - note: the first
parameter is unused so the value '0' doesn't mean anything below }
Call(SCI_SETMARGINLEFT, 0, ToCurrentPPI(2));

Call(SCI_MARKERDEFINE, mmLineError, SC_MARK_BACKFORE);
Call(SCI_MARKERSETFORE, mmLineError, clWhite);
Call(SCI_MARKERSETBACK, mmLineError, clMaroon);
Expand Down Expand Up @@ -280,15 +277,21 @@ procedure TCompScintEdit.UpdateIndicators(const Ranges: TScintRangeList;
end;
end;

procedure TCompScintEdit.UpdateMarginsWidths(const IconMarkersWidth, BaseChangeHistoryWidth: Integer);
procedure TCompScintEdit.UpdateMarginsWidths(const IconMarkersWidth,
BaseChangeHistoryWidth, LeftBlankMarginWidth, RightBlankMarginWidth: Integer);
begin
Call(SCI_SETMARGINWIDTHN, 1, IconMarkersWidth);

var ChangeHistoryWidth: Integer;
if ChangeHistory then
ChangeHistoryWidth := BaseChangeHistoryWidth
else
ChangeHistoryWidth := 0; { Current this is just the preprocessor output memo }
Call(SCI_SETMARGINWIDTHN, 2, ChangeHistoryWidth);

{ Note: the first parameter is unused so the value '0' doesn't mean anything below }
Call(SCI_SETMARGINLEFT, 0, LeftBlankMarginWidth);
Call(SCI_SETMARGINRIGHT, 0, RightBlankMarginWidth);
end;

procedure TCompScintEdit.UpdateThemeColorsAndStyleAttributes;
Expand Down

0 comments on commit a99e8c7

Please sign in to comment.