Icons
Loads icons from Resources, where a single .png
file contains many icons. These icons should have a gap between them, to prevent bleeding from one icon into its neighbours. You give a name to each icon, via a DSL (domain specific language).
You may optionally supply multiple .png
files, at various resolutions. Icons can be requested at any size, and scaling is used if there isn't a .png
file for that particular resolution.
The names and positions of icons within the .png
file are defined like so :
myIcons = icons( myResources ) {
texture( "foo64.png", 64 ) {
row( "file_", 2, 2, 1, "save", "save_as", "open" )
row( "edit_", 2, 68, 1, "copy", "cut", "paste" )
}
}
The above only uses 1 resolution (64x64 pixels). The row
method takes an optional prefix
(in this case file_
and edit_
) as well as the start of the row (2,2) and (2,68), and the column spacing (1). The net results are 6 named icons file_save
, file_save_as
etc.
To get a full-size
icon :
myIcons[ "file_save" ]
To get a smaller icons either :
myIcons.get( "file_save", 32 )
val smallIcons = myIcons.size(32)
smallIcons[ "file_save" ]
There's also a clever feature, which allows all of your icons to scale automatically using an IntProperty :
val iconSizeProperty = SimpleIntProperty( 32 )
val buttonIcons = myIcons.resizableIcons( iconSizeProperty )
fileSaveButton.graphic = buttonIcons[ "file_save" ]
fileSaveAsButton.graphic = buttonIcons[ "file_save_as" ]
If we now change iconsSizeProperty
, all button icons will update. Notice that buttonIcons
return ImageView
s, not Image
s.
Functions
If you want the icon size to be user definable, then create an IntProperty for the preferred size. And use it like so :
Returns another view of the same named images, with an additional feature : See ResizableNamedImages.getResizable.
Allows easy access to images of a given size. Example usage :