It is currently February 25th, 2020, 9:46 am

Padding x Image bug

Report bugs with the Rainmeter application and suggest features.
User avatar
JelleDekkers
Posts: 50
Joined: September 27th, 2017, 6:32 pm

Padding x Image bug

Post by JelleDekkers »

Whenever I use the padding option with an image that only has either W or H defined (so not both), it doesn't work properly.

The code could be this:

Code: Select all

[Variables]
Padding=200

[Rainmeter]
Update=-1
AccurateText=1
DynamicWindowSize=1

[Image]
Meter=Image
ImageName=Image.jpg

W=300

Padding=#Padding#, #Padding#, #Padding#, #Padding#
SolidColor=212121
Any image will work, so just get one and put it in the same folder as the skin.

The result is this:
Image
The gray bars around the image are part of the skin, it's the padding.

However, the image I've used is supposed to look like this:
Image

Whenever I set Padding to 0, that's the image I get, which is good. When I keep increasing the value of Padding, the distortion gets worse and worse.

I'm using Rainmeter 4.3.1.3321.
User avatar
jsmorley
Developer
Posts: 20280
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Padding x Image bug

Post by jsmorley »

It's not a bug really.

A) Padding increases the size and shape of the overall meter.

B) When ONLY W or H is defined, then PreserveAspectRatio is forced to "1".

So what happens, while a bit weird, is not unexpected.

1) You have an image that has a particular aspect ratio. It is bigger in W than it is in H or visa versa.

2) Then you add an equal amount of Padding around all sides of the starting meter, which changes the aspect ratio of the overall meter. You didn't add a proportional amount of padding to the top and bottom based on the aspect ratio of the image. So "relatively more" size was added in one direction. It is having proportionally more added to the "smaller" side in a sense.

3) Then the image is resized to whatever you set W or H to.

4) The aspect ratio of the overall meter is "preserved", causing the image embedded in the center of the overall meter to appear distorted.

This all comes down to "when" the various elements of this stuff happens. The resizing of the image based on the overall size and aspect ratio of the meter is the very last thing that is done, and in fact is done in the "redraw" portion of the update cycle, not when the meter itself is "updated".

So the W is applied to just the "image", while the PreserveAspectRatio is applied to the entire "meter". What you really mean to have happen is that the image is resized to the W, preserving the aspect ratio, and THEN the equal amount of padding is added. Doesn't work that way. The padding is added before the sizing, and more importantly, the preservation of the aspect ratio of the meter, is done.

I would be hesitant to use Padding with images that you resize, as this is going to be a bit hard to manage properly.

I could easily argue against this behavior, but things in Rainmeter have to happen in some "order". Some things have to happen "first" and some "second". This is how it ended up, and I suspect we have to live with it for backwards compatibility reasons.
User avatar
jsmorley
Developer
Posts: 20280
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Padding x Image bug

Post by jsmorley »

I would be tempted to do this instead:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
Pad=150

[MeterBack]
Meter=Shape
Shape=Rectangle 0,0,([MeterImage:W]+#Pad#*2),([MeterImage:H]+#Pad#*2) | StrokeWidth 0 | Fill Color 255,0,0,150
DynamicVariables=1

[MeterImage]
Meter=Image
ImageName=#@#Images\laughing.jpg
X=#Pad#
Y=#Pad#
W=300

1.png
You do not have the required permissions to view the files attached to this post.
User avatar
Jeff
Posts: 125
Joined: September 3rd, 2018, 11:18 am

Re: Padding x Image bug

Post by Jeff »

jsmorley wrote:
December 30th, 2019, 7:58 pm
I suspect we have to live with it for backwards compatibility reasons.
Backwards Compatibility strikes again!

Only problem I see is relative positioning but that can be resolved by #Pad#r/R (custom one on the first meter after if using MeterStyles)
Good enough fix
User avatar
jsmorley
Developer
Posts: 20280
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Padding x Image bug

Post by jsmorley »

The only other issue is that if the image is dynamically changed to something with a different aspect ratio, the background Shape will be one update behind in sizing itself. So for one second it will be wrong, then correct itself.
User avatar
JelleDekkers
Posts: 50
Joined: September 27th, 2017, 6:32 pm

Re: Padding x Image bug

Post by JelleDekkers »

jsmorley wrote:
December 30th, 2019, 8:36 pm
The only other issue is that if the image is dynamically changed to something with a different aspect ratio, the background Shape will be one update behind in sizing itself. So for one second it will be wrong, then correct itself.
That's why I always do two !UpdateMeter bangs, then a !Redraw. Anyways, I fail to see how fixing this bug would affect backwards compatibility. I mean, I don't see anybody using the padding option to deliberately mess up an image's aspect ratio.