From ebd7cefb2e90bdd32cab37508dfbcd847b8a8cb4 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 23 Sep 2020 19:07:15 +0000 Subject: [PATCH] spkToolbar: Add separators (ButtonKind = bkSeparator). Patch provided by Husker, https://forum.lazarus.freepascal.org/index.php/topic,51552.msg378527.html git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7689 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../spktoolbar/SpkToolbar/SpkToolbar.pas | 6 ++ .../spktoolbar/SpkToolbar/spkt_Buttons.pas | 89 ++++++++++++++++--- .../spktoolbar/SpkToolbar/spkt_Const.pas | 18 ++++ 3 files changed, 103 insertions(+), 10 deletions(-) diff --git a/components/spktoolbar/SpkToolbar/SpkToolbar.pas b/components/spktoolbar/SpkToolbar/SpkToolbar.pas index 49f4d72aa..e4b239fc3 100644 --- a/components/spktoolbar/SpkToolbar/SpkToolbar.pas +++ b/components/spktoolbar/SpkToolbar/SpkToolbar.pas @@ -1868,6 +1868,9 @@ begin LargeButtonChevronVMargin := round(LARGEBUTTON_CHEVRON_VMARGIN * AYProportion); LargeButtonCaptionTopRail := round(LARGEBUTTON_CAPTION_TOP_RAIL * AYProportion); LargeButtonCaptionButtomRail := round(LARGEBUTTON_CAPTION_BOTTOM_RAIL * AYProportion); + LargeButtonSeparatorWidth := round(LARGEBUTTON_SEPARATOR_WIDTH * AXProportion); + LargeButtonSeparatorTopMargin := round(LARGEBUTTON_SEPARATOR_TOP_MARGIN * AYProportion); + LargeButtonSeparatorBottomMargin := round(LARGEBUTTON_SEPARATOR_BOTTOM_MARGIN * AYProportion); SmallButtonGlyphWidth := round(SMALLBUTTON_GLYPH_WIDTH * AXProportion); SmallButtonBorderWidth := round(SMALLBUTTON_BORDER_WIDTH * AXProportion); @@ -1876,6 +1879,9 @@ begin SmallButtonDropdownWidth := round(SMALLBUTTON_DROPDOWN_WIDTH * AXProportion); SmallButtonRadius := SMALLBUTTON_RADIUS; SmallButtonMinWidth := 2 * SmallButtonPadding + SmallButtonGlyphWidth; + SmallButtonSeparatorWidth := round(SMALLBUTTON_SEPARATOR_WIDTH * AXProportion); + SmallButtonSeparatorTopMargin := round(SMALLBUTTON_SEPARATOR_TOP_MARGIN * AYProportion); + SmallButtonSeparatorBottomMargin := round(SMALLBUTTON_SEPARATOR_BOTTOM_MARGIN * AYProportion); MaxElementHeight := round(MAX_ELEMENT_HEIGHT * AYProportion); PaneRowHeight := round(PANE_ROW_HEIGHT * AYProportion); diff --git a/components/spktoolbar/SpkToolbar/spkt_Buttons.pas b/components/spktoolbar/SpkToolbar/spkt_Buttons.pas index 1ac643ae9..169a3c3b2 100644 --- a/components/spktoolbar/SpkToolbar/spkt_Buttons.pas +++ b/components/spktoolbar/SpkToolbar/spkt_Buttons.pas @@ -24,7 +24,7 @@ uses type TSpkMouseButtonElement = (beNone, beButton, beDropdown); - TSpkButtonKind = (bkButton, bkButtonDropdown, bkDropdown, bkToggle); + TSpkButtonKind = (bkButton, bkButtonDropdown, bkDropdown, bkToggle, bkSeparator); TSpkBaseButton = class; @@ -952,6 +952,11 @@ begin FDropdownRect := T2DIntRect.Create(FRect.Left, FRect.Bottom - LargeButtonDropdownFieldSize, FRect.Right, FRect.Bottom); //FDropdownRect := T2DIntRect.Create(FRect.Left, FRect.Bottom - LargeButtonDropdownFieldSize + 1, FRect.Right, FRect.Bottom); end else + if FButtonKind = bkSeparator then + begin + FButtonRect := T2DIntRect.Create(FRect.Left, FRect.Top, FRect.Left + LargeButtonSeparatorWidth, FRect.Bottom - LargeButtonDropdownFieldSize); + FDropdownRect := T2DIntRect.Create(0, 0, 0, 0); + end else begin FButtonRect := FRect; FDropdownRect := T2DIntRect.Create(0, 0, 0, 0); @@ -963,6 +968,11 @@ begin FDropdownRect.Create(FRect.Left, FRect.Bottom - LargeButtonDropdownFieldSize, FRect.Right, FRect.Bottom); // FDropdownRect.Create(FRect.Left, FRect.Bottom - LargeButtonDropdownFieldSize + 1, FRect.Right, FRect.Bottom); end else + if FButtonKind = bkSeparator then + begin + FButtonRect.Create(FRect.Left, FRect.Top, FRect.Left + LargeButtonSeparatorWidth, FRect.Bottom - LargeButtonDropdownFieldSize); + FDropdownRect.Create(0, 0, 0, 0); + end else begin FButtonRect := FRect; FDropdownRect.Create(0, 0, 0, 0); @@ -995,14 +1005,33 @@ var drawBtn: Boolean; ppi: Integer; R: TRect; + SeparatorRect: TRect; + SeparatorLineColor: TColor; begin if FToolbarDispatch = nil then exit; if FAppearance = nil then exit; - if (FRect.Width < 2*LargeButtonRadius) or (FRect.Height < 2*LargeButtonRadius) then + if (FButtonKind <> bkSeparator) then + begin + if (FRect.Width < 2*LargeButtonRadius) or (FRect.Height < 2*LargeButtonRadius) then + exit; + end else + begin + SeparatorLineColor := FAppearance.Pane.BorderDarkColor; + SeparatorRect.Create(FRect.Left + (LargeButtonSeparatorWidth div 2), + FRect.Top,FRect.Left + (LargeButtonSeparatorWidth div 2) + 1, + FRect.Bottom); + TGUITools.DrawVLine( + ABuffer, + SeparatorRect.Left, + SeparatorRect.Top + LargeButtonSeparatorTopMargin, + SeparatorRect.Bottom - LargeButtonSeparatorBottomMargin, + SeparatorLineColor + ); exit; + end; delta := FAppearance.Element.HotTrackBrightnessChange; case FAppearance.Element.Style of @@ -1303,6 +1332,12 @@ begin if FAppearance = nil then exit; + if FButtonKind = bkSeparator then + begin + Result := LargeButtonSeparatorWidth; + exit + end; + Bitmap := FToolbarDispatch.GetTempBitmap; if Bitmap = nil then exit; @@ -1352,14 +1387,24 @@ procedure TSpkSmallButton.CalcRects; var RectVector: T2DIntVector; begin - ConstructRects(FButtonRect, FDropdownRect); - {$IFDEF EnhancedRecordSupport} - RectVector := T2DIntVector.Create(FRect.Left, FRect.Top); - {$ELSE} - RectVector.Create(FRect.Left, FRect.Top); - {$ENDIF} - FButtonRect := FButtonRect + RectVector; - FDropdownRect := FDropdownRect + RectVector; + if FButtonKind = bkSeparator then + begin + FButtonRect.Create(FRect.Left, FRect.Top, + FRect.Left + SmallButtonSeparatorWidth, + FRect.Bottom - LargeButtonDropdownFieldSize + ); + FDropdownRect.Create(0, 0, 0, 0); + end else + begin + ConstructRects(FButtonRect, FDropdownRect); + {$IFDEF EnhancedRecordSupport} + RectVector := T2DIntVector.Create(FRect.Left, FRect.Top); + {$ELSE} + RectVector.Create(FRect.Left, FRect.Top); + {$ENDIF} + FButtonRect := FButtonRect + RectVector; + FDropdownRect := FDropdownRect + RectVector; + end; end; procedure TSpkSmallButton.ConstructRects(out BtnRect, DropRect: T2DIntRect); @@ -1515,10 +1560,28 @@ var R: TRect; dx: Integer; ppi: Integer; + SeparatorRect: TRect; + SeparatorLineColor: TColor; begin if (FToolbarDispatch = nil) or (FAppearance = nil) then exit; + if FButtonKind = bkSeparator then + begin + SeparatorLineColor := FAppearance.Pane.BorderDarkColor; + SeparatorRect.Create(FRect.Left + (SmallButtonSeparatorWidth div 2), + FRect.Top,FRect.Left + (SmallButtonSeparatorWidth div 2) + 1, + FRect.Bottom); + TGUITools.DrawVLine( + ABuffer, + SeparatorRect.Left, + SeparatorRect.Top + SmallButtonSeparatorTopMargin, + SeparatorRect.Bottom - SmallButtonSeparatorBottomMargin, + SeparatorLineColor + ); + exit; + end; + if (FRect.Width < 2*SmallButtonRadius) or (FRect.Height < 2*SmallButtonRadius) then exit; @@ -1761,6 +1824,12 @@ begin if FAppearance = nil then exit; + if FButtonKind = bkSeparator then + begin + Result := SmallButtonSeparatorWidth; + exit + end; + ConstructRects(BtnRect, DropRect); if FButtonKind = bkButtonDropdown then diff --git a/components/spktoolbar/SpkToolbar/spkt_Const.pas b/components/spktoolbar/SpkToolbar/spkt_Const.pas index ea5dbab6a..a727ba201 100644 --- a/components/spktoolbar/SpkToolbar/spkt_Const.pas +++ b/components/spktoolbar/SpkToolbar/spkt_Const.pas @@ -38,6 +38,9 @@ const LARGEBUTTON_CHEVRON_VMARGIN = 2; LARGEBUTTON_CAPTION_TOP_RAIL = 45; LARGEBUTTON_CAPTION_BOTTOM_RAIL = 58; + LARGEBUTTON_SEPARATOR_WIDTH = 9; + LARGEBUTTON_SEPARATOR_TOP_MARGIN = 4; + LARGEBUTTON_SEPARATOR_BOTTOM_MARGIN = 4; SMALLBUTTON_GLYPH_WIDTH = 16; //was: 20; //16; SMALLBUTTON_BORDER_WIDTH = 2; @@ -45,6 +48,9 @@ const SMALLBUTTON_PADDING = 4; // was: 2 SMALLBUTTON_DROPDOWN_WIDTH = 11; SMALLBUTTON_RADIUS = 4; + SMALLBUTTON_SEPARATOR_WIDTH = 9; + SMALLBUTTON_SEPARATOR_TOP_MARGIN = 2; + SMALLBUTTON_SEPARATOR_BOTTOM_MARGIN = 2; DROPDOWN_ARROW_WIDTH = 8; DROPDOWN_ARROW_HEIGHT = 8; @@ -153,6 +159,9 @@ var LargeButtonChevronVMargin: Integer; LargeButtonCaptionTopRail: Integer; LargeButtonCaptionButtomRail: Integer; + LargeButtonSeparatorWidth: Integer; + LargeButtonSeparatorTopMargin: Integer; + LargeButtonSeparatorBottomMargin: Integer; SmallButtonGlyphWidth: Integer; SmallButtonBorderWidth: Integer; @@ -161,6 +170,9 @@ var SmallButtonDropdownWidth: Integer; SmallButtonRadius: Integer; SmallButtonMinWidth: Integer; + SmallButtonSeparatorWidth: Integer; + SmallButtonSeparatorTopMargin: Integer; + SmallButtonSeparatorBottomMargin: Integer; DropdownArrowWidth: Integer; DropdownArrowHeight: Integer; @@ -290,6 +302,9 @@ begin LargeButtonChevronVMargin := SpkScaleY(LARGEBUTTON_CHEVRON_VMARGIN, FromDPI, ToDPI); LargeButtonCaptionTopRail := SpkScaleY(LARGEBUTTON_CAPTION_TOP_RAIL, FromDPI, ToDPI); LargeButtonCaptionButtomRail := SpkScaleY(LARGEBUTTON_CAPTION_BOTTOM_RAIL, FromDPI, ToDPI); + LargeButtonSeparatorWidth := SpkScaleX(LARGEBUTTON_SEPARATOR_WIDTH, FromDPI, ToDPI); + LargeButtonSeparatorTopMargin := SpkScaleY(LARGEBUTTON_SEPARATOR_TOP_MARGIN, FromDPI, ToDPI); + LargeButtonSeparatorBottomMargin := SpkScaleY(LARGEBUTTON_SEPARATOR_BOTTOM_MARGIN, FromDPI, ToDPI); SmallButtonGlyphWidth := SpkScaleX(SMALLBUTTON_GLYPH_WIDTH, FromDPI, ToDPI); SmallButtonBorderWidth := SpkScaleX(SMALLBUTTON_BORDER_WIDTH, FromDPI, ToDPI); @@ -298,6 +313,9 @@ begin SmallButtonDropdownWidth := SpkScaleX(SMALLBUTTON_DROPDOWN_WIDTH, FromDPI, ToDPI); SmallButtonRadius := SMALLBUTTON_RADIUS; SmallButtonMinWidth := 2 * SmallButtonPadding + SmallButtonGlyphWidth; + SmallButtonSeparatorWidth := SpkScaleX(SMALLButton_SEPARATOR_WIDTH, FromDPI, ToDPI); + SmallButtonSeparatorTopMargin := SpkScaleY(SMALLBUTTON_SEPARATOR_TOP_MARGIN, FromDPI, ToDPI); + SmallButtonSeparatorBottomMargin := SpkScaleY(SMALLBUTTON_SEPARATOR_BOTTOM_MARGIN, FromDPI, ToDPI); DropdownArrowWidth := SpkScaleX(DROPDOWN_ARROW_WIDTH, FromDPI, ToDPI); DropdownArrowHeight := SpkScaleY(DROPDOWN_ARROW_HEIGHT, FromDPI, ToDPI);