Page 2 of 2
Re: Can I "center" my download rate with the «.» ?
Posted: August 8th, 2018, 9:50 pm
by jsmorley
Rambytes wrote:I've read twice the answer of jsmorley and i'm not sure to understand how to split in two meter....
I'll work on a solution for you, but it might have to be later tonight or in the morning.
Re: Can I "center" my download rate with the «.» ?
Posted: August 8th, 2018, 11:27 pm
by Rambytes
My friend TAKE YOUR TIME..... no rush on that... no rush at all
Re: Can I "center" my download rate with the «.» ?
Posted: August 8th, 2018, 11:56 pm
by FreeRaider
I think I found a possible solution, but it works if you use a
monospaced font (I used Courier New in this example code)
Code: Select all
[Rainmeter]
Update=500
DynamicWindowSize=1
AccurateText=1
[Metadata]
Name=Testing
Author=FreeRaider
License=Creative Commons Attribution-Non-Commercial-Share Alike 3.0
[Variables]
OFFSET=-18
[MeasureNetIn]
Measure=NetIn
[MeterDOWNLOAD]
Meter=String
X=0
Y=0
FontFace=Courier New
FontColor=255,255,255,255
StringStyle=Bold
StringAlign=Left
FontSize=24
NumOfDecimals=1
AutoScale=1k
Text="DOWNLOAD"
Antialias=1
DynamicVariables=1
[MeterDOWNLOADrate]
Meter=String
MeasureName=MeasureNetIn
X=( ([MeterDOWNLOAD:W] * 2 + #OFFSET#) /2 )
Y=5R
FontFace=Courier New
FontColor=255,255,255,255
StringStyle=Bold
FontSize=20
StringAlign=RIGHT
NumOfDecimals=1
AutoScale=1k
Text="%1/s"
Antialias=1
DynamicVariables=1
Let us know what you think.
Re: Can I "center" my download rate with the «.» ?
Posted: August 9th, 2018, 1:31 am
by Rambytes
OMG......
Ok, dude, you're awesome....
Explain to me this part of the code:
Code: Select all
X=( ([MeterDOWNLOAD:W] * 2 + #OFFSET#) /2 )
Thanks again!
Re: Can I "center" my download rate with the «.» ?
Posted: August 9th, 2018, 3:26 am
by jsmorley
I really still think Lua is a better way to go. It keeps the skin really simple, and to be honest the Lua isn't rocket science either. The trickiest bit is just a canned routine I stole from
https://docs.rainmeter.net/snippets/autoscale/.
CenerOnDec_1.0.rmskin
CenterOnDec.ini:
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
Interface=Best
CenterPoint=150
[MeasureNetIn]
Measure=NetIn
Interface=#Interface#
UseBits=1
[Lua]
Measure=Script
ScriptFile=CenterOnDec.lua
Disabled=1
[MeterNetInTrunc]
Meter=String
X=#CenterPoint#
StringAlign=Right
FontSize=15
FontWeight=400
FontColor=255,255,255,255
AntiAlias=1
DynamicVariables=1
Text=[&Lua:SplitScaled([&MeasureNetIn:],'trunc')]
[MeterNetInFrac]
Meter=String
X=#CenterPoint#
StringAlign=Left
FontSize=15
FontWeight=400
FontColor=255,255,255,255
AntiAlias=1
DynamicVariables=1
Text=.[&Lua:SplitScaled([&MeasureNetIn:],'frac')]
CenterOnDec.lua:
Code: Select all
function SplitScaled(inVal, whichSide)
valScaled, scaleTxt = AutoScale(inVal,1)
truncValue, fracValue = math.modf(valScaled)
fracValue = Round(fracValue, 1)
fracValue = string.gsub(fracValue, '0.', '')
if whichSide == 'trunc' then
return truncValue
elseif whichSide == 'frac' then
return fracValue..' '..scaleTxt..'b/s'
else
return ''
end
end
function AutoScale(num, idp)
assert(tonumber(num), 'AutoScale expects a number.')
local scales = {'', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'}
local places = idp or 0
local scale = ""
local scaled = 0
for i, v in ipairs(scales) do
if (num < (1024 ^ i)) or (i == #scales) then
scale = v
scaled = Round(num / 1024 ^ (i - 1), places)
break
end
end
return scaled, scale
end
function Round(num, idp)
assert(tonumber(num), 'Round expects a number.')
local mult = 10 ^ (idp or 0)
if num >= 0 then
return math.floor(num * mult + 0.5) / mult
else
return math.ceil(num * mult - 0.5) / mult
end
end
GIF.gif
The decimal point will never move, no matter what is on the left or right side of it, and that is the stated goal. It doesn't care what font or font size you use.
I will let you take a crack at adding what is needed for the NetOut stuff, needless to say is will follow the same approach, with no changes needed to the one-size-fits-all Lua.
Let me know if you have questions. I can walk you through the Lua if you need it.
https://docs.rainmeter.net/manual/lua-scripting/
https://docs.rainmeter.net/manual/lua-scripting/inline-lua/
https://docs.rainmeter.net/manual/variables/nesting-variables/
http://lua-users.org/wiki/MathLibraryTutorial
math.modf
Return the integral and fractional parts of the given number.
> = math.modf(5)
5 0
> = math.modf(5.3)
5 0.3
> = math.modf(-5.3)
-5 -0.3
http://lua-users.org/wiki/StringLibraryTutorial
string.gsub(s, pattern, replace [, n])
This is a very powerful function and can be used in multiple ways. Used simply it can replace all instances of the pattern provided with the replacement. A pair of values is returned, the modified string and the number of substitutions made. The optional fourth argument n can be used to limit the number of substitutions made
Re: Can I "center" my download rate with the «.» ?
Posted: August 9th, 2018, 12:36 pm
by jsmorley
Reworked my solution to use Inline Lua, as it makes the Lua a reusable function, and anyway is just simpler and more straight-forward.
P.S. I used "bits" and not the default "bytes" in the display of the Net values, which is consistent with places like speedtest.net, and scaled by 1024 (mebibit or Mib), which is consistent with how Windows deals with "mega". If you want to change this to "bytes", you can remove the UseBits=1 options from the NetIn measure, and change the b/s text in the Lua to B/s. You can scale by 1000 (megabit or Mb) by changing the 1024 in the AutoScale function in the .lua to 1000.
Re: Can I "center" my download rate with the «.» ?
Posted: August 9th, 2018, 2:46 pm
by FreeRaider
Rambytes wrote:OMG......
Ok, dude, you're awesome....
Explain to me this part of the code:
Code: Select all
X=( ([MeterDOWNLOAD:W] * 2 + #OFFSET#) /2 )
Thanks again!
You are welcome!
Now
Code: Select all
X=( ([MeterDOWNLOAD:W] * 2 + #OFFSET#) /2 )
it return the X position of the meter and it is used as the anchor point. It use the
weight width of meterDOWNLOAD (have a look at this page
https://docs.rainmeter.net/manual/variables/section-variables/#MeterParameters/) and an OFFESET variable (it is a bit negative value in this case) for setting the X position as you prefer.
I used Autoscale=1k because it leave the "k" before "/s" and it means that
Scales by 1024 with kilo as the lowest unit.
Maybe this option in METERDOWNLOAD it is useless, but to understand this option it is better to read this page
https://docs.rainmeter.net/manual/variables/#DynamicVariables
Re: Can I "center" my download rate with the «.» ?
Posted: August 10th, 2018, 11:50 am
by Rambytes
FreeRaider, and ALL the OTHER, thanks a lot...... very very very appreciated!!!!!
Re: Can I "center" my download rate with the «.» ?
Posted: August 10th, 2018, 5:04 pm
by FreeRaider
Glad to help.