Skip to content

TStyledCategoryButtons - Technical Reference ​

Overview ​

TStyledCategoryButtons extends TCategoryButtons with styled button rendering, per-item styles, caption/image alignment and notification badges. This page lists the members added by the library to TStyledCategoryButtons, TStyledButtonItem, TStyledButtonCategory and TStyledButtonCategories; the members inherited from the VCL are summarized briefly. For the usage see TStyledCategoryButtons.

Class Hierarchy ​

TCategoryButtons        (Vcl.CategoryButtons)
  └─ TStyledCategoryButtons

TButtonItem             (Vcl.CategoryButtons, a TCollectionItem)
  └─ TStyledButtonItem

TButtonCategory
  └─ TStyledButtonCategory

TButtonCategories
  └─ TStyledButtonCategories

Unit ​

pascal
Vcl.StyledCategoryButtons

Description ​

TStyledCategoryButtons maintains the compatibility with TCategoryButtons (Categories, SelectedItem, ButtonOptions, ButtonWidth, ButtonHeight, Images, the VCL events) and draws every button with the Styled Components renderer. The component has a style (StyleFamily/StyleClass/StyleAppearance, shape and radius) shared by its buttons; each button item can override it. The class is registered for Win32 and Win64 and has the Component Editor Styled CategoryButtons Editor... (see Component Editor).

Key Features ​

  • Full TCategoryButtons compatibility
  • Collapsible categories containing styled buttons
  • Component style and per-item style
  • Caption alignment (left, center, right) and image alignment (left, right, top, bottom, center), with Spacing and ImageMargins
  • Flat appearance
  • Notification badges through an event
  • Follows the VCL Style with the Classic family (AsVCLComponent)

Published properties (Object Inspector) ​

Categories and layout ​

PropertyTypeDefaultDescription
CategoriesTStyledButtonCategoriesemptyCollection of the categories (TStyledButtonCategory); Categories.Add and Categories[Index] return a TStyledButtonCategory; the buttons of a category are in its Items (TButtonItem, cast to TStyledButtonItem)
CaptionAlignmentTAlignmenttaLeftJustifyAlignment of the caption: taLeftJustify, taCenter, taRightJustify (used when boShowCaptions is in ButtonOptions)
ImageAlignmentTImageAlignmentiaLeftPosition of the image: iaLeft, iaRight, iaTop, iaBottom, iaCenter
ImageMarginsTImageMarginsLeft=2Margins around the image; stored only when changed
SpacingInteger4Distance between the image and the caption
FlatBooleanFalseFlat buttons: the face of the Normal and Disabled button is not drawn
ButtonsCursorTCursorcrHandPointCursor when the mouse is over a button
CursorTCursorcrDefaultCursor of the component outside the buttons

Style ​

PropertyTypeDefaultDescription
StyleFamilyTStyledButtonFamilyClassicStyle family of the buttons
StyleClassTStyledButtonClassWindowsStyle class of the buttons
StyleAppearanceTStyledButtonAppearanceNormalAppearance of the buttons
StyleDrawTypeTStyledButtonDrawTypebtRoundRectShape (btRect, btRoundRect, btRounded, btEllipse)
StyleRadiusInteger6Corner radius; must be greater than zero
StyleShadowSizeInteger-1Shadow of the buttons in pixels, the same in every state (-1 = the one of the style family, 0 = none); values below -1 raise an exception
StyleRoundedCornersTRoundedCornersall fourWhich corners are rounded
ButtonStyleNormal, ButtonStylePressed, ButtonStyleSelected, ButtonStyleHot, ButtonStyleDisabledTStyledButtonAttributesfrom the styleColors, border and font of each state, shared by the items that have the style of the component

Setting StyleFamily to a family that is not registered raises EStyledAttributesException (while streaming a form it falls back to Classic).

Events ​

EventTypeDescription
OnGetNotificationBadgeInfoTGetCategoryButtonsBadgeInfoSupplies the badge of a button: (const ACategoryIndex, AButtonItemIndex: Integer; var ABadgeContent: string; var ASize: TNotificationBadgeSize; var APosition: TNotificationBadgePosition; var AColor, AFontColor: TColor; var AFontStyle: TFontStyles). The badge is drawn if ABadgeContent is not empty (defaults: nbsNormal, nbpTopRight, bold)

Inherited from TCategoryButtons (summary) ​

ButtonOptions (boAllowReorder, boAllowCopyingButtons, boFullSize, boGradientFill, boShowCaptions, boBoldCaptions, boUsePlusMinus, boCaptionOnlyBorder), ButtonWidth, ButtonHeight, ButtonFlow, Images, HeaderFont, SelectedItem, Align, Anchors, Color, Font, Enabled, Visible, StyleElements, TabOrder, TabStop, PopupMenu, ShowHint, and the events OnButtonClicked, OnCategoryCollapase (spelled so in the VCL), OnSelectedItemChange, OnBeforeDrawButton, OnDrawButton, OnAfterDrawButton, OnDrawIcon, OnHotButton, OnReorderButton, OnClick, OnEnter, OnExit... See the Embarcadero documentation of Vcl.CategoryButtons.TCategoryButtons.

Public members ​

MemberDescription
property AsVCLComponent: BooleanTrue when the component follows the VCL Style (Classic family, seClient in StyleElements, class equal to the active style); setting it to True resets the style to Classic/Windows/Normal. Not stored
property StyleApplied: BooleanTrue when the style has been resolved
constructor CreateStyled(AOwner; const AFamily; const AClass; const AAppearance)Creates the component with a given style (Create uses the defaults registered with RegisterDefaultRenderingStyle)
class procedure RegisterDefaultRenderingStyle(const ADrawType; const AFamily = DEFAULT_CLASSIC_FAMILY; const AClass = DEFAULT_WINDOWS_CLASS; const AAppearance = DEFAULT_APPEARANCE; const AStyleRadius = DEFAULT_RADIUS; const AButtonsCursor = DEFAULT_CURSOR)Default style, shape, radius and buttons cursor of the components created afterwards
procedure SetCategoryButtonsStyle(const AStyleFamily; const AStyleClass; const AStyleAppearance)Sets family, class and appearance together; raises EStyledCategoryButtonsError if the combination is not available
function StyledButtonState(const AState: TButtonDrawState): TStyledButtonStateConverts the draw state of the VCL into the styled state (Disabled, Hot, Pressed, Selected, Normal)
procedure Assign(Source: TPersistent)Copies also the style of another TStyledCategoryButtons
procedure SetBounds(...)Override of TControl.SetBounds

TStyledButtonItem ​

Button of a category (Category.Items), a TButtonItem: Caption, ImageIndex, Hint, Action, OnClick are inherited from the VCL. A new item gets the style, shape and radius of the component; Assign copies the style properties too.

Published ​

PropertyTypeDefaultDescription
CategoryButtonsTStyledCategoryButtonsread-onlyThe component the item belongs to
StyleFamilyTStyledButtonFamilyof the componentFamily of the item; stored only if the item has a family, class or appearance different from the component
StyleClassTStyledButtonClassof the componentClass of the item
StyleAppearanceTStyledButtonAppearanceof the componentAppearance of the item
StyleDrawTypeTStyledButtonDrawTypeof the componentShape of the item; stored only if different
StyleRadiusIntegerof the componentCorner radius of the item; stored only if different
StyleShadowSizeIntegerof the componentShadow of the item (-1 = the one of the style family); stored only if different
StyleRoundedCornersTRoundedCornersof the componentRounded corners of the item; stored only if different

The item has no NotificationBadge property: the badges are supplied by the OnGetNotificationBadgeInfo event of the component.

Public ​

MethodDescription
procedure SetButtonStyle(const AStyleFamily; const AStyleClass; const AStyleAppearance)Sets family, class and appearance of the item. An empty value keeps the current one or, if the item has none, uses that of the component; raises EStyledCategoryButtonsError if the combination is not available
procedure Assign(Source: TPersistent)Copies the caption, image and the style of another item

TStyledButtonCategory and TStyledButtonCategories ​

TStyledButtonCategory is a TButtonCategory (Caption, Collapsed, Color, GradientColor, TextColor, Items) without additional members: it exists so that the collection creates styled categories. TStyledButtonCategories is the collection: function Add: TStyledButtonCategory, Items[Index]: TStyledButtonCategory (default property) and property CategoryButtons: TStyledCategoryButtons (the owner).

Types ​

NameDescription
TGetCategoryButtonsBadgeInfoType of OnGetNotificationBadgeInfo (see above)
TButtonProcreference to procedure (Button: TStyledButtonItem), used to iterate the items
TStyledCategoryButtonsClass, TStyledButtonItemClass, TStyledButtonCategoryClass, TStyledButtonCategoriesClassClass references
EStyledCategoryButtonsErrorException class

Usage Examples ​

Categories and styled items ​

pascal
var
  CatButtons: TStyledCategoryButtons;
  Cat: TStyledButtonCategory;
  Item: TStyledButtonItem;
begin
  CatButtons := TStyledCategoryButtons.CreateStyled(Self,
    BOOTSTRAP_FAMILY, btn_primary, BOOTSTRAP_NORMAL);
  CatButtons.Parent := Self;
  CatButtons.Align := alLeft;
  CatButtons.Images := ImageList1;

  Cat := CatButtons.Categories.Add;
  Cat.Caption := 'File';
  Item := Cat.Items.Add as TStyledButtonItem;
  Item.Caption := 'New';
  Item.ImageIndex := 0;
  Item.SetButtonStyle(BOOTSTRAP_FAMILY, btn_success, BOOTSTRAP_NORMAL);

  Cat := CatButtons.Categories.Add;
  Cat.Caption := 'Tools';
  Cat.Collapsed := True;   // starts collapsed
end;

Image position and flat buttons ​

pascal
CatButtons.ImageAlignment := iaTop;
CatButtons.CaptionAlignment := taCenter;
CatButtons.Flat := True;

Replacing TCategoryButtons with the Interposer unit ​

Vcl.StyledComponentsHooks declares TCategoryButtons = class(TStyledCategoryButtons) and TButtonCategory = class(TStyledButtonCategory); the component creates TStyledButtonItem buttons. See Interposer Unit.

See Also ​

Released under Apache License, Version 2.0.