iconidwithbadge()

Function group Execute on client Platform(s)
General YES All

Syntax

iconidwithbadge(cIcn,iCnt/cBadgeIcn[,kIconBadge...,iBadgeColor,iBadgeTextColor])

Description

Returns a formatted string for $iconid. cIcn is the main icon (an SVG icon), iCnt/cBadgeIcn control the badge. The kIconBadge... constants control the display of the badge, and iBadgeColor and iBadgeTextColor set the colors of the badge and text.

When an icon ID uses an SVG icon name, iconidwithbadge() allows you to append additional values to the SVG name to define a badge to be added to the main icon.

The parameters are:

Parameter Description
cIcn the ID of the primary SVG icon for the object / toolbar object
iCnt/cBadgeicn the count to be displayed on the badge, or the ID of a smaller secondary icon
kIconBadge kIconBadgeAlignTop, kIconBadgeAlignBottom, or the default is the position set by the OS, also kIconBadgeBackgroundHide, see below
ibadgecolor the color of the badge, the default is kJSThemeColorSecondary
ibadgetextcolor the color of the count, or secondary icon, the default is kJSThemeColorSecondaryText

The following lines of code set up icon badges for buttons:

Do  $cinst.$objs.button.$iconid.$assign(iconidwithbadge( 'tablet_mac', 9 ))
Do $cinst.$objs.button.$iconid.$assign(iconidwithbadge( 'tablet_mac+32x32', 9 ))
Do $cinst.$objs.button.$iconid.$assign(iconidwithbadge( 'tablet_mac', 99, 0, kDarkGreenkWhite ))

Some Omnis objects used fixed icon sizes, such as menu items or tabbar tabs, therefore when applying a badge to these objects you cannot supply an icon size for the primary icon as the size will be fixed by the object, for example:

Do  $imenus.NewMenu.$objs.Item.$iconid.$assign(iconidwithbadge( 'tablet_mac', 9 ))

When using iconidwithbadge() in a client-executed method, the SVG parameters must be URLs, which can be generated with iconurl() in server-executed code.

The default icon badge background colour is kJSThemeColorSecondary, while the count or secondary icon is kJSThemeColorSecondaryText (for window class controls the colors are the standard OS colors).

Badge Options

The constants kIconBadgeAlignTop and kIconBadgeAlignBottom can be used in the kIconBadge parameter in iconidwithbadge() to specify the position of the badge. Omitting this or passing 0, Omnis will use the default position for the OS – by default, macOS will draw a badge at the top right of an icon, and Windows at the bottom right.

The constant kIconBadgeBackgroundHide allows you to hide the default colored circle badge when used with a secondary icon. If the badge has a count and not an icon, the badge background is always drawn and this option ignored. For example:

$iconid.$assign(iconidwithbadge( 'tablet_mac', 'star', kBadgeIconHideBackground, kDefault, kRed ))