TwBar commands syntax

Description

This page decribes the bar commands allowed in the def string of function TwDefine, and their syntax.

TwDefine(" barName  barCommand1 barCommand2 ... ");

where barCommandn is one of the following commands.

Bar commands

label

Syntax
label=string

Description

Changes the label of a bar, that is the title displayed on top of a bar. By default, the label is the name used when the bar was created.

Example
TwDefine(" mybar label='Engine properties' ");

help

Syntax
help=string

Descritpion

Defines the help message associated to a bar. This message will be displayed inside the Help bar automatically created to help the user.

You can also define a global help message. It will be displayed at the beginning of the Help bar. To define it, use the GLOBAL keyword instead of the bar name.

Example
TwDefine(" mybar help='These properties defines the engine behaviour' ");
 
TwDefine(" GLOBAL help='I can write here a general description of my program.\n Welcome happy users!' ");

color

Syntax
color=alpha red green blue

color=red green blue

Description

Changes the color of a bar. By default this color is chosen randomly.

alpha, red, green and blue are integer values between 0 and 255 that define the alpha, red, green and blue color channels. If alpha is not provided, it is assumed to be opaque (alpha=255).

To ensure good contrast between bar text and background, the red/green/blue color is not used directly. Instead, it is converted to a hue/lightness/saturation color and only the hue and saturation components are used; the lightness is adjusted to get good visual.

Example
TwDefine(" mybar color='50 0 0 255' "); // semi-transparent blue bar
TwDefine(" mybar color='128 128 0' ");  // opaque yellow bar

position

Syntax
position=x y

Description

Move a bar to a new position.

x and y are positive integer values that represent the new position of the bar in pixels. (x=0, y=0) is upper-left corner of the application window.

Example
TwDefine(" mybar position='200 40' "); // move bar to position (200, 40)

size

Syntax
size=sx sy

Description

Change the bar size.

sx and sy are positive integer values that represent the new size of the bar in pixels.

Example
TwDefine(" mybar size='240 320' "); // resize bar

valuesWidth

Syntax
valuesWidth=w

Description

Change the width of the bar right column used to display numerical values.

w is a positive integer that represents width in pixels.

Example
TwDefine(" mybar valuesWidth=120 "); // set values column width

fontSize

Syntax
fontSize=s

Description

Change the size of the font used by the bars.

s is 1 for small font, 2 for medium font, or 3 for large font. Note that all bars share the same font, so this change is applied to all bars.

fontSize is a global command. You can use the GLOBAL keyword instead of a bar name to execute it.

Example
TwDefine(" GLOBAL fontSize=3 "); // use large font

refresh

Syntax
refresh=r

Description

Change the refresh rate of the bar.

Values displayed by a bar are automatically updated to reflect changes of their associated variables. r is a real value corresponding to the number of seconds between two updates.

Example
TwDefine(" mybar refresh=1.5 "); // refresh the bar every 1.5 seconds

show / hide / iconify

Syntax
show

hide

iconify

Description

Show, hide or iconify the tweak bar.

Example
TwDefine(" mybar iconify "); // mybar is iconified
TwDefine(" mybar hide ");    // mybar is hidden
TwDefine(" mybar show ");    // mybar is displayed again

iconPos

Syntax
iconPos=p

Description

Changes the place where icons of iconified bars are displayed.

p is one of the following values:

  • bottomleft or bl for bottom-left corner of the window (default).
  • bottomright or br for bottom-right corner of the window.
  • topleft or tl for top-left corner of the window.
  • topright or tr for top-right corner of the window.

Note that this command is applied to all bar icons. You can use the GLOBAL keyword instead of a bar name to execute it.

Example
TwDefine(" GLOBAL iconPos=bottomright "); // icons go to bottom-right corner of the window

iconAlign

Syntax
iconAlign=vertical

iconAlign=horizontal

Description

Changes the alignment of icons of iconified bars. It can be vertical (the default), or horizontal.

Note that this command is applied to all bar icons. You can use the GLOBAL keyword instead of a bar name to execute it.

Example
TwDefine(" GLOBAL iconAlign=horizontal "); // icons will be aligned horizontally

iconMargin

Syntax
iconMargin=’x y

Description

Add a margin between borders of the window and icons of iconified bars. x and y are the number of pixels between window borders and icons in the x and y directions respectively.

Note that this command is applied to all bar icons. You can use the GLOBAL keyword instead of a bar name to execute it.

Example
TwDefine(" GLOBAL iconMargin='8 16' "); // icons will be displayed at 8 and 16 pixels from the horizontal and vertical window borders respectively

Notes

Note on string parameters

If a command requires a string, it can be a simple name without any special characters; but if it contains special characters like spaces, punctuations or quotation marks, you should surround it with simple quotes (), back-quotes (`), or double-quotes (). In between these two quotes, the other kind of quotes would be considered as normal characters; so use a kind of quotes that does not appear in your string. If you need the three kinds of quotes in your string, you can split it and surround each part by a different quotation mark; the successive string parts would then be concatenated and you’d get the expected result (see the following examples).

Examples:

param=Simple                // ->  Simple

param='Two words'           // ->  Two words

param=`That's All Folks`    // ->  That's All Folks

param='He says "Hello!"'    // ->  He says "Hello!" 
                            // note that in a c-string " are replaced by \" ie.:  " param='He says \"Hello!\"' "

param="'aa'-"`"bb"-`'`cc`'  // ->  'aa'-"bb"-`cc`
                            // note that in a c-string " are replaced by \" ie.: " param=\"'aa'-\"`\"bb\"-`'`cc`' "

Note on case sensitivity

  • Commands keywords are case insensitive: color=’...’ is the same as Color=’...’ and is the same as COLOR=’...’ .
  • Names are case sensitive: mybar is different from MyBar and is different from myBar.

See also


Log in to edit this page