It is currently October 18th, 2021, 11:38 am

[Solved] Question: String Meter val manip - Remove space?

Help with creating, editing & fixing problems with skins
User avatar
Grim
Posts: 56
Joined: February 5th, 2014, 3:44 pm
Location: Canada

[Solved] Question: String Meter val manip - Remove space?

Post by Grim »

I've gone through the docs, I've searched, I've googled, I've skimmed the skin archives looking for someone who may have done this so I can 'borrow' the code, and hours later I've come up empty. :(

So here I am asking for help.

I've got a RAM and SWAP Meter that displays the values via String working fine. However due to the size of my skin I'd like to be able to remove the spaces between the value and the "byte" representation to save a bit of space.

Can this be done? :confused:
If yes, please show me how oh wise Rainmeter gurus! :D

TL;DR
String Meter...
What I have: 2.3 GB
What I want: 2.3GB (No space between the number and GB)
Last edited by Grim on February 12th, 2014, 5:42 pm, edited 2 times in total.
User avatar
jsmorley
Developer
Posts: 22368
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Question: String Meter value manipulation - Remove space

Post by jsmorley »

Assuming you are using the AutoScale option on the meter to scale the value, then really no. The space is added automatically when the meter is drawn, and there is no way to suppress it. You would instead need to use the Scale option, and tell it the amount you want to scale the number. Then you can set any text you want on the meter, by using the Text option with %1 for the value returned by MeasureName on the meter. This is going to be quite a bit less flexible than AutoScale, since you will have to make an assumption that the value is always going to be megabytes or gigabytes or whatever works best.
User avatar
smurfier
Moderator
Posts: 1930
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Question: String Meter value manipulation - Remove space

Post by smurfier »

Here's the scary math solution.

Code: Select all

[Variables]
Decimals=2

[num]
Measure=Calc
Formula=1563154794265

[Scale]
Measure=Calc
Formula=num=0?1:ceil(log(num)/(10*log(2)))
Substitute="1":"B","2":"kB","3":"mB","4":"gB","5":"tB","6":"pB","7":"eB","8":"zB","9":"yB"

[Scaled]
Measure=Calc
Formula=round(num/1024**(Scale-1),#Decimals#)

[String]
Meter=String
MeasureName=Scaled
MeasureName2=Scale
NumOfDecimals=#Decimals#
Text=%1%2
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
Grim
Posts: 56
Joined: February 5th, 2014, 3:44 pm
Location: Canada

Re: Question: String Meter value manipulation - Remove space

Post by Grim »

jsmorley wrote:Assuming you are using the AutoScale option on the meter to scale the value, then really no. The space is added automatically when the meter is drawn, and there is no way to suppress it. You would instead need to use the Scale option, and tell it the amount you want to scale the number. Then you can set any text you want on the meter, by using the Text option with %1 for the value returned by MeasureName on the meter. This is going to be quite a bit less flexible than AutoScale, since you will have to make an assumption that the value is always going to be megabytes or gigabytes or whatever works best.
I am using AutoScale, and damn. 3.1 feature request? :oops:
smurfier wrote:Here's the scary math solution.
:o
8< Snip, will play with this and see.


Thanks for the quick responses. :thumbup:

Edit: Took the 'B' out of my Text. Saved some room there. :)
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Question: String Meter value manipulation - Remove space

Post by MerlinTheRed »

Perhaps this would be a cool addition to the String measure. Let it behave kind of like a String meter only that it's not displayed. This means let it use AutoScale and %1 etc. to insert values of other measures, then edit the result by Substitute/RegExpSubstitute.
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
User avatar
Grim
Posts: 56
Joined: February 5th, 2014, 3:44 pm
Location: Canada

Re: Question: String Meter value manipulation - Remove space

Post by Grim »

So I found a solution to this that's way simple using a Substitute on the Measure.
Substitute=" K":"K"," M":"M"," G":"G"," T":"T"
:thumbup:
Full working code example with measures and meters.

Code: Select all

[MeasurePMUsed]
Measure=PhysicalMemory
UpdateDivider=2
Substitute=" K":"K"," M":"M"," G":"G"," T":"T"

[MeasurePMFree]
Measure=PhysicalMemory
InvertMeasure=1
UpdateDivider=2
Substitute=" K":"K"," M":"M"," G":"G"," T":"T"

[MeasurePMTotal]
Measure=PhysicalMemory
Total=1
UpdateDivider=-1
Substitute=" K":"K"," M":"M"," G":"G"," T":"T"

[MeterPMTextUsed]
Meter=String
MeasureName=MeasurePMUsed
X=5
Y=r
FontColor=00FF00
NumOfDecimals=1
AutoScale=1
Text="RAM Used: %1"

[MeterPMTextFree]
Meter=String
MeasureName=MeasurePMFree
X=r
Y=R
FontColor=00FF00
NumOfDecimals=1
AutoScale=1
Text="RAM Free: %1"

[MeterPMTextTotal]
Meter=String
MeasureName=MeasurePMTotal
X=r
Y=R
FontColor=00FF00
NumOfDecimals=1
AutoScale=1
Text="RAM Total: %1"
Edit: Thanks to the creator of the following skin for the snippet.
http://goatrance.deviantart.com/art/The-professional-312277079
User avatar
Grim
Posts: 56
Joined: February 5th, 2014, 3:44 pm
Location: Canada

Re: Question: String Meter value manipulation - Remove space

Post by Grim »

Grim wrote:So I found a solution to this that's way simple using a Substitute on the Measure.
Substitute=" K":"K"," M":"M"," G":"G"," T":"T"
Simpler still...
Substitute=" ":""

Tested in the skin I'm working on and works on FreeDiskSpace, Memory, and Net Measures.
:)

Was sure I tested this before posting the OP and it wasn't working, but it works now. :confused:
User avatar
moshi
Posts: 1740
Joined: November 13th, 2012, 9:53 pm

Re: [Solved] Question: String Meter val manip - Remove space

Post by moshi »

haha :D

i would not have gotten this idea. but it makes sense, as the meter of course does not to the scaling and the value is already there in the measure.
User avatar
jsmorley
Developer
Posts: 22368
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: [Solved] Question: String Meter val manip - Remove space

Post by jsmorley »

The routines for Subsitute and AutoScale are both in the underlying code for measures (Measure.cpp in the C++), but they are "called" by the meters when the value is "used". Just so happens that Substitute is done last. This is a nice trick that also never occurred to me before.
User avatar
Grim
Posts: 56
Joined: February 5th, 2014, 3:44 pm
Location: Canada

Re: [Solved] Question: String Meter val manip - Remove space

Post by Grim »

jsmorley wrote:The routines for Subsitute and AutoScale are both in the underlying code for measures (Measure.cpp in the C++), but they are "called" by the meters when the value is "used". Just so happens that Substitute is done last. This is a nice trick that also never occurred to me before.
Tips and Tricks! :thumbup: