Saq et al,
I love these semi-competitive focused coding task threads. I like to
generalise and simplify too,
As a result I seem to have identified that the new toggle operator and
parameters is not accepting this form (as in Saq's example)
text={{{[{$:/palette}toggle<lightPalette>,< darkPalette>] }}}/>
*Is this a bug, limitation or a restriction?*
*Although; this generalised toggle does work*
\define toggle-text(tiddler value1 value2)
<$button>Day/Night IV
<$action-setfield $tiddler="$tiddler$" text={{{ [[$tiddler$]get[text]]
+[toggle[$value1$],[$value2$]] }}}/>
</$button>
\end
<<toggle-text "$:/palette" "$:/palettes/Vanilla" "$:/palettes/SolarFlare" >>
Since the above is worthy of a reusable global macro placing the macro
definition in a tiddler tagged $:/tags/Macro
Then create a tiddler day-night containing;
<<toggle-text "$:/palette" "$:/palettes/Vanilla" "$:/palettes/SolarFlare"
>>
Then wherever you want the day night toggle just use
{{night-day}}
*Your comments please!*
This approach of mine is designed to capture functionality in a way it is
very easy to use.
- I would invite my coding companions to consider the development of
some de facto standards
- The find a way to easily package it to other to acquire it (I have
some already)
- For a complete solution I would look at displaying the button as a
icon that changes color eg red/green
Regards
Tones
On Tuesday, 15 December 2020 at 20:09:55 UTC+11 [email protected] wrote:
> @Mohammad yes the toggle operator is best used with list fields.
>
> You can further simplify and skip the list widget:
>
> <$vars
> lightPalette="$:/palettes/Vanilla"
> darkPalette="$:/palettes/SolarFlare"
> >
> <$button>Day/Night II
> <$action-setfield $tiddler="$:/palette"
> text={{{[{$:/palette}match<lightPalette>then<darkPalette>else<lightPalette>]}}}/>
> </$button>
> </$vars>
>
> On Tuesday, December 15, 2020 at 9:59:11 AM UTC+1 Mohammad wrote:
>
>> It seems in this case there are other simple solutions too, while in my
>> opinion toggle is the most semantic one but in its current implementation
>> is tricky to use for toggling a field can be changed outside the script.
>>
>> These are other solutions that do not use toggle but very simple. Of
>> course simple is the best but not simpler.
>>
>> *!! Simple solution*
>>
>> <$button>Day/Night
>> <$list
>> filter="[{$:/palette}match[$:/palettes/Vanilla]then[$:/palettes/SolarFlare]else[$:/palettes/Vanilla]]">
>> <$action-setfield $tiddler="$:/palette" text=<<currentTiddler>>/>
>> </$list>
>> </$button>
>>
>>
>> *!! Good practice*
>>
>> <$vars
>> lightPalette="$:/palettes/Vanilla"
>> darkPalette="$:/palettes/SolarFlare"
>> >
>> <$button>Day/Night II
>> <$list
>> filter="[{$:/palette}match<lightPalette>then<darkPalette>else<lightPalette>]"
>>
>> variable=selectedPalette>
>> <$action-setfield $tiddler="$:/palette" text=<<selectedPalette>>/>
>> </$list>
>> </$button>
>> </$vars>
>>
>>
>> You may read *darkPalette *and *lightPalete *from a config tiddler
>> fields.
>>
>> Best wishes
>> Mohammad
>>
>>
>> On Mon, Dec 14, 2020 at 4:14 PM Mohammad Rahmani <[email protected]>
>> wrote:
>>
>>> I use the below button to toggle between day/night palette
>>>
>>> <$button>Day/Night
>>> <$action-listops $tiddler="$:/palette" $field="text"
>>> $subfilter="+[toggle[$:/palettes/Vanilla],[$:/palettes/SolarFlare]]" />
>>> </$button>
>>>
>>> The problem here is if $:/palette is not empty and has not one of the
>>> two values above, then I get the wrong values in the text field (actually
>>> the value is appended). How can I replace the field value using toggle
>>> operator.
>>>
>>>
>>>
>>> Best wishes
>>> Mohammad
>>>
>>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/bb4eb1f6-0c9d-4346-80eb-af4c90c3ca4bn%40googlegroups.com.