Skip to content

Instantly share code, notes, and snippets.

@samthecodingman
Last active March 30, 2022 21:56
Show Gist options
  • Save samthecodingman/44e58a47a0b2d07c8553f036285f5c4b to your computer and use it in GitHub Desktop.
Save samthecodingman/44e58a47a0b2d07c8553f036285f5c4b to your computer and use it in GitHub Desktop.
Working AutoHotkey Example - Shaded Icons in a ListView: Demonstrates the use of icons in a ListView to show shading for a row
; [DEMO] Shaded Icons in a ListView
; Description: Demonstrates the use of icons in a ListView to show shading for a row
; Author: Samuel Jones (@samthecodingman)
; Created: 21 NOV 2018
; Last-Modified: 21 NOV 2018
; License: MIT (https://opensource.org/licenses/MIT)
; URL: https://gist.github.com/samthecodingman/44e58a47a0b2d07c8553f036285f5c4b
; Requires AHK v1.0.46 or later. Demo itself not compatible with AHK v2, but concept is.
#SingleInstance force
; Change below to GetScaleImageList("scale-circ.icl"), etc to change icon variant
SCALE_IMAGE_LIST := GetScaleImageList()
Gui, Add, ListView, vMainLV h400 w300 HScroll, |Position|Value
Gui, Show,, ListView with shades
LV_SetImageList(SCALE_IMAGE_LIST) ; attach images to ListView
; Show each of the shades
Loop 6
{
v := (A_Index - 1) * 0.2 ; 0, 0.2, 0.4, ... etc
LV_Add("Icon" . GetScaleIndex(v), "", A_Index, v) ; NOTE: Skip first value to have an icon-only column
}
; Show a blank line
; if # in "Icon#" is bigger than the image list (in this case, 6), no icon will be shown
LV_Add("Icon7", "", "--", "--")
; Show the shades in use
Loop 10
{
Random, r , 0.0, 1.0 ; random float between 0 and 1.
LV_Add("Icon" . GetScaleIndex(r), "", A_Index, r)
}
Return
GuiClose:
GuiEscape:
ExitApp
; Copy below code to your project.
; +-----------------------------------+
; | SCALE ICON FUNCTIONS |
; +-----------------------------------+
; By Samuel Jones <@samthecodingman> [MIT License]
; Note: You can get "scale.icl" variants from the Gist
; URL: https://gist.github.com/samthecodingman/44e58a47a0b2d07c8553f036285f5c4b
; Contents of "scale.icl" file
; color: red green
; index: 1-->|---2-->|---3-->|---4-->|---5-->|---6
; value: 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
; [FUNCTION] Gets an index corresponding to a shade in "scale.icl"
; v - a 0..1 value to be mapped to an index
GetScaleIndex(v) {
if (v < 0.5)
return v < 0.1 ? 1 : (v < 0.3 ? 2 : 3)
else
return v < 0.7 ? 4 : (v < 0.9 ? 5 : 6)
}
; [FUNCTION] Initializes an ImageList with the shades in "scale.icl"
; aFilepath - alternate image lib file path
GetScaleImageList(aFilepath:="") {
if (not aFilepath)
aFilepath := A_ScriptDir . "\scale.icl"
_il := IL_Create(6)
Loop 6
IL_Add(_il, aFilepath, A_Index)
return _il
}
@samthecodingman
Copy link
Author

If you want to create your own "scale.icl" files, you can make use of these awesome programs:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment