ID:2386993
 
(See the best response by Lummox JR.)
Code:
proc/SWITCH(mob/M, var/Title, var/Text = "", var/Options = list(), var/Fade = 0, var/CloseOnFade = 0)
if(winget(M, "Switch", "is-visible") == "true") return

//Clean up the interface and write the text//
M << output(null, "Switch.grid1");M.List.Cut() //Clear grid, and clear the list.
winset(M,"Switch.Title", "text = '[Title]'")
winset(M, "Switch.grid1", "cells = 0x0") // Another way of clearing the grid...
winset(M,"Switch.grid1","style='body{background-color:#FF0000;}'") //Make sure the cells are not highlighted.
winset(M,"Switch.Text","text = '[Text]'") // Add the text
winset(M, "Switch.grid1", "cells = 1x[length(Options)]") // Create the right number of cells based on the number of options.
/////Lets start adding the options///////////

for(var/a in Options)
var/Option/O = new ; O.name = "[a]"
M.List.Add(O)
for(var/Z in M.List)
M << output("<font color = red>[Z]</font>","Switch.grid1:1,[M.List.Find(Z)]")


Problem description:I'm making some modifications to Kidpaddle45's Interface library to better fit my game's concept. I can't seem to get the text color of the options that populate within grid1 to change, neither through the skin file nor code. This current futile attempt actually just colors in the whole box area for the option as red. What am I doing wrong, and what is the best way to achieve a color change for var/Z?




A few things worth mentioning:

1) You don't need the "var" keyword in proc arguments. It's doing nothing. Get rid of it.

2) In HTML, never put a space around the = for an attribute. It just isn't done.

3) The M.List.Find() call is totally wrong. Instead, use a local var as a counter and increment it with each item in the list.

4) It makes no sense to have two loops: one to fill the list and one to fill the grid. Those should be the same loop.
In response to Lummox JR
Lummox JR wrote:
A few things worth mentioning:

1) You don't need the "var" keyword in proc arguments. It's doing nothing. Get rid of it.

2) In HTML, never put a space around the = for an attribute. It just isn't done.

3) The M.List.Find() call is totally wrong. Instead, use a local var as a counter and increment it with each item in the list.

4) It makes no sense to have two loops: one to fill the list and one to fill the grid. Those should be the same loop.

Hey, Lummox, thanks for taking the time to respond. I'm not great at familiarizing myself with other's code, though I have been trying. I was hoping to just be able to use it as a libary without making many adjustments. That said, it seems there's some cleaning up to do.

1) I've cleaned up the unnecessary var keywords.

2) Noted, this is a habit I do in coding. Is it frowned upon there as well?

3 & 4)

Here's the solution I've come up with to clean it up a bit:

    var/i   
for(var/a in Options)
i ++
var/Option/O = new; O.name = "[a]"
M.List.Add(O)
M << output("<font color=red>[O]</font>", "Switch.grid1:1, [i]")


Not sure if it's the most efficient solution, but I think it addresses what you're talking about. Now changing the font color seems to work, but it makes the options un-clickable. I understand why, or at least I think I do. Originally, the argument was passed as simply O, but in trying to add color, I start passing it as a text string instead. What would be a way to change the color and be able to click it?

Best response
You could try outputting a new style to the control just before doing the output, and then change the style back to "normal" after the output is all done. Changing text-color rather than style might be an easier option.