Thread Tools Display Modes
09-16-14, 08:14 AM   #1
Kagura
A Fallenroot Satyr
Join Date: Nov 2008
Posts: 21
ScrollFrame behavior

I am working on my own UI and Framework and noticed that when I place frames in a scrollframe, the aligning (anchors) seem to be behaving very weird.

I attached the screenshots and the lua code for creating this panel you see on the picture. My problem is next and it really annoys the shit out of me :S

On screenshot one, you can see the close button is aligned one pixel higher than the close button (the SetPoint for both these buttons get generated from the offsets and it basically translates for both to :SetPoint('TOP', 10, 0)

On screenshot two you can see the close button is aligned one pixel lower.

On screenshot three, you can see they are correctly aligned.

So what's the difference between these screenshots? Well nothing code-wise. The only difference is that this 'window' is dragged to different positions on the screen.

If I anchor these buttons to anything but the scroll child, they work as expected.

So my question is : Is there anything I can do to fix this or is this some quirk with ScrollFrames I can not get around?






Lua Code:
  1. local addon, ns = ...
  2. local O3 = ns.O3
  3. local UI = O3.UI
  4.  
  5. UI.ScrollWindow = UI.Window:extend({
  6.     createContent = function (self)
  7.         self.content = UI.ScrollPanel:instance({
  8.             parentFrame = self.frame,
  9.             offset = {1, 1, 24, 24},
  10.             style = function (self)
  11.                 self.scrollFrame:outline({
  12.                     layer = 'BORDER',
  13.                     gradient = 'VERTICAL',
  14.                     color = {1, 1, 1, 0.03 },
  15.                     colorEnd = {1, 1, 1, 0.05 },
  16.                     offset = {-1, -1, -1, -1 },
  17.                 })
  18.                 self.scrollFrame:texture({
  19.                     layer = 'BACKGROUND',
  20.                     file = O3.Media:texture('Background'),
  21.                     tile = true,
  22.                     color = {0.5, 0.5, 0.5, 0.5},
  23.                     offset = {-1, -1, -1, -1},
  24.                 })
  25.             end,
  26.         })
  27.         self.contentFrame = self.content.scrollFrame.content.frame
  28.     end,
  29.     hook = function (self)
  30.         self.frame:SetScript('OnSizeChanged', function ()
  31.             self.content:update()
  32.         end)
  33.     end,
  34.     postCreate = function (self)
  35.         UI.Button:instance({
  36.             parentFrame = self.contentFrame,
  37.             width = 100,
  38.             height = 20,
  39.             text = 'Open',
  40.             offset = {0, nil, 10, nil}
  41.         })
  42.  
  43.         UI.Button:instance({
  44.             parentFrame = self.contentFrame,
  45.             width = 100,
  46.             height = 20,
  47.             text = 'Close',
  48.             offset = {101, nil, 10, nil}
  49.         })
  50.  
  51.         UI.GlyphButton:instance({
  52.             parentFrame = self.contentFrame,
  53.             width = 20,
  54.             height = 20,
  55.             text = '',
  56.             offset = {202, nil, 10, nil}
  57.         })
  58.     end,
  59. })
  60.  
  61. local testPanel = UI.ScrollWindow:instance({
  62.     --managed = true,
  63.     _weight = 99,
  64.     -- name = 'TestWindow',
  65.     offset = {100, nil, 100, nil},
  66.     parentFrame = UIParent,
  67. })
  68. testPanel:show()
  Reply With Quote
09-16-14, 08:48 AM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
I'm not sure how you're generating the offsets for the buttons, but it would appear that you're getting a different result for the Open and Close buttons because only one of them is being affected by this.

I would hazard a guess that its point is being set to a fraction of a pixel and is being rounded based on its proximity to a pixel boundary as the frame is moved around, however the fact that it's only affecting one of the buttons would indicate that something is different between them.

The only visible difference I can see based on the code you've posted is that they contain different text, so maybe you're factoring in the font string somehow.
  Reply With Quote
09-16-14, 09:05 AM   #3
Kagura
A Fallenroot Satyr
Join Date: Nov 2008
Posts: 21
I tried next piece of code

Lua Code:
  1. -- snip
  2.     postCreate = function (self)
  3.         local button1 = UI.Button:instance({
  4.             parentFrame = self.contentFrame,
  5.             width = 100,
  6.             height = 20,
  7.             text = 'Close',
  8.             --offset = {0, nil, 10, nil}
  9.         })
  10.         button1:point('TOPLEFT', 10, -10)
  11.  
  12.         local button2 = UI.Button:instance({
  13.             parentFrame = self.contentFrame,
  14.             width = 100,
  15.             height = 20,
  16.             text = 'Close',
  17.             --offset = {101, nil, 10, nil}
  18.         })
  19.         button2:point('TOPLEFT', 110, -10)
  20.     end,
  21. -- snip

Result : Nothing changed.


Last edited by Kagura : 09-16-14 at 09:15 AM.
  Reply With Quote
09-16-14, 09:30 AM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You can try changing the y offset to -10.5 and seeing if that makes any difference, but it's bizarre that you would have two identical buttons and only one of them is moving.

What happens if you create a frame inside of the scroll child and set your points relative to that?

Or setting button2's point relative to button1's?

If it's an issue with the scroll frame it should be affecting both of them, not individually. I've used scroll frames extensively to crop things and never managed to have one element inside of it misaligned with another one of the elements.

For example this entire map is made up of a grid of images inside of a scroll frame set with their top left corners aligned relative to the scroll child, like you're doing, if they weren't aligned it would be pretty obvious.


You can see the separate tiles here..

Last edited by semlar : 09-16-14 at 09:40 AM.
  Reply With Quote
09-16-14, 09:46 AM   #5
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Maybe it could be helpful to see all of your code.
  Reply With Quote
09-16-14, 10:03 AM   #6
Kagura
A Fallenroot Satyr
Join Date: Nov 2008
Posts: 21
OK, that actually helped. Placing these buttons directly as a child of the scroll child gives this behavior. If you place it in a frame inside the scroll child, the problem goes away:

@Duugu : my whole code for the window is in my original post. Posting every piece of code that makes that possible would be a huge overload here.

I tried recreating this without using any of my frameworks code and I can indeed reproduce it.

Lua Code:
  1. -- snip
  2.     postCreate = function (self)
  3.         self.content:createPanel({
  4.             offset = {0, 0, 0, 0},
  5.             createRegions = function (self)
  6.                 UI.Button:instance({
  7.                     parentFrame = self.frame,
  8.                     width = 100,
  9.                     height = 20,
  10.                     text = 'Close',
  11.                     offset = {0, nil, 10, nil}
  12.                 })
  13.  
  14.                 UI.Button:instance({
  15.                     parentFrame = self.frame,
  16.                     width = 100,
  17.                     height = 20,
  18.                     text = 'Close',
  19.                     offset = {101, nil, 10, nil}
  20.                 })
  21.             end,
  22.         })
  23.     end,
  24. -- snip
  Reply With Quote
09-16-14, 10:35 AM   #7
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Alright, I am able to reproduce this and it appears to be the same bug that I've previously run into with font strings inside of scrollframes, but I didn't know it also affected buttons.

This is a picture from an old attempt I had made at using a scroll frame to make text appear to fill up with a different color, but I had to scrap it because the border was freaking out when the frame was moved. The number on the bottom is the same thing using textures instead of font strings, and is not bugged.


It only affects the vertical movement, and I never found a way around it. As far as I could tell it was a bug with how the contents of the scrollframe are rendered.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » ScrollFrame behavior


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