It is currently March 19th, 2024, 8:57 am

Working with InputText

Our most popular Tips and Tricks from the Rainmeter Team and others
User avatar
jsmorley
Developer
Posts: 22632
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Working with InputText

Post by jsmorley »

Yamajac wrote: December 5th, 2019, 9:38 pm I haven't looked into it but doesn't the inputtext plugin store the last value it had, so you'd be able to do IfMatch just right on the input textplugin instead?
The problem is that you have to use the $UserInput$ macro in the context of a bang, or it is just "executed". I really need to use !SetOption, since you can't use IfMatch on [Variables], so since I am setting the String measure anyway, might as well do the test there.
User avatar
jsmorley
Developer
Posts: 22632
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Working with InputText

Post by jsmorley »

Actually, I like this better...

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
MyVar=Starting Value

[MeterSearchBox]
Meter=Shape
Shape=Rectangle 1,1,202,25 | Fill Color 215,215,215,255 | Stroke Color 130,130,130,255
W=202
H=25

[MeterSearchLabel]
Meter=String
X=5
Y=5
W=200
H=23
SolidColor=0,0,0,1
FontColor=47,47,47,255
FontSize=12
AntiAlias=1
DynamicVariables=1
StringCase=Upper
Text=#MyVar#
LeftMouseUpAction=[!EnableMeasure MeasureInput][!CommandMeasure "MeasureInput" "ExecuteBatch 1"]

[MeasureInput]
Measure=Plugin
Plugin=InputText
X=5
Y=3
W=197
H=21
SolidColor=200,200,200,255
FontColor=47,47,47,255
FontSize=11
AntiAlias=1
FocusDismiss=1
DynamicVariables=1
Disabled=1
UpdateDivider=-1
IfMatchMode=1
IfMatch=(?i)^jsmorley$|^pul53dr1v3r$|^$
IfMatchAction=[Play error]
IfNotMatchAction=[!SetVariable MyVar "[MeasureInput]"]
Command1=[!SetVariable RawInput "$UserInput$"][!UpdateMeasure MeasureInput]
It's pretty much exactly what I started with, but instead of just using [$UserInput$] in the Command1 option, which would be executed, I just use the macro in the context of a !SetVariable bang that really doesn't do anything but throw the raw input value into a variable that is never used. At the same time the value of [MeasureInput] will be set to the string the user input, and that can be tested right there and then.

I also added IfMatchMode=1, so it doesn't require the test to change from "true" to "false", and added |^$ as another excluded string, so if they hit enter without typing anything, that is ignored.

In any case, now inputting "en-US" does not open the language folder...
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Working with InputText

Post by pul53dr1v3r »

sorry for the confusion. i'm guilty because i sometimes don't think with my head. :Whistle

Thank you Morley for the solution, it does just the job. i've used the last one. :rosegift:
Thank you ET too and sorry for my, probably a bit rough reply. :rosegift:
I deserve :x at best.
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Working with InputText

Post by pul53dr1v3r »

How to get rid of showing a part of CommandN code in a text field when there is no value entered in it?

For instance, i have this case:

Code: Select all

[MeasureInputTxt1]
Measure=Plugin
Plugin=InputText
FontSize=10
InputNumber=1
InputLimit=2
FocusDismiss=1
FontColor=255,255,255
SolidColor=50,50,50
X=10
Y=10
W=10
H=10
DynamicVariables=1
DefaultValue=#MeterInputTxt1#
Command1=[!WriteKeyValue Variables MeterInputTxt1 "(Clamp($UserInput$,1,10))" "#@#Variables.inc"]
Command2=[!RefreshGroup "Group1"]

[MeterInputField1]
Meter=Shape
X=10
Y=10
MeterStyle=StyleInputBox
LeftMouseUpAction=[!CommandMeasure MeasureInputTxt1 "ExecuteBatch 1-2"]

[MeterInputTxt1]
Meter=String
MeterStyle=StyleInputTxt
Text=#MeterInputTxt1#
So, the Clamp option is used to limit input number range, but when the MeterInputTxt1 variable is empty, i get (Clamp(,1,10)) in the field.
User avatar
Active Colors
Moderator
Posts: 1250
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany
Contact:

Re: Working with InputText

Post by Active Colors »

pul53dr1v3r wrote: February 15th, 2021, 12:10 pm How to get rid of showing a part of CommandN code in a text field when there is no value entered in it?

For instance, i have this case:

Code: Select all

[MeasureInputTxt1]
Measure=Plugin
Plugin=InputText
FontSize=10
InputNumber=1
InputLimit=2
FocusDismiss=1
FontColor=255,255,255
SolidColor=50,50,50
X=10
Y=10
W=10
H=10
DynamicVariables=1
DefaultValue=#MeterInputTxt1#
Command1=[!WriteKeyValue Variables MeterInputTxt1 "(Clamp($UserInput$,1,10))" "#@#Variables.inc"]
Command2=[!RefreshGroup "Group1"]

[MeterInputField1]
Meter=Shape
X=10
Y=10
MeterStyle=StyleInputBox
LeftMouseUpAction=[!CommandMeasure MeasureInputTxt1 "ExecuteBatch 1-2"]

[MeterInputTxt1]
Meter=String
MeterStyle=StyleInputTxt
Text=#MeterInputTxt1#
So, the Clamp option is used to limit input number range, but when the MeterInputTxt1 variable is empty, i get (Clamp(,1,10)) in the field.
This way it is treating it as a part of the string and this is how it works in many places https://docs.rainmeter.net/manual-beta/formulas/.
Before writing your value to Variables you can !SetVariable YourValueToBeClamped and run a measure to clamp it and the result to write further. It is some extra steps but it is not that hard I think.
User avatar
balala
Rainmeter Sage
Posts: 16091
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Working with InputText

Post by balala »

pul53dr1v3r wrote: February 15th, 2021, 12:10 pm So, the Clamp option is used to limit input number range, but when the MeterInputTxt1 variable is empty, i get (Clamp(,1,10)) in the field.
As Active Colors said, you have to add a Calc measure, something like this:

Code: Select all

[MeasureMyLimit]
Measure=Calc
Formula=#MeterInputTxt1#
RegExpSubstitute=1
Substitute="^$":"0"
OnChangeAction=[!WriteKeyValue Variables MeterInputTxt1 "(Clamp([MeasureMyLimit],1,10))" "#@#Variables.inc"]
DynamicVariables=1
UpdateDivider=-1
As you can see, the MeterInputTxt1 variable isn't written directly by the Command1 option of the [MeasureInputTxt1] measure, but by the OnChangeAction option of the above [MeasureMyLimit] measure. In order to get this properly working replace the above Command1 option with the following one: Command1=[!SetVariable MeterInputTxt1 "$UserInput$"][!UpdateMeasure "MeasureMyLimit"].
This way, if you're entering an empty string, you get written 1 (the lower limit of the Clamp function).
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Working with InputText

Post by pul53dr1v3r »

@ AC, Balala

yes, it does the job but... an additional measure. I feel like there is a plugin option to prevent this from happening. :???:

Thanks for the solution.
User avatar
balala
Rainmeter Sage
Posts: 16091
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Working with InputText

Post by balala »

pul53dr1v3r wrote: February 15th, 2021, 5:43 pm yes, it does the job but... an additional measure. I feel like there is a plugin option to prevent this from happening. :???:
No, I doubt there would be. This is how you have to do this, I don't see another way.
User avatar
Active Colors
Moderator
Posts: 1250
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany
Contact:

Re: Working with InputText

Post by Active Colors »

pul53dr1v3r wrote: February 15th, 2021, 5:43 pm @ AC, Balala

yes, it does the job but... an additional measure. I feel like there is a plugin option to prevent this from happening. :???:

Thanks for the solution.
I agree with balala's statement above but just in case you don't need to have extra measure per each of your input element. I don't know how many of those you have but considering the form MeasureInputTxt1 I guess there are more alike input elements. You just need to have only one such measure for the entire skin. Just pass your value from any input to the measure like balala explained. If you need any further help let us know.
User avatar
pul53dr1v3r
Posts: 442
Joined: July 30th, 2014, 10:30 am

Re: Working with InputText

Post by pul53dr1v3r »

i just had in my mind a plugin option to set a minimal number of characters in an input text measure as leaving it empty can cause errors in certain cases, especially where numeric values are required. Adding additional measure for every InputText measure could be a headache for those who use the plugin. The option should return the last entered value if the number of entered characters is less than the determined with the option.
If InputLimit option (for max number of characters) is necessary, why not to add this one? Can't InputLimit be achieved without the option? It can, but that's much easier way for many users, less code, resource usage...

Just a suggestion for devs with a BIG thanks for all the work up to now!
Post Reply