The RENDER_ICON function reads an SVG file in the IDL distribution and returns a byte array for use as a widget button or widget tree icon.
The IDL distribution contains over 2000 icons from the Font Awesome project. These icons can be found in the IDL distribution in:
<IDL_DIR>/resource/bitmaps/svg/brands
<IDL_DIR>/resource/bitmaps/svg/regular
<IDL_DIR>/resource/bitmaps/svg/solid
Note: All of these icons are distributed under the Creative Commons Attribution 4.0 International License and can be freely used in your own applications.
Note: You can use the SVG_ICON_BROWSER routine to quickly display all of the icons that are included within IDL.
This routine is written in the IDL language. Its source code can be found in the file render_icon.pro in the lib/utilities subdirectory of the IDL distribution.
Examples
Read an icon within the IDL distribution and display it in several different sizes:
w = widget_base(/row)
icon = RENDER_ICON("folder-open")
w1 = widget_base(w)
wb = widget_button(w1, value=icon, /bitmap)
icon = RENDER_ICON("folder-open", width=32, height=32)
w1 = widget_base(w)
wb = widget_button(w1, value=icon, /bitmap)
icon = RENDER_ICON("folder-open", width=64, height=64)
w1 = widget_base(w)
wb = widget_button(w1, value=icon, /bitmap)
widget_control, w, /realize
Syntax
Result = RENDER_ICON( Name, BACKGROUND_COLOR=value, FOREGROUND_COLOR=value, HEIGHT=value, ROTATE_DIRECTION=value, WIDTH=value )
Return Value
RENDER_ICON returns a byte array containing the icon data. The dimensions of the Result are either M x N x 3 or M x N x 4 depending upon whether the BACKGROUND_COLOR keyword was specified or not. By default the width and height are both set to 16. However, you can override the width or height (or both) if you want to render the icon in a different size.
Arguments
Name
A scalar string specifying the icon name. There are three different folders containing svg icons within the IDL distribution:
<IDL_DIR>/resource/bitmaps/svg/brands
<IDL_DIR>/resource/bitmaps/svg/regular
<IDL_DIR>/resource/bitmaps/svg/solid
By default, RENDER_ICON looks in the regular folder for the matching icon. To choose one of the other folders, prepend the icon name with either "brands:" or "solid:". For example:
icon = RENDER_ICON("folder-open")
icon = RENDER_ICON("regular:folder-open")
icon = RENDER_ICON("solid:folder-open")
icon = RENDER_ICON("brands:apple")
Tip: You do not need to include the ".svg" file suffix with the icon name; if necessary, the suffix will be automatically appended.
Keywords
BACKGROUND_COLOR
Set this keyword to a scalar integer containing the background color for the icon. This color should either be a hexadecimal number in the format 0xRRGGBB (where RR is the red value, GG is green , and BB is blue), or a three-element byte array [Red, Green, Blue]. By default, the background color is set to transparent and the resulting icon is an RGBA image with dimensions M x N x 4.
FOREGROUND_COLOR
Set this keyword to a scalar integer or three-element byte array containing the foreground color for the icon. This color should either be a hexadecimal number in the format 0xRRGGBB (where RR is the red value, GG is green , and BB is blue), or a three-element byte array [Red, Green, Blue]. The default foreground color is the "BUTTON_TEXT" color from the WIDGET_SYSTEM_COLORS structure. This color will be black (0x000000) when "light mode" is in effect, and off-white (0xD1D1D1) when "dark mode" is in effect.
HEIGHT
Set this keyword to an integer giving the desired height of the icon. The default is 16 pixels.
ROTATE_DIRECTION
Set this keyword to an integer giving the rotation direction, including both reflection and rotation (counterclockwise). Note that the reflection is performed first. Possible values are:
Note: The WIDTH and HEIGHT keywords specify the original height and width, before any rotation. For example, if you set WIDTH = 100, HEIGHT = 50, and ROTATE_DIRECTION = 1, then the result will have dimensions 50 x 100 x 3.
WIDTH
Set this keyword to an integer giving the desired width of the icon. The default is 16 pixels.
Version History
See Also
RENDER_SVG, SVG_ICON_BROWSER