Thread Tools Display Modes
08-17-19, 01:51 AM   #1
spychalski
A Kobold Labourer
Join Date: Jun 2008
Posts: 1
Adding one pixel in a frame's height instead adds two?

Hey, it's my first time messing around with addons, trying to make a simple frame and ran into a very intriguing issue.

For starters, here is some code:
Lua Code:
  1. local function CreateUnitFrame(self, unit)
  2.     self:SetSize(220, 41)
  3.     self:SetBackdrop(settings.textures.backdrop)
  4.     self:SetBackdropColor(0, 0, 0)
  5.  
  6.     -- health bar
  7.     local hp = CreateFrame("StatusBar", nil, self)
  8.     hp:SetPoint("TOPLEFT")
  9.     hp:SetPoint("TOPRIGHT")
  10.     hp:SetHeight(30)
  11.     hp:SetStatusBarTexture(settings.textures.main)
  12.     hp:SetStatusBarColor(unpack(settings.colors.hpBar))
  13.  
  14.     hp.bg = hp:CreateTexture(nil, "BACKGROUND")
  15.     hp.bg:SetAllPoints(hp)
  16.     hp.bg:SetTexture(settings.textures.backdrop.bgFile)
  17.  
  18.     hp.frequentUpdates = true
  19.     hp.PostUpdate = core.SetBackground
  20.     self.Health = hp
  21.  
  22.     -- power bar
  23.     local pb = CreateFrame("StatusBar", nil, self)
  24.     pb:SetPoint("BOTTOMLEFT", 0, 0)
  25.     pb:SetPoint("BOTTOMRIGHT", 0, 0)
  26.     pb:SetHeight(10)
  27.     pb:SetStatusBarTexture(settings.textures.main)
  28.  
  29.     pb.bg = pb:CreateTexture(nil, "BACKGROUND")
  30.     pb.bg:SetAllPoints(pb)
  31.     pb.bg:SetTexture(settings.textures.backdrop.bgFile)
  32.     pb.bg:SetVertexColor(unpack(settings.colors.hpBar))
  33.  
  34.     pb.colorPower = true
  35.     self.Power = pb
  36. end

This is a simple Frame with a Health bar and a Power bar. My goal is to have 1px borders around the frame itself and one pixel separating the two bars. Instead, this is what I get:



and in case you can't see it:


the frame's height is 44, when it should be 43:

1 px top
40 px health
1 px gap
10 px power
1 px bottom

Now, checking the second image, I can tell you the Power bar is only 9 pixels high. The underlying frame is "taking" one pixel from it.

Does anybody have any ideas how to approach and fix this?

I already messed around with UI scales, no matter what it is (0.5333, 0.64, 0.7111 and 1 tested), the issue persists.

The only way I can fix this is by instead drawing one of the inner bars with one less pixel.
  Reply With Quote
08-17-19, 05:58 AM   #2
elcius
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Sep 2011
Posts: 75
most likely caused by floating point errors on a parent frames position or size.
doing this may work:
Lua Code:
  1. self:SetSize(220.1, 41.1)
  Reply With Quote
08-17-19, 07:51 AM   #3
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
As elcius points out, sizing is off on every UI element due to UI scale. If you don't use the UI scale option, WoW does not default it to 1, it attempts to give you a pixel perfect size, which is about 0.7 for a 1920x1080 screen. In the past, WoW gave you 1, which is why older screenshots, especially vanilla, had bigger screen elements like the bottom bar taking up the whole screen width.

The problem with a UI scale under 1 is that while sizing and positioning attributes go with the screen size, the "absolute" values are hidden and configured for us behind the scenes, which are approximately "screen / scale". This means a 1920x1080 screen using a scale of 0.7 has an absolute size of 2742x1542 "underneath". There is no way to directly get these values, at least no way I'm aware of, but MoveAnything gives you the absolute values of a frame, which is what I use when carefully moving something to avoid weird thick or antialiased borders. The "visible" values end up with decimal places but the frame I'm moving gets a razor sharp edge.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Adding one pixel in a frame's height instead adds two?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off