Skip to content

Commit

Permalink
Improve customization of scrollbar & toolbar.
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jun 8, 2023
1 parent 751c4e0 commit a3b5391
Show file tree
Hide file tree
Showing 25 changed files with 801 additions and 358 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="171">
<Units Count="172">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -1068,6 +1068,10 @@
<Filename Value="components/simba.component_button.pas"/>
<IsPartOfProject Value="True"/>
</Unit170>
<Unit171>
<Filename Value="components/simba.component_scrollbar.pas"/>
<IsPartOfProject Value="True"/>
</Unit171>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
5 changes: 5 additions & 0 deletions Source/components/simba.component_button.pas
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.component_button;

{$i simba.inc}
Expand Down
46 changes: 44 additions & 2 deletions Source/components/simba.component_menubar.pas
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.component_menubar;

{$i simba.inc}

interface

uses
Classes, SysUtils, Controls, Forms, Menus, Graphics;
Classes, SysUtils, Controls, Forms, Menus, Graphics,
simba.settings;

type
TSimbaMainMenuBar = class(TCustomControl)
Expand All @@ -29,6 +35,8 @@ TSimbaMainMenuBar = class(TCustomControl)
procedure MouseLeave; override;

procedure DoMenuClose(Sender: TObject);

procedure MaybeReplaceModifiers(Menu: TPopupMenu);
public
constructor Create(AOwner: TComponent); override;

Expand Down Expand Up @@ -86,6 +94,7 @@ procedure TSimbaMainMenuBar.Paint;
Style.Alignment := taCenter;
Style.Layout := tlCenter;

Canvas.Font.Color := SimbaTheme.ColorFont;
Canvas.Brush.Color := SimbaTheme.ColorFrame;
Canvas.FillRect(ClientRect);

Expand Down Expand Up @@ -160,12 +169,41 @@ procedure TSimbaMainMenuBar.DoMenuClose(Sender: TObject);
FItems[I].ClosedAt := GetTickCount64();
end;

procedure TSimbaMainMenuBar.MaybeReplaceModifiers(Menu: TPopupMenu);

procedure ReplaceModifiers(const MenuItem: TMenuItem);
var
I: Integer;
Key: Word;
Shift: TShiftState;
begin
if (MenuItem.ShortCut > 0) then
begin
ShortCutToKey(MenuItem.ShortCut, Key, Shift);
if (ssCtrl in Shift) then
MenuItem.ShortCut := ShortCut(Key, Shift - [ssCtrl] + [ssMeta]);
end;

for I := 0 to MenuItem.Count - 1 do
ReplaceModifiers(MenuItem.Items[I]);
end;

var
I: Integer;
begin
if Application.HasOption('no-macos-commandkey') then
Exit;

for I := 0 to Menu.Items.Count - 1 do
ReplaceModifiers(Menu.Items[I]);
end;

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

ParentFont := True;
ControlStyle := ControlStyle + [csOpaque];
Font.Color := SimbaTheme.ColorFont;

CalculateSizes();
end;
Expand All @@ -177,6 +215,10 @@ procedure TSimbaMainMenuBar.AddMenu(Title: String; APopupMenu: TPopupMenu);
FItems[High(FItems)].Menu := APopupMenu;
APopupMenu.OnClose := @DoMenuClose;

{$IFDEF DARWIN}
MaybeReplaceModifiers(APopupMenu);
{$ENDIF}

CalculateSizes();
end;

Expand Down
53 changes: 53 additions & 0 deletions Source/components/simba.component_scrollbar.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.component_scrollbar;

{$i simba.inc}

interface

uses
Classes, SysUtils,
ATScrollBar, simba.settings;

type
TSimbaScrollBar = class(TATScrollBar)
protected
procedure DoSettingChange_ScrollBarSize(Setting: TSimbaSetting);
procedure DoSettingChange_ScrollBarArrowSize(Setting: TSimbaSetting);
public
constructor Create(AOwner: TComponent); override;
end;

implementation

uses
simba.mufasatypes;

procedure TSimbaScrollBar.DoSettingChange_ScrollBarSize(Setting: TSimbaSetting);
begin
Theme^.InitialSize := Scale96ToScreen(Setting.Value);

Update();
end;

procedure TSimbaScrollBar.DoSettingChange_ScrollBarArrowSize(Setting: TSimbaSetting);
begin
Theme^.ArrowSize := Setting.Value;

Update();
end;

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

SimbaSettings.RegisterChangeHandler(Self, SimbaSettings.General.ScrollBarSize, @DoSettingChange_ScrollBarSize, True);
SimbaSettings.RegisterChangeHandler(Self, SimbaSettings.General.ScrollBarArrowSize, @DoSettingChange_ScrollBarArrowSize, True);
end;

end.

29 changes: 24 additions & 5 deletions Source/components/simba.component_synedit.pas
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.component_synedit;

{$i simba.inc}
Expand All @@ -8,13 +13,13 @@ interface
Classes, SysUtils, Controls, Forms, StdCtrls, Graphics,
SynEdit, SynEditTypes, SynEditFoldedView, SynEditTextBuffer, SynEditMarkupSelection,
LazSynEditText,
ATScrollBar;
simba.component_scrollbar;

type
TSimbaSynEdit = class(TSynEdit)
protected
FScrollbarVert: TATScrollbar;
FScrollbarHorz: TATScrollbar;
FScrollbarVert: TSimbaScrollBar;
FScrollbarHorz: TSimbaScrollBar;

procedure DoVertScrollBarChange(Sender: TObject);
procedure DoHorzScrollBarChange(Sender: TObject);
Expand All @@ -31,6 +36,7 @@ TSimbaSynEdit = class(TSynEdit)

// Hide gutters etc so the synedit acts more like the "memo" component.
procedure HideSynEditThings;
procedure ReplaceKeyStrokeModifiers(const Find, Replace: TShiftStateEnum);

property FontAntialising: Boolean read GetFontAntialising write SetFontAntialising;
end;
Expand Down Expand Up @@ -114,11 +120,11 @@ constructor TSimbaSynEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);

FScrollbarVert := TATScrollbar.Create(Self);
FScrollbarVert := TSimbaScrollBar.Create(Self);
FScrollbarVert.Kind := sbVertical;
FScrollbarVert.OnChange := @DoVertScrollBarChange;

FScrollbarHorz := TATScrollbar.Create(Self);
FScrollbarHorz := TSimbaScrollBar.Create(Self);
FScrollbarHorz.Kind := sbHorizontal;
FScrollbarHorz.OnChange := @DoHorzScrollBarChange;

Expand Down Expand Up @@ -147,5 +153,18 @@ procedure TSimbaSynEdit.HideSynEditThings;
Options := Options + [eoHideRightMargin];
end;

procedure TSimbaSynEdit.ReplaceKeyStrokeModifiers(const Find, Replace: TShiftStateEnum);
var
I: Integer;
begin
for I := 0 to Keystrokes.Count - 1 do
if (Find in Keystrokes[I].Shift) then
Keystrokes[I].Shift := Keystrokes[I].Shift - [Find] + [Replace];

for I := 0 to MouseActions.Count - 1 do
if (Find in MouseActions[I].Shift) then
MouseActions[I].Shift := MouseActions[I].Shift - [Find] + [Replace];
end;

end.

5 changes: 5 additions & 0 deletions Source/components/simba.component_tabcontrol.pas
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.component_tabcontrol;

{$i simba.inc}
Expand Down
52 changes: 20 additions & 32 deletions Source/components/simba.component_treeview.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ interface

uses
Classes, SysUtils, Controls, Forms, Graphics, StdCtrls, ComCtrls, LMessages, LCLType, ImgList,
ATScrollBar,
simba.component_edit, simba.component_treeviewhint;
simba.component_edit, simba.component_treeviewhint, simba.component_scrollbar;

type
TSimbaTreeView = class;

TSimbaInternalTreeView = class(TTreeView)
protected
FLoading: Boolean;
FScrollbarVert: TATScrollbar;
FScrollbarHorz: TATScrollbar;
FScrollbarVert: TSimbaScrollBar;
FScrollbarHorz: TSimbaScrollBar;

procedure UpdateScrollBars;
procedure DoSelectionChanged; override;
Expand All @@ -49,12 +48,14 @@ TSimbaTreeView = class(TCustomControl)
FFilterEdit: TSimbaEdit;
FHint: TSimbaTreeViewHint;
FTree: TSimbaInternalTreeView;
FScrollbarVert: TATScrollbar;
FScrollbarHorz: TATScrollbar;
FScrollbarVert: TSimbaScrollBar;
FScrollbarHorz: TSimbaScrollBar;
FOnGetNodeHint: TNodeHintEvent;
FNodeClass: TTreeNodeClass;
FOnAfterFilter: TNotifyEvent;

procedure FontChanged(Sender: TObject); override;

procedure UpdateFilter;

function GetImages: TCustomImageList;
Expand Down Expand Up @@ -128,19 +129,17 @@ constructor TSimbaTreeView.Create(AOwner: TComponent; NodeClass: TTreeNodeClass)

FNodeClass := NodeClass;

FScrollbarVert := TATScrollbar.Create(Self);
FScrollbarVert := TSimbaScrollBar.Create(Self);
FScrollbarVert.Parent := Self;
FScrollbarVert.Kind := sbVertical;
FScrollbarVert.Align := alRight;
FScrollbarVert.Width := ATScrollbarTheme.InitialSize;
FScrollbarVert.OnChange := @ScrollVertChange;
FScrollbarVert.Visible := True;

FScrollbarHorz := TATScrollbar.Create(Self);
FScrollbarHorz := TSimbaScrollBar.Create(Self);
FScrollbarHorz.Parent := Self;
FScrollbarHorz.Kind := sbHorizontal;
FScrollbarHorz.Align := alBottom;
FScrollbarHorz.Height := ATScrollbarTheme.InitialSize;
FScrollbarHorz.IndentCorner := 100;
FScrollbarHorz.OnChange := @ScrollHorzChange;
FScrollbarHorz.Visible := True;
Expand All @@ -156,13 +155,13 @@ constructor TSimbaTreeView.Create(AOwner: TComponent; NodeClass: TTreeNodeClass)
FTree.ExpandSignType := tvestArrow;
FTree.ExpandSignColor := clWhite;
FTree.TreeLinePenStyle := psClear;
FTree.Font.Color := SimbaTheme.ColorFont;
FTree.BackgroundColor := SimbaTheme.ColorBackground;
FTree.SelectionColor := SimbaTheme.ColorActive;
FTree.OnCreateNodeClass := @DoCreateNodeClass;
FTree.OnMouseMove := @DoMouseMove;
FTree.DragMode := dmAutomatic;
FTree.TabStop := False;
FTree.BackgroundColor := SimbaTheme.ColorBackground;
FTree.SelectionColor := SimbaTheme.ColorActive;
FTree.Font.Color := SimbaTheme.ColorFont;

FHint := TSimbaTreeViewHint.Create(FTree);

Expand All @@ -177,25 +176,6 @@ constructor TSimbaTreeView.Create(AOwner: TComponent; NodeClass: TTreeNodeClass)
FFilterEdit.Font.Color := SimbaTheme.ColorFont;
FFilterEdit.HintTextColor := clLtGray;
FFilterEdit.HintText := '(search)';

with ATScrollbarTheme do
begin
InitialSize := Scale96ToScreen(16);
ThumbMinSize := Scale96ToScreen(24);
ThumbRoundedRect := False;
DirectJumpOnClickPageUpDown := True;

ColorCorner := SimbaTheme.ColorFrame;
ColorBG := SimbaTheme.ColorScrollBarInActive;
ColorThumbBorder := SimbaTheme.ColorScrollBarActive;
ColorThumbFill := SimbaTheme.ColorScrollBarActive;
ColorThumbFillOver := SimbaTheme.ColorScrollBarActive;
ColorThumbFillPressed := SimbaTheme.ColorScrollBarActive;
ColorThumbDecor := SimbaTheme.ColorScrollBarActive;
ColorArrowFill := SimbaTheme.ColorScrollBarActive;
ColorArrowBorder := SimbaTheme.ColorScrollBarActive;
ColorArrowSign := SimbaTheme.ColorLine;
end;
end;

procedure TSimbaTreeView.FullCollapse;
Expand Down Expand Up @@ -294,6 +274,14 @@ function TSimbaTreeView.GetTopLevelCount: Integer;
Result := FTree.Items.TopLvlCount;
end;

procedure TSimbaTreeView.FontChanged(Sender: TObject);
begin
inherited FontChanged(Sender);

FTree.Font := Self.Font;
FTree.Font.Color := SimbaTheme.ColorFont;
end;

procedure TSimbaTreeView.UpdateFilter;
var
Node, NodeParent: TTreeNode;
Expand Down

0 comments on commit a3b5391

Please sign in to comment.