PBToolboxAI v4 ← Site

buttonbar — u_pbt_buttonbar #

← Component reference · Guide contents

buttonbar lays out a row of command buttons — icon, label, or both — in one component. A click reports the button id (ue_clicked); each button is driven by a handle (of_button) to disable, colour or hide it. It is the component to prefer as soon as there are several buttons: one WebView2 for the whole bar, where N separate button would cost N.

▶ See it live — Demo application, Button bar tile, with the code and this page side by side.


Quick start #

// A command bar in three lines
uo_bar.of_add_button(/*key*/ "save", /*image_file*/ "mono:img\packimages.dll:svg/samples/save", /*text*/ "Save")
uo_bar.of_add_button(/*key*/ "find", /*image_file*/ "mono:img\packimages.dll:svg/samples/find", /*text*/ "Find")
uo_bar.of_add_button(/*key*/ "copy", /*image_file*/ "", /*text*/ "Copy")   // no icon

// Grey out a button
uo_bar.of_button(/*key*/ "copy").ib_enabled = false

// React : ue_clicked carries the button key
// (in the ue_clicked event of the component)
CHOOSE CASE as_key
	CASE "save" ; wf_save()
	CASE "find" ; wf_find()
END CHOOSE

Properties #

PropertyTypeDefaultDescription
ii_padding_xinteger12Left/right inset of the bar, in pixels: the space before the first button and after the last one. 0 presses the buttons to the edges; -1 = the theme's
ii_padding_yinteger12Top/bottom inset of the bar, in pixels. A button FILLS the bar's height, so this inset decides how tall the buttons are (a taller bar, or a smaller inset, gives taller buttons). 12 by default; -1 = the theme's
ii_gapinteger-1Space BETWEEN two buttons, in pixels. -1 (default) = the theme's. 0 joins the buttons, with a separator line between them when the theme has one
is_alignstringendAligns the row: start (left), center, end (right, default, like a dialog) or justify (equal-width buttons across the full width). Logical (RTL-aware) values — ALIGN_* constants
is_defaultstring""Key of the default button — the primary action, painted with the accent, that Enter fires (like a dialog's OK). When a button of the bar has the keyboard focus, Enter fires THAT button, which then wears the default look (the Windows convention); is_default still reads back the key you set. A greyed or hidden default does not take Enter: the key stays with the window. When two bars of the same window have a default button (two MDI sheets, two panels), Enter goes to the one on the side of the focus. The role leaves with its button: removing it, or clearing the bar, empties is_default. Empty = none; only one default button at a time
is_cancelstring""Key of the cancel button — the one Escape fires (like a dialog's Cancel). Greyed or hidden, it does not take Escape. The role leaves with its button: removing it, or clearing the bar, empties is_cancel. Empty = none; only one cancel button at a time
is_theme_stylestring""Visual style of the component (THEME_STYLE_* constants); empty = the application's, followed at every change
is_theme_modestring""Light or dark variant (THEME_MODE_* constants); empty = the application's, followed at every change
il_theme_accentlong-1Accent colour of this component (-1 = the application accent, or the theme's)
is_tooltipstring""Simple tooltip shown when hovering the component
is_super_tooltip_titlestring""Title of the rich tooltip (takes precedence over is_tooltip)
is_super_tooltip_textstring""Text of the rich tooltip (rich markup accepted)
is_super_tooltip_imagestring""Image of the rich tooltip

Methods #

MethodRole
of_add_button (string as_key, string as_image_file, string as_text) → longAdds a command button (id, image file, label) at the end of the bar. mono: on the image recolours it to the theme; an empty label makes an icon-only button. Returns 0, -5 on an empty key, a key holding / or a vertical bar, a key already in the bar, or a button with neither image nor text
of_insert_button (string as_key, integer ai_index, string as_image_file, string as_text) → longInserts a command button at position ai_index (1 based), shifting the rest right. Returns 0, -5 on an empty key, a key holding / or a vertical bar, a key already in the bar, or a button with neither image nor text
of_remove_button (string as_key) → longRemoves one button by its key; the others keep their live state. Its Alt+letter, the shortcuts the application gave it, its default / cancel role, colours and tooltip leave with it. Returns 0, -5 on an empty key or a key that names no button
of_move_button (string as_key, integer ai_index) → longMoves one button to position ai_index (1 based) without losing its live state. Returns 0, -5 on an empty key or a key that names no button
of_clear_buttons ( ) → longRemoves every button from the bar, with their Alt+letters, the shortcuts the application gave them, the default / cancel roles, colours and tooltips. Returns 0, -2 when not created
of_focus_button (string as_key) → longPuts the keyboard focus on ONE button — No rather than Yes in a destructive question, so that Enter answers No. Returns 0, -5 on an empty key or a key that names no button, -4 when the button cannot take it (greyed, hidden, or not drawn in demo mode), -2 when not created
of_register_shortcut (string as_chord, string as_key) → longGives ONE button a keyboard shortcut (Ctrl+S, F5…): pressed anywhere in the window, it fires the button (ue_clicked), even when the focus is elsewhere. It is independent of the button's Alt+letter: greying the button, changing its letter or re-enabling it never touches it. An empty chord removes it. On a bar a shortcut always names a button: the one-argument form, or a key that names no button, returns -5. Returns 0, -2 when not created
of_button (string as_key) → n_pbt_buttonbar_buttonReturns a button's handle (by id) to read or change its properties (see below)

Events #

EventWhen
ue_clicked (string as_key)A button was used: a click, Enter (the default button, or the focused one), Escape (the cancel button), its Alt+letter or a shortcut registered on it. Its key is passed: an application that wires Cancel must expect it from Escape too. A disabled button emits nothing

A button's properties (of_button) #

PropertyTypeDefaultDescription
ib_enabledbooleantrueEnables or disables a button; disabled, it cannot be clicked, nor fired by Enter, Escape or its shortcut
ib_visiblebooleantrueShows or hides a button; hidden, it keeps its place and comes back where it was
is_textstring""The button label; change it after adding. A button keeps a label or an icon: emptying the label of a button without an icon is refused, and the label reads back unchanged
is_imagestring""The button icon (image file; mono: follows the theme); change it after adding. Emptying the icon of a button without a label is refused. An icon-only button is announced to a screen reader by its tooltip (is_tooltip), else by its key
il_badgelong0A small count badge in the button corner (0 = none)
is_shortcutstring""Mnemonic for this button: Alt+the letter fires it, from anywhere in the window, and the letter is underlined in its label. One letter (the first is used); empty = none. A shortcut registered explicitly for the same key (of_register_shortcut) wins over the letter; a PB menu using the same letter loses it while the button can fire. While the button is greyed, hidden or not drawn in demo mode, its letter is left to the window
il_back_colorlong-1Background of THIS button (-1 = the component's, which follows the theme)
il_text_colorlong-1Text colour of THIS button (-1 = the component's)
il_back_color_hoverlong-1Background of THIS button on hover (-1 = the component's)
il_text_color_hoverlong-1Text colour of THIS button on hover (-1 = the component's)
il_accentlong-1Accent of THIS button (-1 = the component's accent)

Inherited from the common base #

These members exist on every visual component — they are not specific to this one. They are detailed once, in the transverse chapters; this table only says where to read them.

MembersRoleDetailed in
of_count · of_keys_at · of_hasWalk what the component holds3.2 Items
of_resetPut the component back to zero3.6 Resetting a component: of_reset()
of_register_shortcut · of_clear_shortcutsThe component's keyboard chords3.5 Keyboard shortcuts
of_is_created · of_is_ready · of_get_last_errorWhether it was born, whether it is ready, what failed3.7 Diagnostics
of_save_as_png · of_save_as_jpgExport the rendering as an image3.8 Exporting the rendering as an image
of_set_redrawGroup changes into a single repaint3.10 Best practices
of_preload_iconsIcons shown with no delayInstant display: of_icon
of_set_translationTranslate one of the component's labels5.2 Adapting a label: of_set_translation
of_focus_webviewGive the component the focus6.4 Keyboard and focus
of_print · of_print_to_pdfPrint, or write a PDF6.9 Printing
of_set_property · of_get_property · of_component_nameDriving a property by its name3.1 The property engine

← Component reference · Guide contents