Today a client (who himself is a developer) approached to me and told me he needs a user-interface for a dialog which acts like a button but displays a small colored icon besides the text. I told him I’ll make it for free if I may give it away to the community.
Below you can find the source code for a user-area that implements a button-like interface, but additionally displays an icon on the left or right side. This icon can be a simple color or a bitmap.
The following is the source code for the above example. You can copy&paste the
IconButton class and the
AddIconButton function into your source code. As of version 1.2, the code is released under the WTFPL license, so do what the fuck you want with it!
The buttons act just like normal Cinema 4D buttons. If the user presses the button, you will receive a call to your
GeDialog.Command() method with the button’s ID. The
IconButton interface supports three different types of icons and four different display modes.
The icon is passed as the foruth parameter to
- Color constant (eg.
- Vector color (eg.
c4d.Vector(1.0, 0.66, 0.12'))
The display mode is passed as the fifth argument to
AddIconButton(). The default value is
IconButton.M_NOICON: Display no icon at all, just the text
IconButton.M_ICONLEFT: Display the icon on the left-hand side
IconButton.M_ICONLEFT: Display the icon on the right-hand side
IconButton.M_FULL: Scale the icon to the full size of the button.
You can do any adjustments to the code you like to fit your personal needs. For example, if you want the icon to be of another size, just modify the
IconButton.S_ICON value either directly on the
IconButton class or on an instance.