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
This commit is contained in:
wp_xxyyzz
2020-09-23 19:07:15 +00:00
parent 202d0b5559
commit ebd7cefb2e
3 changed files with 103 additions and 10 deletions

View File

@ -1868,6 +1868,9 @@ begin
LargeButtonChevronVMargin := round(LARGEBUTTON_CHEVRON_VMARGIN * AYProportion); LargeButtonChevronVMargin := round(LARGEBUTTON_CHEVRON_VMARGIN * AYProportion);
LargeButtonCaptionTopRail := round(LARGEBUTTON_CAPTION_TOP_RAIL * AYProportion); LargeButtonCaptionTopRail := round(LARGEBUTTON_CAPTION_TOP_RAIL * AYProportion);
LargeButtonCaptionButtomRail := round(LARGEBUTTON_CAPTION_BOTTOM_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); SmallButtonGlyphWidth := round(SMALLBUTTON_GLYPH_WIDTH * AXProportion);
SmallButtonBorderWidth := round(SMALLBUTTON_BORDER_WIDTH * AXProportion); SmallButtonBorderWidth := round(SMALLBUTTON_BORDER_WIDTH * AXProportion);
@ -1876,6 +1879,9 @@ begin
SmallButtonDropdownWidth := round(SMALLBUTTON_DROPDOWN_WIDTH * AXProportion); SmallButtonDropdownWidth := round(SMALLBUTTON_DROPDOWN_WIDTH * AXProportion);
SmallButtonRadius := SMALLBUTTON_RADIUS; SmallButtonRadius := SMALLBUTTON_RADIUS;
SmallButtonMinWidth := 2 * SmallButtonPadding + SmallButtonGlyphWidth; 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); MaxElementHeight := round(MAX_ELEMENT_HEIGHT * AYProportion);
PaneRowHeight := round(PANE_ROW_HEIGHT * AYProportion); PaneRowHeight := round(PANE_ROW_HEIGHT * AYProportion);

View File

@ -24,7 +24,7 @@ uses
type type
TSpkMouseButtonElement = (beNone, beButton, beDropdown); TSpkMouseButtonElement = (beNone, beButton, beDropdown);
TSpkButtonKind = (bkButton, bkButtonDropdown, bkDropdown, bkToggle); TSpkButtonKind = (bkButton, bkButtonDropdown, bkDropdown, bkToggle, bkSeparator);
TSpkBaseButton = class; 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, FRect.Right, FRect.Bottom);
//FDropdownRect := T2DIntRect.Create(FRect.Left, FRect.Bottom - LargeButtonDropdownFieldSize + 1, FRect.Right, FRect.Bottom); //FDropdownRect := T2DIntRect.Create(FRect.Left, FRect.Bottom - LargeButtonDropdownFieldSize + 1, FRect.Right, FRect.Bottom);
end else 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 begin
FButtonRect := FRect; FButtonRect := FRect;
FDropdownRect := T2DIntRect.Create(0, 0, 0, 0); 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, FRect.Right, FRect.Bottom);
// FDropdownRect.Create(FRect.Left, FRect.Bottom - LargeButtonDropdownFieldSize + 1, FRect.Right, FRect.Bottom); // FDropdownRect.Create(FRect.Left, FRect.Bottom - LargeButtonDropdownFieldSize + 1, FRect.Right, FRect.Bottom);
end else 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 begin
FButtonRect := FRect; FButtonRect := FRect;
FDropdownRect.Create(0, 0, 0, 0); FDropdownRect.Create(0, 0, 0, 0);
@ -995,14 +1005,33 @@ var
drawBtn: Boolean; drawBtn: Boolean;
ppi: Integer; ppi: Integer;
R: TRect; R: TRect;
SeparatorRect: TRect;
SeparatorLineColor: TColor;
begin begin
if FToolbarDispatch = nil then if FToolbarDispatch = nil then
exit; exit;
if FAppearance = nil then if FAppearance = nil then
exit; exit;
if (FButtonKind <> bkSeparator) then
begin
if (FRect.Width < 2*LargeButtonRadius) or (FRect.Height < 2*LargeButtonRadius) then if (FRect.Width < 2*LargeButtonRadius) or (FRect.Height < 2*LargeButtonRadius) then
exit; 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; delta := FAppearance.Element.HotTrackBrightnessChange;
case FAppearance.Element.Style of case FAppearance.Element.Style of
@ -1303,6 +1332,12 @@ begin
if FAppearance = nil then if FAppearance = nil then
exit; exit;
if FButtonKind = bkSeparator then
begin
Result := LargeButtonSeparatorWidth;
exit
end;
Bitmap := FToolbarDispatch.GetTempBitmap; Bitmap := FToolbarDispatch.GetTempBitmap;
if Bitmap = nil then if Bitmap = nil then
exit; exit;
@ -1352,6 +1387,15 @@ procedure TSpkSmallButton.CalcRects;
var var
RectVector: T2DIntVector; RectVector: T2DIntVector;
begin begin
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); ConstructRects(FButtonRect, FDropdownRect);
{$IFDEF EnhancedRecordSupport} {$IFDEF EnhancedRecordSupport}
RectVector := T2DIntVector.Create(FRect.Left, FRect.Top); RectVector := T2DIntVector.Create(FRect.Left, FRect.Top);
@ -1360,6 +1404,7 @@ begin
{$ENDIF} {$ENDIF}
FButtonRect := FButtonRect + RectVector; FButtonRect := FButtonRect + RectVector;
FDropdownRect := FDropdownRect + RectVector; FDropdownRect := FDropdownRect + RectVector;
end;
end; end;
procedure TSpkSmallButton.ConstructRects(out BtnRect, DropRect: T2DIntRect); procedure TSpkSmallButton.ConstructRects(out BtnRect, DropRect: T2DIntRect);
@ -1515,10 +1560,28 @@ var
R: TRect; R: TRect;
dx: Integer; dx: Integer;
ppi: Integer; ppi: Integer;
SeparatorRect: TRect;
SeparatorLineColor: TColor;
begin begin
if (FToolbarDispatch = nil) or (FAppearance = nil) then if (FToolbarDispatch = nil) or (FAppearance = nil) then
exit; 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 if (FRect.Width < 2*SmallButtonRadius) or (FRect.Height < 2*SmallButtonRadius) then
exit; exit;
@ -1761,6 +1824,12 @@ begin
if FAppearance = nil then if FAppearance = nil then
exit; exit;
if FButtonKind = bkSeparator then
begin
Result := SmallButtonSeparatorWidth;
exit
end;
ConstructRects(BtnRect, DropRect); ConstructRects(BtnRect, DropRect);
if FButtonKind = bkButtonDropdown then if FButtonKind = bkButtonDropdown then

View File

@ -38,6 +38,9 @@ const
LARGEBUTTON_CHEVRON_VMARGIN = 2; LARGEBUTTON_CHEVRON_VMARGIN = 2;
LARGEBUTTON_CAPTION_TOP_RAIL = 45; LARGEBUTTON_CAPTION_TOP_RAIL = 45;
LARGEBUTTON_CAPTION_BOTTOM_RAIL = 58; 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_GLYPH_WIDTH = 16; //was: 20; //16;
SMALLBUTTON_BORDER_WIDTH = 2; SMALLBUTTON_BORDER_WIDTH = 2;
@ -45,6 +48,9 @@ const
SMALLBUTTON_PADDING = 4; // was: 2 SMALLBUTTON_PADDING = 4; // was: 2
SMALLBUTTON_DROPDOWN_WIDTH = 11; SMALLBUTTON_DROPDOWN_WIDTH = 11;
SMALLBUTTON_RADIUS = 4; SMALLBUTTON_RADIUS = 4;
SMALLBUTTON_SEPARATOR_WIDTH = 9;
SMALLBUTTON_SEPARATOR_TOP_MARGIN = 2;
SMALLBUTTON_SEPARATOR_BOTTOM_MARGIN = 2;
DROPDOWN_ARROW_WIDTH = 8; DROPDOWN_ARROW_WIDTH = 8;
DROPDOWN_ARROW_HEIGHT = 8; DROPDOWN_ARROW_HEIGHT = 8;
@ -153,6 +159,9 @@ var
LargeButtonChevronVMargin: Integer; LargeButtonChevronVMargin: Integer;
LargeButtonCaptionTopRail: Integer; LargeButtonCaptionTopRail: Integer;
LargeButtonCaptionButtomRail: Integer; LargeButtonCaptionButtomRail: Integer;
LargeButtonSeparatorWidth: Integer;
LargeButtonSeparatorTopMargin: Integer;
LargeButtonSeparatorBottomMargin: Integer;
SmallButtonGlyphWidth: Integer; SmallButtonGlyphWidth: Integer;
SmallButtonBorderWidth: Integer; SmallButtonBorderWidth: Integer;
@ -161,6 +170,9 @@ var
SmallButtonDropdownWidth: Integer; SmallButtonDropdownWidth: Integer;
SmallButtonRadius: Integer; SmallButtonRadius: Integer;
SmallButtonMinWidth: Integer; SmallButtonMinWidth: Integer;
SmallButtonSeparatorWidth: Integer;
SmallButtonSeparatorTopMargin: Integer;
SmallButtonSeparatorBottomMargin: Integer;
DropdownArrowWidth: Integer; DropdownArrowWidth: Integer;
DropdownArrowHeight: Integer; DropdownArrowHeight: Integer;
@ -290,6 +302,9 @@ begin
LargeButtonChevronVMargin := SpkScaleY(LARGEBUTTON_CHEVRON_VMARGIN, FromDPI, ToDPI); LargeButtonChevronVMargin := SpkScaleY(LARGEBUTTON_CHEVRON_VMARGIN, FromDPI, ToDPI);
LargeButtonCaptionTopRail := SpkScaleY(LARGEBUTTON_CAPTION_TOP_RAIL, FromDPI, ToDPI); LargeButtonCaptionTopRail := SpkScaleY(LARGEBUTTON_CAPTION_TOP_RAIL, FromDPI, ToDPI);
LargeButtonCaptionButtomRail := SpkScaleY(LARGEBUTTON_CAPTION_BOTTOM_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); SmallButtonGlyphWidth := SpkScaleX(SMALLBUTTON_GLYPH_WIDTH, FromDPI, ToDPI);
SmallButtonBorderWidth := SpkScaleX(SMALLBUTTON_BORDER_WIDTH, FromDPI, ToDPI); SmallButtonBorderWidth := SpkScaleX(SMALLBUTTON_BORDER_WIDTH, FromDPI, ToDPI);
@ -298,6 +313,9 @@ begin
SmallButtonDropdownWidth := SpkScaleX(SMALLBUTTON_DROPDOWN_WIDTH, FromDPI, ToDPI); SmallButtonDropdownWidth := SpkScaleX(SMALLBUTTON_DROPDOWN_WIDTH, FromDPI, ToDPI);
SmallButtonRadius := SMALLBUTTON_RADIUS; SmallButtonRadius := SMALLBUTTON_RADIUS;
SmallButtonMinWidth := 2 * SmallButtonPadding + SmallButtonGlyphWidth; 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); DropdownArrowWidth := SpkScaleX(DROPDOWN_ARROW_WIDTH, FromDPI, ToDPI);
DropdownArrowHeight := SpkScaleY(DROPDOWN_ARROW_HEIGHT, FromDPI, ToDPI); DropdownArrowHeight := SpkScaleY(DROPDOWN_ARROW_HEIGHT, FromDPI, ToDPI);