A little app to display wNim commonly used colors…. forgive any bad code, I only started learning Nim a month back so feel free to change it, make it better etc :-)
# Displays a window with all the commonly used wColor constants # Its only been designed for full screen (1920 x 1080) use, it will not resize if the window is minimised. # import wNim type PanelSize = tuple[width: int, height: int] # # # How the data is stored in the following sequence: # 1. the wColor constant... this will be converted to the colours number when read using a for/in loop, this number is used for the panels variable name (see 3. # below for notes of why i named the panels this way) and also read again seperately to colour the panels background # 2. the wColor constant as a string... used for the text of a StaticText control which is displayed on the panel # 3. a number used as the variable name for the StaticText control... any number can be used so long as its not the same as a wColor number, the reason # i used this way is because the panels that display the wColors as a background and the StaticText controls are created on the fly and this is the only # way i could find of creating variable names for them while in the middle of a for/in loop. # NOTE: Numbers used for StaticText variable names must be higher than 16777215 (which is the highest number used by the value of a colour constant when its converted) # IMPORTANT: we could also use DISCARD when creating the controls rather than storing them in a variable, however that will prevent you accessing them if needs be.... anyway here is a line showing how to use discard when # creating the StaticText controls, if you do go down this route then you also need to remove any lines # that try to access or change the StaticText and you can get rid of the number used # for the StaticTexts name in the sequence below... # # discard StaticText(colorConst, label=(colorsTest[i][1])) # # let colorsTest = @[(wAquamarine, "wAquamarine", 16777216), (wBlack, "wBlack", 16777217), (wBlue, "wBlue", 16777218), (wBlueViolet, "wBlueViolet", 16777219), (wBrown, "wBrown", 16777220), (wCadetBlue, "wCadetBlue", 16777221), (wCoral, "wCoral", 16777222), (wCornflowerBlue, "wCornflowerBlue", 16777223), (wCyan, "wCyan", 16777224), (wDarkGreen, "wDarkGreen", 16777225), (wDarkGrey, "wDarkGrey", 16777226), (wDarkOliveGreen, "wDarkOliveGreen", 16777227), (wDarkOrchid, "wDarkOrchid", 16777228), (wDarkSlateBlue, "wDarkSlateBlue", 16777229), (wDarkSlateGrey, "wDarkSlateGrey", 16777230), (wDarkTurquoise, "wDarkTurquoise", 16777231), (wDimGrey, "wDimGrey", 16777232), (wFireBrick, "wFireBrick", 16777233), (wForestGreen, "wForestGreen", 16777234), (wGold, "wGold", 16777235), (wGoldenrod, "wGoldenrod", 16777236), (wGreen, "wGreen", 16777237), (wGreenYellow, "wGreenYellow", 16777238), (wGrey, "wGrey", 16777239), (wIndianRed, "wIndianRed", 16777240), (wKhaki, "wKhaki", 16777241), (wLightBlue, "wLightBlue", 16777242), (wLightGrey, "wLightGrey", 16777243), (wLightMagenta, "wLightMagenta", 16777244), (wLightSteelBlue, "wLightSteelBlue", 16777245), (wLimeGreen, "wLimeGreen", 16777246), (wMagenta, "wMagenta", 16777247), (wMaroon, "wMaroon", 16777248), (wMediumAquamarine, "wMediumAquamarine", 16777249), (wMediumBlue, "wMediumBlue", 16777250), (wMediumForestGreen, "wMediumForestGreen", 16777251), (wMediumGoldenrod, "wMediumGoldenrod", 16777252), (wMediumGrey, "wMediumGrey", 16777253), (wMediumOrchid, "wMediumOrchid", 16777254), (wMediumSeaGreen, "wMediumSeaGreen", 16777255), (wMediumSlateBlue, "wMediumSlateBlue", 16777256), (wMediumSpringGreen, "wMediumSpringGreen", 16777257), (wMediumTurquoise, "wMediumTurquoise", 16777258), (wMediumVioletRed, "wMediumVioletRed", 16777259), (wMidnightBlue, "wMidnightBlue", 16777260), (wNavy, "wNavy", 16777261), (wOrange, "wOrange", 16777262), (wOrangeRed, "wOrangeRed", 16777263), (wOrchid, "wOrchid", 16777264), (wPaleGreen, "wPaleGreen", 16777265), (wPink, "wPink", 16777266), (wPlum, "wPlum", 16777267), (wPurple, "wPurple", 16777268), (wRed, "wRed", 16777269), (wSalmon, "wSalmon", 16777270), (wSeaGreen, "wSeaGreen", 16777271), (wSienna, "wSienna", 16777272), (wSkyBlue, "wSkyBlue", 16777273), (wSlateBlue, "wSlateBlue", 16777274), (wSpringGreen, "wSpringGreen", 16777275), (wSteelBlue, "wSteelBlue", 16777276), (wTan, "wTan", 16777277), (wThistle, "wThistle", 16777278), (wTurquoise, "wTurquoise", 16777279), (wViolet, "wViolet", 16777281), (wVioletRed, "wVioletRed", 16777282), (wWheat, "wWheat", 16777283), (wWhite, "wWhite", 16777284), (wYellow, "wYellow", 16777285), (wYellowGreen, "wYellowGreen", 16777286)] # # create a panelSize object that will simply hold the default size of each panel used to display # a color... var panelSize: PanelSize panelSize = (width: 300, height: 80) # var app = App() # I havent specified a frame size param (like this: size=(900, 400)) in the style here because the # frame is maximised after its shown.. var frame = Frame(title="wNim - Commonly Used Color Constants") frame.center() frame.show() # Maximize will only work after the frame has been shown.. frame.maximize() # # Work out the maximum panels we can get across the screen.. let maxAcross = frame.getClientSize().width div panelSize.width # # This for loop is what does all the displaying...it creates a new panel that has its background set to the wColor, and adds a StaticText control to the panel var acrossCounter = 0 for i, (colorConst, colorString, staticTextVar) in colorsTest: # var colorConst = Panel(frame, size=panelSize, pos=((acrossCounter * panelSize.width), ((i div maxAcross) * panelSize.height + 10) )) acrossCounter = acrossCounter + 1 if acrossCounter == maxAcross: acrossCounter = 0 var staticTextVar = StaticText(colorConst, label=(colorsTest[i][1])) colorConst.setBackgroundColor(colorsTest[i][0]) # # # # app.mainLoop