kaigou: this is what I do, darling (Default)
锴 angry fishtrap 狗 ([personal profile] kaigou) wrote in [community profile] style_system2009-11-17 11:37 am

style system variables

Is it possible to set a variable to be another variable?

That is, instead of:

set color_thing = "#333366";

doing:

set color_thing = $*some_other_thing;

such that the default value of $*color_thing is equal to the value of $*some_other_thing, but with option for user to override?
zvi: self-portrait: short, fat, black dyke in bunny slippers (Default)

[personal profile] zvi 2009-11-17 05:47 pm (UTC)(link)
Yes, at the theme level, you can do that.
branchandroot: oak against sky (Default)

[personal profile] branchandroot 2009-11-17 06:39 pm (UTC)(link)
Right inside your print_stylesheet function, you should be able to require that variable x equal variable y. But that would screw with the ability of the user to select something totally different if that's what floats their boat. So I guess either you want to frame your x=y statement in such a way that if the values are changed they decouple, or else just set both variables to the same thing up in the settables list. *rueful* I usually go with the latter, despite it being longhand, as it were.
zvi: self-portrait: short, fat, black dyke in bunny slippers (Default)

[personal profile] zvi 2009-11-17 06:42 pm (UTC)(link)
Hmm. Oh, you know, I've never actually tried to do it as a straight substitution. I've always done it through CSS, and you don't get the user over-riding them being connected that way.

thing-x { color: $*color-thing-y; }

Sorry for not thinking it through.

Um, I don't think you can temporarily define functions in themes? I know that you can create variables inside the print stylesheet functions, though. I don't know exactly how it's done, alas.
zvi: self-portrait: short, fat, black dyke in bunny slippers (Default)

[personal profile] zvi 2009-11-17 08:29 pm (UTC)(link)
Yes, that's true.

The thing that I don't think you can do, which I think you want to do, is say set this_value=y and in a function, set user_controlled_value=this_value

And then have there be an effect when the user changes the user_controlled_value through the wizard. I could be wrong about that, though.
afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)

[personal profile] afuna 2009-11-18 02:36 am (UTC)(link)
You can set properties to other properties on prop_init, but I'm not sure about the particular scenario you're proposing, since usually what we do is check whether $*Y has been set; if it has, we use the user-defined value. If it hasn't, we use the fallback value. So something like this:

layout:
property Color X { des = "base value" }
property Color Y { des = "falls back on base value if not provided" }
set X = "blue"
set Y = ""


function prop_init() {
    if ( $*Y == "" or not defined $*Y ) {
        # Y has no value, let's fill it in 
        $*Y = $*X
    }
}