Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 752

Community Tips & Tricks • Handling Empty InputText

$
0
0
I was looking for an answer to this some time ago and didn't find anything, so here's my solution.

The problem:
When we use the InputText plugin to allow the user to enter some value, it is possible that the user mistakenly/knowingly leaves it empty and hits enter. What happens is that the meter that displays that value will disappear, making any other meter which position is relative to that meter move.

Example: In the next code, we have a shape meter and 2 string meters, one called title and another subtitle. You can enter a Title and a subtitle by clicking them, typing and then hitting enter.

Code:

[Rainmeter]Update=-1AccurateText=1[Variables]Title=TitleSubtitle=Subtitle[TextStyle]FontColor=255,255,255AntiAlias=1StringAlign=CenterX=([BG:W]/2)Y=10RW=100DynamicVariables=1LeftMouseUpAction=!CommandMeasure "m#CurrentSection#" "ExecuteBatch 1-2"[mTitle]Measure=PluginPlugin=InputTextStringAlign=CenterInputLimit=0InputNumber=0X=([Title:X])Y=[Title:Y]W=100H=[Title:H]FontSize=15Command1=[!SetVariable Title "$UserInput$"][!WriteKeyValue Variables Title "[#CurrentSection#]"][!Update][!Redraw]DefaultValue=#Title#[mSubtitle]Measure=PluginPlugin=InputTextStringAlign=CenterInputLimit=0InputNumber=0X=([Subtitle:X])Y=[Subtitle:Y]W=100H=[Subtitle:H]FontSize=10Command1=[!SetVariable Subtitle "$UserInput$"][!WriteKeyValue Variables Subtitle "[#CurrentSection#]"][!Update][!Redraw]DefaultValue=#Subtitle#[BG]Meter=ShapeShape=Rectangle 0,0,100,70 | Fill Color 0,0,0[Title]MeterStyle=TextStyleMeter=StringFontSize=15Text=#Title#Y=10[Subtitle]Meter=StringMeterStyle=TextStyleFontSize=10Text=#Subtitle#
This works great, but if you leave Title empty and hit enter, Tittle will disappear and Subtitle will move up.
ezgif.com-video-to-gif-converter (1).gif
To avoid this we can use substitute.
We just add Substitute="":"DefaultValue" to the InputText measures. Not that easy tho, if you only do that, nothing will change, because we don't use the value of the measure to set the variable, only to write it, we use $UserInput$ to set the variable. It would only go back to the default value after a refresh. To fix it, we'll add another SetVariable bang like this:

Before:
[!SetVariable Subtitle "$UserInput$"][!WriteKeyValue Variables Subtitle "[#CurrentSection#]"][!Update][!Redraw]

After:
[!SetVariable Subtitle "$UserInput$"][!SetVariable Subtitle "[#CurrentSection#]"][!WriteKeyValue Variables Subtitle "[#CurrentSection#]"][!Update][!Redraw]

This will overwrite the $UserInput$ value with the value of the measure with our substitution (If we don't use $UserInput$ at all the Plugin won't work).

So now, after adding those changes to both measures our code looks like this:

Code:

[Rainmeter]Update=-1AccurateText=1[Variables]Title=TitleSubtitle=Subtitle[TextStyle]FontColor=255,255,255AntiAlias=1StringAlign=CenterX=([BG:W]/2)Y=10RW=100DynamicVariables=1LeftMouseUpAction=!CommandMeasure "m#CurrentSection#" "ExecuteBatch 1-2"[mTitle]Measure=PluginPlugin=InputTextSubstitute="":"Title"StringAlign=CenterInputLimit=0InputNumber=0X=([Title:X])Y=[Title:Y]W=100H=[Title:H]FontSize=15Command1=[!SetVariable Title "$UserInput$"][!SetVariable Title "[#CurrentSection#]"][!WriteKeyValue Variables Title "[#CurrentSection#]"][!Update][!Redraw]DefaultValue=#Title#[mSubtitle]Measure=PluginPlugin=InputTextSubstitute="":"Subtitle"StringAlign=CenterInputLimit=0InputNumber=0X=([Subtitle:X])Y=[Subtitle:Y]W=100H=[Subtitle:H]FontSize=10Command1=[!SetVariable Subtitle "$UserInput$"][!SetVariable Subtitle "[#CurrentSection#]"][!WriteKeyValue Variables Subtitle "[#CurrentSection#]"][!Update][!Redraw]DefaultValue=#Subtitle#[BG]Meter=ShapeShape=Rectangle 0,0,100,70 | Fill Color 0,0,0[Title]MeterStyle=TextStyleMeter=StringFontSize=15Text=#Title#Y=10[Subtitle]Meter=StringMeterStyle=TextStyleFontSize=10Text=#Subtitle#
And done, now when we leave them empty, the values return to our set default values, in this case, "Title" and "Subtitle".
ezgif.com-video-to-gif-converter (2).gif
Any other workaround is welcomed.

Statistics: Posted by RicardoTM — Today, 12:10 am — Replies 0 — Views 14



Viewing all articles
Browse latest Browse all 752

Trending Articles