It is currently April 27th, 2024, 3:01 pm

Show tooltip only if text clipped?

Report bugs with the Rainmeter application and suggest features.
User avatar
~Faradey~
Posts: 366
Joined: November 12th, 2009, 4:47 pm
Location: Ukraine

Re: Show tooltip only if text clipped?

Post by ~Faradey~ »

lysy1993lbn wrote:Unfortunetly Text=%1 is exacly what I use :(
Well, if you only use Text="%1" and nothing different, i mean for exmpl Text="%1 - %2 |%3", then you can remove Text="%1" from metters, text should be shown anyway, and you can use this example. But if not then lua script will need to some changes ;)
User avatar
~Faradey~
Posts: 366
Joined: November 12th, 2009, 4:47 pm
Location: Ukraine

Re: Show tooltip only if text clipped?

Post by ~Faradey~ »

I've rewrite example and now it involvesText="%1" and also using this approach you don't have to create many script measures in skin for each Metter. I did so to make code simple (convinient) to use. Look at the code, hope you'll understand why, but if not, ask for what you don't understand and I, or rainmeter's gurus will answer you :)

Skin

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
String="Hello i am a very very very long string"
String2="short string"

;--------------------------------------------
[CHCD]
Measure=Script
ScriptFile="#CURRENTPATH#ch_mcd.lua"
Meterlength=MeterToGetStringWidth
MeterToCheck=TestMeter
MeasureToCheck=TestMeasure1
UpdateDivider=-1
[MeterToGetStringWidth]
Meter=String
X=-3000
Y=-1000
Hidden=0
UpdateDivider=-1
;------------------------------------------

[TestMeasure1]
Measure=TIME
Format=#String#

[TestMeasure2]
Measure=TIME
Format=#String2#

[TestMeasure3]
Measure=TIME
Format=#String#

[TestMeter]
Meter=String
MeasureName=TestMeasure1
X=0
Y=0
W=100
H=14
ToolTipText="%1"
ToolTipHidden=1
FontColor=255,255,255
SolidColor=0,0,0,1
Hidden=0
Text="%1"
ClipString=1
MouseOverAction=!execute [!SetOption CHCD MeterToCheck #CURRENTSECTION#][!SetOption CHCD MeasureToCheck TestMeasure1][!UpdateMeasure CHCD]

[TestMeter2]
Meter=String
MeasureName=TestMeasure2
X=0
Y=20r
W=100
H=14
ToolTipText="%1"
ToolTipHidden=1
FontColor=255,255,255
SolidColor=0,0,0,1
Hidden=0
Text="%1"
ClipString=1
MouseOverAction=!execute [!SetOption CHCD MeterToCheck #CURRENTSECTION#][!SetOption CHCD MeasureToCheck TestMeasure2][!UpdateMeasure CHCD]

[TestMeter3]
Meter=String
MeasureName=TestMeasure3
X=0
Y=20r
W=100
H=14
ToolTipText="%1"
ToolTipHidden=1
FontColor=255,255,255
SolidColor=0,0,0,1
Hidden=0
Text="%1"
ClipString=1
MouseOverAction=!execute [!SetOption CHCD MeterToCheck #CURRENTSECTION#][!SetOption CHCD MeasureToCheck TestMeasure3][!UpdateMeasure CHCD]
Lua Script

Code: Select all

PROPERTIES =
{

}

function Initialize()
 
end -->Initialize

function Update()
sMeterSetting1,sMeterSetting2 = SELF:GetOption('Meterlength'),SELF:GetOption('MeterToCheck')
sMeasureSetting = SELF:GetOption('MeasureToCheck')
sMeasure = SKIN:GetMeasure(sMeasureSetting)
Val0 = sMeasure:GetStringValue()
SKIN:Bang("!SetOption "..sMeterSetting1.." Text \"\"\"" ..Val0.."\"\"\""); SKIN:Bang("!UpdateMeter "..sMeterSetting1); SKIN:Bang("!Redraw")
sMeter1,sMeter2 = SKIN:GetMeter(sMeterSetting1),SKIN:GetMeter(sMeterSetting2)
Val1,Val2,Val2_1 = sMeter1:GetW(),sMeter2:GetOption('Text'),tonumber(sMeter2:GetW())
if Val1 >= Val2_1 then 
	SKIN:Bang("!SetOption "..sMeterSetting2.." ToolTipHidden 0")
	SKIN:Bang("!UpdateMeter "..sMeterSetting2)
	SKIN:Bang("!Redraw")
else 
	SKIN:Bang("!SetOption "..sMeterSetting2.." ToolTipHidden 1")
	SKIN:Bang("!UpdateMeter "..sMeterSetting2)
	SKIN:Bang("!Redraw")
end	
end -->Update
User avatar
lysy1993lbn
Posts: 291
Joined: July 25th, 2011, 9:53 am
Location: Lublin, Poland

Re: Show tooltip only if text clipped?

Post by lysy1993lbn »

Thanks ~Faradey~.. Semms to works fine, but.. do i need 20 script measures to make it work in 20 separate meters?

I'm bit confused..

Sorry if it's a stupid question but i don't know lua scripting at all..
"Never argue with an idiot, he will drag you down to his level and beat you with experience."
my deviantART | Alternative Rainmeter tray icons
User avatar
~Faradey~
Posts: 366
Joined: November 12th, 2009, 4:47 pm
Location: Ukraine

Re: Show tooltip only if text clipped?

Post by ~Faradey~ »

Of Course not, as i wrote earlier in my post:
~Faradey~ wrote: using this approach you don't have to create many script measures in skin for each Metter
so i repeat, you don't have to! ;)
all you need to add in your skin is this little part of code:

Code: Select all

;--------------------------------------------
[CHCD]
Measure=Script
ScriptFile="#CURRENTPATH#ch_mcd.lua"
Meterlength=MeterToGetStringWidth
MeterToCheck=TestMeter
MeasureToCheck=TestMeasure1
UpdateDivider=-1
[MeterToGetStringWidth]
Meter=String
X=-3000
Y=-1000
Hidden=0
UpdateDivider=-1
;------------------------------------------
and lua script ch_mcd.lua itself (in scin's directory ,you can change the path if you want, just edit ScriptFile="#CURRENTPATH#ch_mcd.lua" to where you want it)

also in metter where you want to use this feature, you need to add OnMouseOverAction and use bang with next syntax:
MouseOverAction=!execute [!SetOption CHCD MeterToCheck NameOfMeter][!SetOption CHCD MeasureToCheck NameOfMeasure][!UpdateMeasure CHCD]


hope now you get the point)
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Show tooltip only if text clipped?

Post by smurfier »

Here's a slightly simplified version:

Skin.ini

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
String="Hello i am a very very very long string"
String2="short string"

;--------------------------------------------
[CHCD]
Measure=Script
ScriptFile=Lua.lua
Meterlength=MeterToGetStringWidth
UpdateDivider=-1

[MeterToGetStringWidth]
Meter=String
X=-3000
Y=-1000
UpdateDivider=-1
;------------------------------------------

[TestMeasure1]
Measure=TIME
Format=#String#

[TestMeasure2]
Measure=TIME
Format=#String2#

[TestMeasure3]
Measure=TIME
Format=#String#

[TestMeter]
Meter=String
MeasureName=TestMeasure1
X=0
Y=0
W=100
H=14
ToolTipText="%1"
ToolTipHidden=1
FontColor=255,255,255
SolidColor=0,0,0,1
ClipString=1
MouseOverAction=!CommandMeasure CHCD ToolTip('#CURRENTSECTION#')

[TestMeter2]
Meter=String
MeasureName=TestMeasure2
X=0
Y=20r
W=100
H=14
ToolTipText="%1"
ToolTipHidden=1
FontColor=255,255,255
SolidColor=0,0,0,1
ClipString=1
MouseOverAction=!CommandMeasure CHCD ToolTip('#CURRENTSECTION#')

[TestMeter3]
Meter=String
MeasureName=TestMeasure3
X=0
Y=20r
W=100
H=14
ToolTipText="%1"
ToolTipHidden=1
FontColor=255,255,255
SolidColor=0,0,0,1
ClipString=1
MouseOverAction=!CommandMeasure CHCD ToolTip('#CURRENTSECTION#')
Lua.lua:

Code: Select all

function Initialize()
	LengthName=SELF:GetOption('MeterLength')
	LengthHandle=SKIN:GetMeter(LengthName)
end

function ToolTip(MeterName)
	local MeterHandle=SKIN:GetMeter(MeterName)
	local Measure=SKIN:GetMeasure(MeterHandle:GetOption('MeasureName'))
	
	SKIN:Bang('!SetOption',LengthName,'Text',Measure:GetStringValue())
	SKIN:Bang('!UpdateMeter',LengthName)
	SKIN:Bang('!Redraw')
	
	SKIN:Bang('!SetOption',MeterName,'ToolTipHidden',LengthHandle:GetW() >= MeterHandle:GetW and 0 or 1)
	SKIN:Bang('!UpdateMeter',MeterName)
	SKIN:Bang('!Redraw') 
end -- ToolTip
This version retrieves the MeasureName from the meter itself. No need to specify it to the script at all.

Note: This script requires Rainmeter 2.3 beta r1377 or higher.
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
lysy1993lbn
Posts: 291
Joined: July 25th, 2011, 9:53 am
Location: Lublin, Poland

Re: Show tooltip only if text clipped?

Post by lysy1993lbn »

Sorry.. still don't understand half this trick..

Do i need

Code: Select all

[TestMeasure2]
Measure=TIME
Format=#String2#
For all meters?
It's measure output so it has to be Format=[MeasureRSS2] (ant of course DynamicVariables=1). Will it work in that way?

What should I add to every meter (or by meter styles) to get it to work with all?

Skin update is set to 10 minutes, RSS is updated then, maybe run this script in the same time interval..

Feel so stupid.. :?

BTW: There is skin which i'm trying implement it in.
"Never argue with an idiot, he will drag you down to his level and beat you with experience."
my deviantART | Alternative Rainmeter tray icons
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Show tooltip only if text clipped?

Post by smurfier »

What you are asking about is simply a placeholder for the actual measure that you are using.
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
lysy1993lbn
Posts: 291
Joined: July 25th, 2011, 9:53 am
Location: Lublin, Poland

Re: Show tooltip only if text clipped?

Post by lysy1993lbn »

Tell me like for idiot.. Where should I put what? Exacly code..
Maybe I'll understand finally then..
"Never argue with an idiot, he will drag you down to his level and beat you with experience."
my deviantART | Alternative Rainmeter tray icons
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Show tooltip only if text clipped?

Post by smurfier »

You save the lua code using notepad as Lua.lua, being sure to change the file type to "all files" and removing the .txt extension. Put it in the same folder as your skin.

In you skin add the following Measure. The MeterLenght line gives the script the name of a String Meter that we will use to determine the width of the text.

Code: Select all

[Lua]
Measure=Script
ScriptFile=Lua.lua
MeterLength=SpareMeter
Now define the meter that we specified in the script measure.

Code: Select all

[SpareMeter]
Meter=String
X=-3000
Y=-1000
UpdateDivider=-1
We place it in the extreme negative coordinate region just so that it's not part of the skin that is shown.

Now we are going to set up a string meter to use out new script with.

Code: Select all

[SomeText]
Meter=String
MeasureName=SomeMeasure
H=10
W=100
ToolTipText=%1
MouseOverAction=!CommandMeasure Lua ToolTip('#CURRENTSECTION#')
When you mouseover the meter the script will fire, pulling the MeasureName from the meter itself. It will use the 'SpareMeter' that we defined to see how long the text is in pixels, and determine if the ToolTip is necessary.
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 . . .
allkhor
Posts: 3
Joined: June 16th, 2012, 12:22 pm

Re: Show tooltip only if text clipped?

Post by allkhor »

smurfier wrote: SKIN:Bang('!SetOption',MeterName,'ToolTipHidden',LengthHandle:GetW >= MeterHandle:GetW and 0 or 1)
In this line, rainmeter 2.3.1 r1510 64-bit, return error: Script:Lua.lua:29:function arguments expected near '>='


Change to:

Code: Select all

SKIN:Bang('!SetOption',MeterName,'ToolTipHidden',LengthHandle:GetW() >= MeterHandle:GetW() and 0 or 1)
Thank's for script!