It is currently March 29th, 2024, 9:12 am

[New Feature] Measured String Width?

Report bugs with the Rainmeter application and suggest features.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

[New Feature] Measured String Width?

Post by SilverAzide »

Hello Devs!

I don't know if this is currently possible, but it would be very handy to be able to find the "measured" width of a string in a String meter when clipping is used. By "measured", I mean the width -- in pixels -- you use internally to determine if a string needs to be clipped or wrapped (i.e., Graphics::MeasureString(), DrawText() or equivalent) within the bounding rectangle.

One use of this would be to emulate a feature that Windows often uses. If I have a string that ends up being clipped and "ellipses-ized", I could add some logic in a related measure to provide a tooltip to show the full text, whereas if the string does not end up being clipped I could remove/hide the tooltip.

Here is a simple illustration. In the Rainmeter About dialog, if the Message column is clipped, a tooltip is provided, but if you widen it enough to show the full text, the tooltip is not shown
Image1.png
I realize that the width property (W) can tell you the width of a string meter, but it does not work when clipping is used (you just get the width of the clipping rectangle).

I envision this feature not as a new measure or anything, but as a property of a section. You would reference this like you do the X, Y, W, H properties now, for example [MyStringMeter:Q], where "Q" (or whatever you decide) is the "measured" width in pixels. (Measured height could be useful too.) Obviously this value would be dependent on a lot of things, like if clipping is used, the H/W of the meter, the font, D2D vs. GDI+, etc. -- stuff that is nearly impossible/impractical to find out external to the app code. This feature would also be totally backward compatible with existing skins, since it is only a new property and not a new/revised measure or meter.

A boolean or enum-type property that tells you if a string is clipped or wrapped (or both or neither) could be just as useful, but providing the numeric values might provide more flexibility for skin developers.

Thanks for listening!
You do not have the required permissions to view the files attached to this post.
Gadgets Wiki GitHub More Gadgets...
User avatar
fonpaolo
Moderator
Posts: 1387
Joined: April 11th, 2013, 8:08 pm
Location: Italy

Re: [New Feature] Measured String Width?

Post by fonpaolo »

I agree and fully endorse.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: [New Feature] Measured String Width?

Post by balala »

There is a simple solution of this. According to this one you have to create two different string meters, which both show the same string. One of them have to be clipped and visible, the other unclipped and invisible (setting an almost transparent color, with Alpha set to 1). All other settings should be identical (FontSize, FontFace, StringStyle and so on) - this is very important! Now you can compare the width of these two meters. If the second one (unclipped) is wider then the first one (clipped), then means that the meter exceeded the set width and gone clipped, otherwise obviously it didn't:

Code: Select all

[MeterString1]
Meter=STRING
MeasureName=MyMeasure
X=0
Y=0
W=250
H=14
ClipString=1
FontColor=220,220,220
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=%1

[MeterString2]
Meter=STRING
MeasureName=MyMeasure
X=0
Y=0
FontColor=220,220,220,1
SolidColor=0,0,0,1
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=%1

[MeasureIfClipped]
Measure=Calc
Formula=( [MeterString1:W] = [MeterString2:W] )
IfCondition=(#CURRENTSECTION#=1)
IfTrueAction=[BANGS FOR THE CASE WHEN [MeterString1] ISN'T CLIPPED]
IffALSEAction=[BANGS FOR THE CASE WHEN [MeterString1] IS CLIPPED]
You also have to be careful about the width of the skin (SkinWidth option in [Rainmeter] section), which in some cases can cause troubles.