Fanning Software Consulting

Depressed Widget Buttons

QUESTION: I'd like to make a toolbar with each button having a special bitmap. But I can figure out how to make these buttons look depressed when they are selected. Is there a trick I am missing?

ANSWER: I usually tell the buttons I'll be switching to Matlab in about half a second if they don't do what I want. That tends to make them depressed.

Actually, you can get the depressed look you are looking for with bitmap buttons by setting the EXCLUSIVE or NONEXCLUSIVE keywords on the base widget that will hold your bitmap buttons. Note that if you are running your program in an X environment (or if you want to write cross-platform code, and who doesn't?), you should also set the TOOLBAR keyword on the base widget creation routine. This will make your buttons look and behave more naturally.

A picture of a bitmap toolbar widget.
An example of a toolbar made with bitmapped buttons.
 

Making exclusive or non-exclusive text buttons (instead of bitmap buttons) that look depressed when selected is more difficult. Text buttons in exclusive bases are normally represented as radio buttons. I have solved the problem in the past by creating my own “buttons” from draw widgets. I write these as compound widgets, and I modify the draw widget event structure internally so that it looks like a button event structure to anyone who uses these modified “buttons”.

A picture depressed buttons made from draw widgets.
An example of depressed buttons made from draw widgets.
 

Dick Jackson has worked out a way to make a bitmap from a piece of text. You use the bitmap instead of the text, thus avoiding the probem of depressed text buttons altogether. He offered the code on the IDL newsgroup, and it worked extremely well the couple of times I needed to use it.

A picture depressed buttons made from text bitmaps.
An example from Dick Jackson's program BitmapForButtonText.
 

[Return to IDL Programming Tips]