Include with Substitution
Rainmeter skins often have repeated sections of code corresponding to repeated instances of a given object. A "Disk Drive" skin will have one or more instances of a disk drive, while a "Stock Quote" skin will have one or more instances of a stock quote. Using the stock quote skin as an example, a skin I have developed has a series of measures and meters that looks something like this:
Code: Select all
[measureNameStock1]
...
[measurePriceStock1]
...
[measureChangeStock1]
...
[meterNameStock1]
...
[meterPriceStock1]
...
[meterChangeStock1]
...
Code: Select all
@IncludeS1=stock1.inc
@IncludeS2=stock2.inc
@IncludeS3=stock3.inc
Code: Select all
[measureNameStock$num$]
...
[measurePriceStock$num$]
...
[measureChangeStock$num$]
...
[meterNameStock$num$]
...
[meterPriceStock$num$]
...
[meterChangeStock$num$]
...
It occured to me that the use of a master include could be formalized with an enhancement to the Include syntax. For example, since Rainmeter already has a "Substitute" capability, we might have:
Code: Select all
@IncludeS1=stock.inc Substitute="$num$":"1"
@IncludeS2=stock.inc Substitute="$num$":"2"
@IncludeS3=stock.inc Substitute="$num$":"3"
Conditional Include
A common feature of skins that make use of repeated measures and meters is the need to conditionally enable or disable them. For example, if the stock skin discussed above can support 9 stocks, but a given user only wants to display 3 stocks, a common technique seems to be to code for 9 stocks, then selectively disable or hide their measures and meters.
For a skin that changes the number of display objects dynamically, disable/hide seems like the way to go. But for other skins, a conditional include mechanism could simplify the code by dispensing with the disables/hides:
Code: Select all
[Variables]
stockCount=3
symbol1=AAPL
symbol2=GOOG
symbol3=MSFT
...
@IncludeS1=stock.inc IncludeIf=(#stockCount# >= 1) Substitute="$num$":"1"
@IncludeS2=stock.inc IncludeIf=(#stockCount# >= 2) Substitute="$num$":"2"
@IncludeS3=stock.inc IncludeIf=(#stockCount# >= 3) Substitute="$num$":"3"
@IncludeS4=stock.inc IncludeIf=(#stockCount# >= 4) Substitute="$num$":"4"
@IncludeS5=stock.inc IncludeIf=(#stockCount# >= 5) Substitute="$num$":"5"
@IncludeS6=stock.inc IncludeIf=(#stockCount# >= 6) Substitute="$num$":"6"
@IncludeS7=stock.inc IncludeIf=(#stockCount# >= 7) Substitute="$num$":"7"
@IncludeS8=stock.inc IncludeIf=(#stockCount# >= 8) Substitute="$num$":"8"
@IncludeS9=stock.inc IncludeIf=(#stockCount# >= 9) Substitute="$num$":"9"
I am undecided about the sugguestions I have just made. I am wary of encumbering Rainmeter's syntax, and complex substitutions or overuse of includes could make understanding a skin much more difficult. For now, I lean toward suggesting the include enhancements described here. I'd be curious to know if other skin developers have found alternate solutions to the issues I have discussed.
--buckb