Icons

class Icons(val resources: Resources) : NamedImages

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 ImageViews, not Images.

Constructors

Link copied to clipboard
constructor(resources: Resources)

Types

Link copied to clipboard
Link copied to clipboard
inner class SizedIcons(val size: Int) : NamedImages

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun add(iconSheet: IconSheet)
Link copied to clipboard
open operator override fun get(name: String): Image?

Returns an Image with the given name at the default size.

open override fun get(name: String, size: Int): Image?

Returns an Image with the given name at the requested size.

Link copied to clipboard
fun names(): List<String>
Link copied to clipboard

If you want the icon size to be user definable, then create an IntProperty for the preferred size. And use it like so :

Link copied to clipboard
open override fun resizableNamedImages(sizeProperty: IntProperty): Icons.ResizableIcons

Returns another view of the same named images, with an additional feature : See ResizableNamedImages.getResizable.

Link copied to clipboard
fun Icons.sheets(block: Sheets.() -> Unit)
Link copied to clipboard

Allows easy access to images of a given size. Example usage :

Link copied to clipboard
fun Icons.texture(textureName: String, size: Int, block: IconSheet.() -> Unit)
Link copied to clipboard
open override fun toString(): String