Skip to content

Commit

Permalink
Themed find panel
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed May 10, 2023
1 parent 8a9ad3a commit 35ea7a3
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 138 deletions.
6 changes: 5 additions & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
<PackageName Value="LCL"/>
</Item4>
</RequiredPackages>
<Units Count="173">
<Units Count="174">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -1077,6 +1077,10 @@
<Filename Value="components/simba.component_menubar.pas"/>
<IsPartOfProject Value="True"/>
</Unit172>
<Unit173>
<Filename Value="components/simba.component_button.pas"/>
<IsPartOfProject Value="True"/>
</Unit173>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
50 changes: 50 additions & 0 deletions Source/components/simba.component_button.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
unit simba.component_button;

{$i simba.inc}

interface

uses
Classes, SysUtils, Buttons;

type
TSimbaButton = class(TSpeedButton)
protected
procedure PaintBackground(var PaintRect: TRect); override;
end;

TSimbaToggleButton = class(TSimbaButton)
constructor Create(AOwner: TComponent); override;
end;

implementation

uses
simba.theme;

procedure TSimbaButton.PaintBackground(var PaintRect: TRect);
begin
Canvas.Brush.Color := SimbaTheme.ColorFrame;
Canvas.FillRect(PaintRect);

Canvas.Pen.Color := SimbaTheme.ColorFrame;
if Down or MouseInClient then
Canvas.Brush.Color := SimbaTheme.ColorActive
else
Canvas.Brush.Color := SimbaTheme.ColorScrollBarActive;

Canvas.RoundRect(PaintRect, Width div 5, Width div 5);
end;

constructor TSimbaToggleButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);

AllowAllUp := True;
GroupIndex := 1+AOwner.ComponentCount;

Font.Color := SimbaTheme.ColorFont;
end;

end.

66 changes: 44 additions & 22 deletions Source/components/simba.component_edit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ TSimbaEdit = class(TCustomControl)

procedure ClearCache;

procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override;
function GetTextWidthCache(const Cache: EPaintCache; const Str: String): Integer;

procedure SelectAll;
Expand Down Expand Up @@ -114,7 +115,7 @@ TSimbaEdit = class(TCustomControl)
implementation

uses
Math, Clipbrd;
Math, Clipbrd, simba.theme;

procedure TSimbaEdit.SetHintText(Value: String);
begin
Expand Down Expand Up @@ -154,6 +155,13 @@ procedure TSimbaEdit.ClearCache;
end;
end;

procedure TSimbaEdit.CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
begin
inherited CalculatePreferredSize(PreferredWidth, PreferredHeight, WithThemeSpace);

PreferredHeight := CalculateHeight();
end;

procedure TSimbaEdit.WMSetFocus(var Message: TLMSetFocus);
begin
inherited;
Expand Down Expand Up @@ -230,7 +238,7 @@ function TSimbaEdit.CalculateHeight: Integer;
with TBitmap.Create() do
try
Canvas.Font := Self.Font;
Canvas.Font.Size := Round(Abs(GetFontData(Canvas.Font.Handle).Height) * 72 / Canvas.Font.PixelsPerInch) + 2; // Measure on larger font size - Font size can be 0
Canvas.Font.Size := Round(Abs(GetFontData(Canvas.Font.Handle).Height) * 72 / Canvas.Font.PixelsPerInch) + 1; // Measure on larger font size - Font size can be 0

Result := Canvas.TextHeight('Tay') + (BorderWidth * 2);
finally
Expand Down Expand Up @@ -258,6 +266,9 @@ procedure TSimbaEdit.AddCharAtCursor(C: Char);
if (Ord(C) < 32) then
Exit;

if HasSelection then
DeleteSelection();

Inc(FCaretX);
NewText := Text;
Insert(C, NewText, FCaretX);
Expand Down Expand Up @@ -400,6 +411,7 @@ procedure TSimbaEdit.Paint;
OldFontColor: TColor;
TextWidth: Integer;
X1, X2: Integer;
DrawCaretX: Integer;
begin
Canvas.Brush.Color := Color;
Canvas.FillRect(ClientRect);
Expand All @@ -421,7 +433,7 @@ procedure TSimbaEdit.Paint;
end;

if (FDrawOffsetX = 0) then
FDrawOffsetX := (BorderWidth*2);
FDrawOffsetX := (BorderWidth * 2);

// Selection
if HasSelection() then
Expand Down Expand Up @@ -452,18 +464,6 @@ procedure TSimbaEdit.Paint;
Canvas.Brush.Color := Color;
Canvas.FillRect(0, 0, 2, Height);
Canvas.FillRect(Width - 2, 0, Width, Height);

// Caret
if FCaretTimer.Enabled then
begin
Inc(FCaretFlash);
if Odd(FCaretFlash) then
Canvas.Pen.Color := clWhite
else
Canvas.Pen.Color := clBlack;
Canvas.Pen.Mode := pmXor;
Canvas.Line((FDrawOffsetX + TextWidth) - 1, BorderWidth, (FDrawOffsetX + TextWidth) - 1, Height - BorderWidth);
end;
end else
if (FHintText <> '') then
begin
Expand All @@ -480,8 +480,28 @@ procedure TSimbaEdit.Paint;
end;

if Focused then
Canvas.Brush.Color := ColorBorderActive
else
begin
// Caret
if FCaretTimer.Enabled then
begin
Inc(FCaretFlash);
if Odd(FCaretFlash) then
Canvas.Pen.Color := clWhite
else
Canvas.Pen.Color := clBlack;

Canvas.Pen.Mode := pmXor;

if (Text = '') then
DrawCaretX := (BorderWidth * 2)
else
DrawCaretX := (FDrawOffsetX + TextWidth) - 1;

Canvas.Line(DrawCaretX, BorderWidth, DrawCaretX, Height - BorderWidth);
end;

Canvas.Brush.Color := ColorBorderActive;
end else
Canvas.Brush.Color := ColorBorder;

Canvas.FrameRect(0, 0, Width, Height);
Expand Down Expand Up @@ -611,17 +631,19 @@ constructor TSimbaEdit.Create(AOwner: TComponent);
ControlStyle := ControlStyle + [csOpaque];
Cursor := crIBeam;
TabStop := True;
Height := CalculateHeight();

HintTextStyle := [fsItalic];
HintTextColor := cl3DDkShadow;

Color := clWindow;
ColorSelection := clHighlight;
ColorBorder := cl3DDkShadow;
ColorBorderActive := cl3DDkShadow;
Font.Color := SimbaTheme.ColorFont;
Color := SimbaTheme.ColorBackground;
ColorSelection := SimbaTheme.ColorActive;
ColorBorder := SimbaTheme.ColorFrame;
ColorBorderActive := SimbaTheme.ColorActive;

BorderWidth := 3;

Height := CalculateHeight();
end;

procedure TSimbaEdit.Clear;
Expand Down
4 changes: 2 additions & 2 deletions Source/forms/simba.main.lfm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object SimbaForm: TSimbaForm
Left = 3237
Left = 3768
Height = 578
Top = 716
Top = 380
Width = 910
Caption = 'Simba'
ClientHeight = 578
Expand Down
123 changes: 28 additions & 95 deletions Source/forms/simba.scripttabsform.lfm
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
object SimbaScriptTabsForm: TSimbaScriptTabsForm
Left = 3624
Height = 192
Top = 1099
Left = 3840
Height = 206
Top = 25
Width = 816
AllowDropFiles = True
Caption = 'Editor'
ClientHeight = 192
ClientHeight = 206
ClientWidth = 816
DesignTimePPI = 120
OnDestroy = FormDestroy
Expand All @@ -16,44 +16,44 @@ object SimbaScriptTabsForm: TSimbaScriptTabsForm
LCLVersion = '2.2.4.0'
object FindPanel: TPanel
Left = 0
Height = 85
Top = 107
Height = 34
Top = 172
Width = 816
Align = alBottom
AutoSize = True
BevelOuter = bvNone
ClientHeight = 85
ClientHeight = 34
ClientWidth = 816
ParentColor = False
TabOrder = 0
Visible = False
OnResize = FindPanelResize
object FindEdit: TEdit
AnchorSideLeft.Control = FindPanel
AnchorSideTop.Control = FindPanel
AnchorSideBottom.Control = FindPanel
AnchorSideBottom.Side = asrBottom
Left = 5
Height = 28
Top = 5
Width = 209
BorderSpacing.Left = 5
BorderSpacing.Top = 5
BorderSpacing.Bottom = 2
OnChange = FindEditChange
OnKeyDown = FindButtonKeyDown
object FindEditPanel: TPanel
Left = 0
Height = 34
Top = 0
Width = 0
Align = alLeft
AutoSize = True
BevelOuter = bvNone
TabOrder = 0
end
object FindButtonPanel: TPanel
Left = 0
Height = 34
Top = 0
Width = 0
Align = alLeft
AutoSize = True
BevelOuter = bvNone
TabOrder = 1
end
object FindButtonClose: TSpeedButton
AnchorSideTop.Control = FindPanel
AnchorSideRight.Control = FindPanel
AnchorSideRight.Side = asrBottom
AnchorSideBottom.Control = FindPanel
AnchorSideBottom.Side = asrBottom
Left = 779
Height = 75
Height = 24
Top = 5
Width = 27
Anchors = [akTop, akRight, akBottom]
Align = alRight
BorderSpacing.Top = 5
BorderSpacing.Right = 10
BorderSpacing.Bottom = 5
Expand All @@ -62,73 +62,6 @@ object SimbaScriptTabsForm: TSimbaScriptTabsForm
Spacing = 0
OnClick = FindButtonClick
end
object FindButtonUp: TBitBtn
AnchorSideLeft.Control = FindButtonDown
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = FindEdit
AnchorSideBottom.Control = FindEdit
AnchorSideBottom.Side = asrBottom
Left = 266
Height = 28
Top = 5
Width = 42
Anchors = [akTop, akLeft, akBottom]
AutoSize = True
BorderSpacing.Left = 5
Images = SimbaForm.Images
ImageIndex = 43
OnClick = FindButtonClick
OnKeyDown = FindButtonKeyDown
OnResize = FindButtonResize
Spacing = 0
TabOrder = 2
end
object FindButtonDown: TBitBtn
AnchorSideLeft.Control = FindEdit
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = FindEdit
AnchorSideBottom.Control = FindEdit
AnchorSideBottom.Side = asrBottom
Left = 219
Height = 28
Top = 5
Width = 42
Anchors = [akTop, akLeft, akBottom]
AutoSize = True
BorderSpacing.Left = 5
Images = SimbaForm.Images
ImageIndex = 44
OnClick = FindButtonClick
OnKeyDown = FindButtonKeyDown
OnResize = FindButtonResize
Spacing = 0
TabOrder = 1
end
object FindCheckBoxCaseSens: TCheckBox
AnchorSideLeft.Control = FindEdit
AnchorSideTop.Control = FindCheckboxWholeWord
AnchorSideTop.Side = asrBottom
Left = 5
Height = 24
Top = 59
Width = 117
BorderSpacing.Bottom = 2
Caption = 'Case Sensitive'
OnChange = FindEditChange
TabOrder = 3
end
object FindCheckboxWholeWord: TCheckBox
AnchorSideLeft.Control = FindEdit
AnchorSideTop.Control = FindEdit
AnchorSideTop.Side = asrBottom
Left = 5
Height = 24
Top = 35
Width = 148
Caption = 'Whole Words Only'
OnChange = FindEditChange
TabOrder = 4
end
end
object TabPopupMenu: TPopupMenu
Images = SimbaForm.Images
Expand Down
Loading

0 comments on commit 35ea7a3

Please sign in to comment.