It is currently April 16th, 2024, 1:01 pm

[Feature] InputText Character Limit!

Report bugs with the Rainmeter application and suggest features.
User avatar
JosephB2000
Posts: 155
Joined: July 29th, 2014, 7:02 pm

[Feature] InputText Character Limit!

Post by JosephB2000 »

I have come across many times where I have needed a character (letter/number) limit on an InputText measure, for example, an InputText that allows the user to change the type of drive they want to use.

The CharacterLimit would limit the amount of text you are able to put by a specific number. An OnLimitAction could also be introduced, in case the skin creator wanted the Measure to perform an action once you reached the Limit.

Maybe the features could look something like this:

Code: Select all

[MeasureInputText]
Measure=Plugin
Plugin=InputText
.
.
CharacterLimit=1
OnLimitAction=[!Refresh]
Notice the '1' on the CharacterLimit option. This means the Measure only allows one character to be typed in.

The OnLimitAction would be useful if you want the Measure to refresh the skin when the limit is reached, or to show a string meter that displays "No more letters can be typed".

If this is possible, please implement something similar in the next update. I am sure many fellow skin creators would back me up with this one!
[Insert Joke Here]
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [Feature] InputText Character Limit!

Post by jsmorley »

I would be ok with the CharacterLimit option, as that makes a lot of sense. I'm not sure when this can be implemented, as the guy who wrote the plugin in C# has moved on, and most of the other developers are more comfortable with C++. We will see. It might be a simple change.

As to OnLimitAction, that is going to be impossible. Rainmeter is not at all in control of things while text is being input, and only regains control again when Enter is hit or the input field is "dismissed". A standard Windows input control is in charge while the input is being done, and there is really no way to have that detect the limit and tell Rainmeter to take some action while the input is still actively being done. The Rainmeter skin is basically asleep / blocked while the input field is active.

So while I suspect it is entirely possible to have the input field just ignore any keystrokes after the limit is reached, as I think this is standard behavior possible with the Windows control, there is no way to have it react to that limit, other than ignoring keystrokes.
User avatar
JosephB2000
Posts: 155
Joined: July 29th, 2014, 7:02 pm

Re: [Feature] InputText Character Limit!

Post by JosephB2000 »

jsmorley wrote:I would be ok with the CharacterLimit option, as that makes a lot of sense. I'm not sure when this can be implemented, as the guy who wrote the plugin in C# has moved on, and most of the other developers are more comfortable with C++. We will see. It might be a simple change.
At last, my first good idea :D

But thanks, I really would like to see this character limit implemented, and you and the C++ developers have no need to rush.

jsmorley wrote:As to OnLimitAction, that is going to be impossible. Rainmeter is not at all in control of things while text is being input, and only regains control again when Enter is hit or the input field is "dismissed". A standard Windows input control is in charge while the input is being done, and there is really no way to have that detect the limit and tell Rainmeter to take some action while the input is still actively being done.
As of that though, I was afraid you were going to say that. I knew that the InputText Measure is a simple Windows Feature, and that rainmeter had no control...

But no worries, the LimitAction wasn't the main feature.
[Insert Joke Here]
User avatar
rbriddickk84
Rainmeter Sage
Posts: 276
Joined: February 17th, 2014, 12:39 pm
Location: Hungary

Re: [Feature] InputText Character Limit!

Post by rbriddickk84 »

Greetings!

I just thinking about this limiting thing, as i working on my clock skin.
I just making an alarm clock option for the main clock, an i want to limit the selectable options for the time.

For example i want to limit the minutes between 00 - 59. But with InputText plugin there are a lots of exception handling needed, and would make a simple alarm clock an insane amount of coding and refreshing actions with external file of use.

I was thinking a lot about some simpler method to limit the selectable options list somehow.

Sorry for posting in the wrong topic!
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5391
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: [Feature] InputText Character Limit!

Post by eclectic-tech »

rbriddickk84 wrote:Greetings!

I just thinking about this limiting thing, as i working on my clock skin.
I just making an alarm clock option for the main clock, an i want to limit the selectable options for the time.

For example i want to limit the minutes between 00 - 59. But with InputText plugin there are a lots of exception handling needed, and would make a simple alarm clock an insane amount of coding and refreshing actions with external file of use.

I was thinking a lot about some simpler method to limit the selectable options list somehow.

Sorry for posting in the wrong topic!
With the use of 1 IfMatch and 1 IfCondition tests on the value returned by the $UserInput$, you can limit the input to any number range and eliminate invalid text inputs.

I will post my input measure and hours test measure so you can see what I am doing.

When a minute time is input by the user, I set the variable Time1Min to the "$UserInput$", then in a string measure, I substitute to add leading zeroes, and test the string to see if it is 1 or 2 digits using the IfMatch. If it does not match digits (meaning it is text or a combination text/numbers), then I reset the variable to the default value and use !CommandMeasure to ask for the input again.
If it passes that test, then I use IfCondition to test to see if the digits are within the range I want to accept, if they are not, then the variable is set to the default, and !CommandMeasure will ask for the input again.

Code: Select all

[mItems]
Measure=Plugin
Plugin=InputText
SolidColor=0,0,0,255
FontColor=255,255,255,255
FontFace=#FontName#
FontSize=((#FontHeight#-1)*#MyScale#)
X=(12*#MyScale#)
Y=(25*#MyScale#)
H=(22*#MyScale#)
W=(140*#MyScale#)
Command1=[!SetVariable Item1 "$UserInput$"] Y=(5*#MyScale#) DefaultValue="#Item1#"
Command2=[!SetVariable Time1Hrs "$UserInput$"] W=(24*#MyScale#) DefaultValue=#Time1Hrs#
Command3=[!SetVariable Time1Min "$UserInput$"] W=(24*#MyScale#) X=(40*#MyScale#) DefaultValue=#Time1Min#

[mInputHrs1]
Measure=String
String=#Time1Hrs#
RegExpSubstitute=1
Substitute="^(\d$)":"0\1"
DynamicVariables=1
IfMatch=\d{1,2}
IfNotMatchAction=[!SetVariable Time1Hrs 00][!CommandMeasure "mItems"  "ExecuteBatch 2"]
IfCondition=(#Time1Hrs#>=0)&&(#Time1Hrs#<=12)
IfFalseAction=[!SetVariable Time1Hrs 00][!CommandMeasure "mItems"  "ExecuteBatch 2"]
IfConditionMode=1

[mInputMin1]
Measure=String
String=#Time1Min#
RegExpSubstitute=1
Substitute="^(\d$)":"0\1"
DynamicVariables=1
IfMatch=\d{1,2}
IfNotMatchAction=[!SetVariable Time1Min 00][!CommandMeasure "mItems"  "ExecuteBatch 3"]
IfCondition=(#Time1Min#>=0)&&(#Time1Min#<=59)
IfFalseAction=[!SetVariable Time1Min 00][!CommandMeasure "mItems"  "ExecuteBatch 3"]
IfConditionMode=1
This should let you limit the input to just numbers in a range you specify. There will be errors in the log by the If Condition if text is entered as the variable; IfCondition only recognizes numbers.

Let me know if this helps
User avatar
rbriddickk84
Rainmeter Sage
Posts: 276
Joined: February 17th, 2014, 12:39 pm
Location: Hungary

Re: [Feature] InputText Character Limit!

Post by rbriddickk84 »

eclectic-tech wrote:With the use of 1 IfMatch and 1 IfCondition tests on the value returned by the $UserInput$, you can limit the input to any number range and eliminate invalid text inputs.

I will post my input measure and hours test measure so you can see what I am doing.

When a minute time is input by the user, I set the variable Time1Min to the "$UserInput$", then in a string measure, I substitute to add leading zeroes, and test the string to see if it is 1 or 2 digits using the IfMatch. If it does not match digits (meaning it is text or a combination text/numbers), then I reset the variable to the default value and use !CommandMeasure to ask for the input again.
If it passes that test, then I use IfCondition to test to see if the digits are within the range I want to accept, if they are not, then the variable is set to the default, and !CommandMeasure will ask for the input again.

Code: Select all

[mItems]
Measure=Plugin
Plugin=InputText
SolidColor=0,0,0,255
FontColor=255,255,255,255
FontFace=#FontName#
FontSize=((#FontHeight#-1)*#MyScale#)
X=(12*#MyScale#)
Y=(25*#MyScale#)
H=(22*#MyScale#)
W=(140*#MyScale#)
Command1=[!SetVariable Item1 "$UserInput$"] Y=(5*#MyScale#) DefaultValue="#Item1#"
Command2=[!SetVariable Time1Hrs "$UserInput$"] W=(24*#MyScale#) DefaultValue=#Time1Hrs#
Command3=[!SetVariable Time1Min "$UserInput$"] W=(24*#MyScale#) X=(40*#MyScale#) DefaultValue=#Time1Min#

[mInputHrs1]
Measure=String
String=#Time1Hrs#
RegExpSubstitute=1
Substitute="^(\d$)":"0\1"
DynamicVariables=1
IfMatch=\d{1,2}
IfNotMatchAction=[!SetVariable Time1Hrs 00][!CommandMeasure "mItems"  "ExecuteBatch 2"]
IfCondition=(#Time1Hrs#>=0)&&(#Time1Hrs#<=12)
IfFalseAction=[!SetVariable Time1Hrs 00][!CommandMeasure "mItems"  "ExecuteBatch 2"]
IfConditionMode=1

[mInputMin1]
Measure=String
String=#Time1Min#
RegExpSubstitute=1
Substitute="^(\d$)":"0\1"
DynamicVariables=1
IfMatch=\d{1,2}
IfNotMatchAction=[!SetVariable Time1Min 00][!CommandMeasure "mItems"  "ExecuteBatch 3"]
IfCondition=(#Time1Min#>=0)&&(#Time1Min#<=59)
IfFalseAction=[!SetVariable Time1Min 00][!CommandMeasure "mItems"  "ExecuteBatch 3"]
IfConditionMode=1
This should let you limit the input to just numbers in a range you specify. There will be errors in the log by the If Condition if text is entered as the variable; IfCondition only recognizes numbers.

Let me know if this helps

Hey there! Thank you for the help!

I will be honest! I have no clue how your commands build up! I used to do much simplier commands, like [!SetVariable Item1 "$UserInput$"], but i thought you can only give commands between []. It is a bit hard to see all the things without the Variables and command giving things. Or maybe it's just too early for me, and can't thinking yet. :)
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5391
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: [Feature] InputText Character Limit!

Post by eclectic-tech »

rbriddickk84 wrote:Hey there! Thank you for the help!

I will be honest! I have no clue how your commands build up! I used to do much simplier commands, like [!SetVariable Item1 "$UserInput$"], but i thought you can only give commands between []. It is a bit hard to see all the things without the Variables and command giving things. Or maybe it's just too early for me, and can't thinking yet. :)
Those additional parameters in the commands are strictly for positioning the input box for my skin, and do not effect the bang actions.

The 'tests' done in the 2 string measures [mInputHrs1] & [mInputMin1] will call for another input from the user if the $UserInput$ does not match the criteria.

You can not limit what a user will type as $UserInput$, but you can 'test' it to make sure you only get the values you want.
User avatar
rbriddickk84
Rainmeter Sage
Posts: 276
Joined: February 17th, 2014, 12:39 pm
Location: Hungary

Re: [Feature] InputText Character Limit!

Post by rbriddickk84 »

eclectic-tech wrote:Those additional parameters in the commands are strictly for positioning the input box for my skin, and do not effect the bang actions.

The 'tests' done in the 2 string measures [mInputHrs1] & [mInputMin1] will call for another input from the user if the $UserInput$ does not match the criteria.

You can not limit what a user will type as $UserInput$, but you can 'test' it to make sure you only get the values you want.
Ah, okay, i see the idea! Thank you for the help and the clarification too! :)
User avatar
eclectic-tech
Rainmeter Sage
Posts: 5391
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: [Feature] InputText Character Limit!

Post by eclectic-tech »

No problem! :welcome:
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [Feature] InputText Character Limit!

Post by jsmorley »

Changes to support this coming in the next beta of Rainmeter.

Only took about 2 years, but that's about right with all the Environmental Impact Studies and Congressional Hearings...