I'm not the best programmer (probably), but when I see I can improve something, I do it. Since I couldn't work with last lazarus because of "^ñáéíóúÁÉÍÓÚÜüÑ" issue, I downgraded to v2.0.12 and linking my programs to 64 bits with it. I like dark interfaces and I was trying to modify IDE v2.0.12. When I selected new units or forms, the dialog is mostly "white" and sometimes a little slow when I go back and forth, so I changed the Form color and Font color and put ListBox and Splitter to inherit them, Splitter changed normally but not ListBox, so I took a look (lol) inside the DrawItem and found that there is a little recalculations on every item (slow) and improved the code to make my goal, so I put an onShow to calculate those "once" and redefined DrawItem. Here's the code.
this block goes on the class definition procedure FormShow(Sender: TObject);
·
·
·
procedure HelpButtonClick(Sender: TObject);
procedure CancelButtonClick(Sender :TObject);
procedure MultiselectCheckBoxClick(Sender :TObject);
private
img_W: byte; // IDEImages.Images_16.Width
S96F: byte; // Scale96ToFont(4)
aR: TRect; // Global Rect instead of Local
FIdleConnected: boolean;
FItemType: TIDEProjectItem;
FSortAlphabetically: boolean;
FImageIndex: Integer;
·
·
·
Implementation sectionprocedure TViewUnitDialog.ListboxDrawItem(Control: TWinControl; Index: Integer;
ARect: TRect; State: TOwnerDrawState);
begin
if Index < 0 then Exit;
with ListBox do begin
if odSelected in state then begin
Canvas.Brush.Color := Parent.Font.Color;
Canvas.Font.Color := Parent.Color;
Canvas.Font.Style := [fsBold]
end
else begin
Canvas.Brush.Color := Parent.Color;
Canvas.Font.Color := Parent.Font.Color;
Canvas.Font.Style := []; // normal font
end;
Canvas.FillRect(aRect);
IDEImages.Images_16.Draw(Canvas, 1, aRect.Top, FImageIndex);
Canvas.TextOut(ARect.Left + img_W + S96F, ARect.Top, Items[Index]); // Less Calculations
{ This avoids blank from bottom of last item to ClientHeight }
if (ClientHeight > aRect.Bottom) and
(index = pred(count)) then begin
Canvas.Brush.Color := Parent.Color;
aR.Top := aRect.Bottom; // (aRect.Bottom - aRect.Top) * Count;
aR.Bottom := ClientHeight;
Canvas.FillRect(aR);
end;
end;
end;
onShowprocedure TViewUnitDialog.FormShow(Sender: TObject);
begin
aR := ListBox.ClientRect; // must be initialized here
img_W := IDEImages.Images_16.Width;
S96F := Scale96ToFont(4);
end;