Skip to content

Commit

Permalink
Issue #1202: Separated drawing of tree lines from grid lines
Browse files Browse the repository at this point in the history
Issue #1088: Better visualize fixed columns
  • Loading branch information
joachimmarder committed Aug 2, 2023
1 parent 258528e commit 67b09ba
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
63 changes: 39 additions & 24 deletions Source/VirtualTrees.BaseTree.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,9 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor)
function DragOver(Source: TObject; KeyState: Integer; DragState: TDragState; Pt: TPoint;
var Effect: Integer): HResult; reintroduce; virtual;
procedure DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: TDimension); virtual;
procedure DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension; UseSelectedBkColor: Boolean = False); virtual;
procedure DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension); virtual;
procedure DrawGridHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: TDimension); virtual;
procedure DrawGridVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension; pFixedColumn: Boolean = False); virtual;
procedure EndOperation(OperationKind: TVTOperationKind);
procedure EnsureNodeFocused(); virtual;
function FindNodeInSelection(P: PVirtualNode; var Index: Integer; LowBound, HighBound: Integer): Boolean; virtual;
Expand Down Expand Up @@ -12007,36 +12009,54 @@ procedure TBaseVirtualTree.DrawDottedHLine(const PaintInfo: TVTPaintInfo; Left,
R: TRect;

begin
with PaintInfo, Canvas do
with PaintInfo do
begin
Brush.Color := FColors.BackGroundColor;
R := Rect(Min(Left, Right), Top, Max(Left, Right) + 1, Top + 1);
Winapi.Windows.FillRect(Handle, R, DottedBrushTreeLines.Handle);
Winapi.Windows.FillRect(PaintInfo.Canvas.Handle, R, DottedBrushTreeLines.Handle);
end;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TBaseVirtualTree.DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension; UseSelectedBkColor: Boolean = False);
procedure TBaseVirtualTree.DrawGridHLine(const PaintInfo: TVTPaintInfo; Left, Right, Top: TDimension);
// Draws a horizontal grid line
var
R: TRect;
begin
R := Rect(Min(Left, Right), Top, Max(Left, Right) + 1, Top + 1);
StyleServices.DrawElement(PaintInfo.Canvas.Handle, StyleServices.GetElementDetails(tlGroupHeaderLineOpenSelectedNotFocused), R, @R, CurrentPPI);
end;


//----------------------------------------------------------------------------------------------------------------------

procedure TBaseVirtualTree.DrawGridVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension; pFixedColumn: Boolean = False);
// Draws a vertical grid line
var
R: TRect;
begin
R := Rect(Left, Min(Top, Bottom), Left + 1, Max(Top, Bottom) + 1);
if pFixedColumn then
StyleServices.DrawElement(PaintInfo.Canvas.Handle, StyleServices.GetElementDetails(ttBranch), R, @R, CurrentPPI)
else
StyleServices.DrawElement(PaintInfo.Canvas.Handle, StyleServices.GetElementDetails(tlGroupHeaderLineOpenSelectedNotFocused), R, @R, CurrentPPI);
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TBaseVirtualTree.DrawDottedVLine(const PaintInfo: TVTPaintInfo; Top, Bottom, Left: TDimension);

// Draws a horizontal line with alternating pixels (this style is not supported for pens under Win9x).

var
R: TRect;

begin
R := Rect(Left, Min(Top, Bottom), Left + 1, Max(Top, Bottom) + 1);
with PaintInfo, Canvas do
begin
if UseSelectedBkColor then
begin
if Focused or (toPopupMode in FOptions.PaintOptions) then
Brush.Color := FColors.FocusedSelectionColor
else
Brush.Color := FColors.UnfocusedSelectionColor;
end
else
Brush.Color := FColors.BackGroundColor;
R := Rect(Left, Min(Top, Bottom), Left + 1, Max(Top, Bottom) + 1);
Brush.Color := FColors.BackGroundColor;
Winapi.Windows.FillRect(Handle, R, DottedBrushTreeLines.Handle);
end;
end;
Expand Down Expand Up @@ -20864,7 +20884,6 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe
SavedTargetDC: Integer;
PaintWidth: TDimension;
CurrentNodeHeight: TDimension;
lUseSelectedBkColor: Boolean; // determines if the dotted grid lines need to be painted in selection color of background color
lEmptyListTextMargin: Integer;

CellIsTouchingClientRight: Boolean;
Expand Down Expand Up @@ -21129,15 +21148,15 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe
begin
if BidiMode = bdLeftToRight then
begin
DrawDottedHLine(PaintInfo, CellRect.Left + PaintInfo.Offsets[ofsCheckBox] - fImagesMargin, CellRect.Right - 1, CellRect.Bottom - 1);
DrawGridHLine(PaintInfo, CellRect.Left + PaintInfo.Offsets[ofsCheckBox] - fImagesMargin, CellRect.Right - 1, CellRect.Bottom - 1);
end
else
begin
DrawDottedHLine(PaintInfo, CellRect.Left, CellRect.Right - IfThen(toFixedIndent in FOptions.PaintOptions, 1, IndentSize) * FIndent - 1, CellRect.Bottom - 1);
DrawGridHLine(PaintInfo, CellRect.Left, CellRect.Right - IfThen(toFixedIndent in FOptions.PaintOptions, 1, IndentSize) * FIndent - 1, CellRect.Bottom - 1);
end;
end
else
DrawDottedHLine(PaintInfo, CellRect.Left, CellRect.Right, CellRect.Bottom - 1);
DrawGridHLine(PaintInfo, CellRect.Left, CellRect.Right, CellRect.Bottom - 1);

Dec(CellRect.Bottom);
Dec(ContentRect.Bottom);
Expand Down Expand Up @@ -21167,11 +21186,7 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe
begin
if (BidiMode = bdLeftToRight) or not ColumnIsEmpty(Node, Column) then
begin
Canvas.Font.Color := FColors.GridLineColor;
lUseSelectedBkColor := (poDrawSelection in PaintOptions) and (toFullRowSelect in FOptions.SelectionOptions) and
(vsSelected in Node.States) and not (toUseBlendedSelection in FOptions.PaintOptions) and not
(tsUseExplorerTheme in FStates);
DrawDottedVLine(PaintInfo, CellRect.Top, CellRect.Bottom, CellRect.Right - 1, lUseSelectedBkColor);
DrawGridVLine(PaintInfo, CellRect.Top, CellRect.Bottom, CellRect.Right - 1, ColumnIsFixed and (NextColumn >= 0));
end;

Dec(CellRect.Right);
Expand Down Expand Up @@ -21369,7 +21384,7 @@ procedure TBaseVirtualTree.PaintTree(TargetCanvas: TCanvas; Window: TRect; Targe
(toShowVertGridLines in FOptions.PaintOptions) and
(not (hoAutoResize in FHeader.Options) or (Cardinal(FirstColumn) < TColumnPosition(Count - 1))) then
begin
DrawDottedVLine(PaintInfo, R.Top, R.Bottom, R.Right - 1);
DrawGridVLine(PaintInfo, R.Top, R.Bottom, R.Right - 1);
Dec(R.Right);
end;

Expand Down
4 changes: 2 additions & 2 deletions Source/VirtualTrees.Types.pas
Original file line number Diff line number Diff line change
Expand Up @@ -641,14 +641,14 @@ TSortDirectionHelper = record helper for VirtualTrees.Types.TSortDirection
dtVCL
);

// Determines the look of a tree's lines.
// Determines the look of a tree's lines that show the hierarchy
TVTLineStyle = (
lsCustomStyle, // application provides a line pattern
lsDotted, // usual dotted lines (default)
lsSolid // simple solid lines
);

// TVTLineType is used during painting a tree
// TVTLineType is used during painting a tree for its tree lines that show the hierarchy
TVTLineType = (
ltNone, // no line at all
ltBottomRight, // a line from bottom to the center and from there to the right
Expand Down

0 comments on commit 67b09ba

Please sign in to comment.