View Single Post
05/10/16, 04:24 PM   #9
Letho
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 238
Heyho,

I'm currently having trouble setting up a scrollable area and stumbled upon this thread as i did some research with google. I'd like to set up a scrollable area from scratch, that means not using any inherited or predefined control/code written by zenimax. Sadly I have no clue how the scroll control works. I found a cheap and dirty workaround, but it's not really working well for it throws some lua errors:

Here is what i did:
1. defined a scrollbar using a slider-control.
2. defined a control of type "CT_SCROLL" (name="ScrollChild") and added a regular CT_CONTROL (name="ScrollingContainer") to it.
3. Using the slider's "OnValueChanged" - event i simply modify the "ScrollingContainer"'s anchor-offset by clearing it's anchors and adding a new one with the new y-offset. Because ScrollingContainer is a child-element of the CT_SCROLL every content displayed "outside" the CT_SCOLL wont be displayed for CT_CONTROL seems to behave like an HTML div-container with overflow:hidden.

This results in the desired behaviour but also throws the "too many anchors processed" lua error - not to mention the low performance.

I'd really like how to implement scrolling areas in a proper way, could anybody help me?

Here's the code:

Lua Code:
  1. function AuraMastery:Tex() -- Shows Window with all icon textures on the screen
  2.     local container = WM:CreateTopLevelWindow("AMTextureContainer"); -- Main container
  3.    
  4.     local bg         = WM:CreateControl("$(parent)_Backdrop", container, CT_BACKDROP);
  5.  
  6.     local oX = 0;
  7.     local oY = 0;
  8.  
  9.     container:SetClampedToScreen(true);
  10.     container:SetDimensions(1600, 900);
  11.     container:ClearAnchors();
  12.     container:SetAnchor(CENTER, GuiRoot, CENTER);
  13.     container:SetAlpha(1);
  14.     container:SetMovable(true);
  15.     container:SetHidden(false);
  16.     container:SetMouseEnabled(true);
  17.  
  18.     bg:SetAnchorFill();
  19.     bg:SetCenterColor(0,0,0,.4);
  20.     bg:SetEdgeTexture(nil, 1, 1, 1, 0);
  21.     bg:SetEdgeColor(1,1,1,.12);
  22.  
  23.     -- Scrollable area that hides everything that expands beyond it's own size
  24.     local scrollChild = WM:CreateControl("$(parent)_ScrollChild", container, CT_SCROLL);
  25.     scrollChild:SetDimensions(1575,900);
  26.     scrollChild:SetAnchor(TOPLEFT, container, TOPLEFT, 0, 0);
  27.     scrollChild:SetScrollBounding(SCROLL_BOUNDING_CONTAINED);
  28.  
  29.     scrollChild.bg = WM:CreateControl("$(parent)_Backdrop", scrollChild, CT_BACKDROP);
  30.     scrollChild.bg:SetAnchorFill();
  31.     scrollChild.bg:SetCenterColor(1,0,0,.1);
  32.     scrollChild.bg:SetEdgeTexture(nil, 1, 1, 1, 0);
  33.     scrollChild.bg:SetEdgeColor(0,0,0,0);
  34.  
  35.         -- This containers Y-Offset will be modified by our scrollbar-value, hiding it's parts that expand beyong the CT_SCROLL's size
  36.     local scrollContainer = WM:CreateControl("AuraMastery_ScrollContainer", scrollChild, CT_CONTROL)
  37.     scrollContainer:SetDimensions(1575,900);
  38.     scrollContainer:SetAnchor(TOPLEFT, container, TOPLEFT, 0, -(padding+iconSize));
  39.     scrollContainer:SetResizeToFitDescendents(true);
  40.     scrollContainer.bg = WM:CreateControl("$(parent)_Backdrop", scrollContainer, CT_BACKDROP);
  41.     scrollContainer.bg:SetAnchorFill();
  42.     scrollContainer.bg:SetCenterColor(0,0,1,.1);
  43.     scrollContainer.bg:SetEdgeTexture(nil, 1, 1, 1, 0);
  44.     scrollContainer.bg:SetEdgeColor(0,0,0,0);
  45.  
  46.     -- SCROLLBAR
  47.     local scrollBar = WM:CreateControl("$(parent)_ScrollBar", container, CT_SLIDER);
  48.     scrollBar:SetDimensions(25, 900);
  49.     scrollBar:SetAnchor(TOPRIGHT, container, TOPRIGHT);
  50.     scrollBar:SetOrientation(ORIENTATION_VERTICAL);
  51.     scrollBar:SetMouseEnabled(true);
  52.     scrollBar:SetMinMax(0,900);
  53.     scrollBar:SetThumbTexture(nil,nil, nil, 25, 25);
  54.     scrollBar:SetValueStep(padding+iconSize);
  55.         -- backdrop
  56.         scrollBar.bg = WM:CreateControl("$(parent)_Backdrop", scrollBar, CT_BACKDROP);
  57.         scrollBar.bg:SetAnchor(TOPLEFT, slider, TOPLEFT, 0, 4)
  58.         scrollBar.bg:SetAnchor(BOTTOMRIGHT, slider, BOTTOMRIGHT, 0, -4)
  59.         scrollBar.bg:SetCenterColor(0,0,0);
  60.         scrollBar.bg:SetEdgeTexture(nil, 1, 1, 1, 0);
  61.         scrollBar.bg:SetEdgeColor(0,0,0,0);
  62.  
  63.     scrollBar:SetHandler("OnValueChanged", function(self) AuraMastery:Scroll(); d(self:GetValue()); end);
  64.  
  65.          -- self.icons contains that path to every texture of type "icon" in the game (e.g.:  [1] = Esoui/art/icons/.../textureName.dds
  66.     for k,v in pairs(self.icons) do
  67.         local modX = (k-1)%29; -- display only 29 icons of size 48px per row!
  68.         local modY = math.floor((k-1)/29);
  69.  
  70.         oX = (modX*iconSize)+((modX+1)*padding);
  71.         oY = (modY*iconSize)+((modY+1)*padding);
  72.  
  73.                 -- button is needed for displaying a tooltip on mouseOver (doesnt work on CT_TEXTURE)
  74.         local iconContainer = WM:CreateControl("Icon"..k, scrollContainer, CT_BUTTON);
  75.         iconContainer:SetDimensions(iconSize, iconSize);
  76.         iconContainer:SetAnchor(TOPLEFT, scrollContainer, TOPLEFT, oX, oY);
  77.         iconContainer.iconnr = k;
  78.  
  79.                 -- the icon texture...
  80.         local icon = WM:CreateControl("$(parent)_Texture"..k, iconContainer, CT_TEXTURE);
  81.         icon:SetAnchorFill();
  82.         icon:SetDimensions(iconSize,iconSize);
  83.         icon:SetTexture(v);
  84.                 -- ... and it's tooltip; SetHidden(false) on mouseover
  85.         local iconTooltip = WM:CreateControl("$(parent)_Tooltip", iconContainer, CT_CONTROL);
  86.         iconTooltip:SetHidden(true);
  87.         iconTooltip:SetDimensions(320,48);
  88.         iconTooltip:SetAnchor(BOTTOM, iconContainer, TOP);
  89.  
  90.         iconTooltip.bg = WM:CreateControl("$(parent)_Backdrop", iconTooltip, CT_BACKDROP);
  91.         iconTooltip.bg:SetAnchorFill();
  92.         iconTooltip.bg:SetDrawLayer(1);
  93.         iconTooltip.bg:SetCenterColor(0,0,0,1);
  94.         iconTooltip.bg:SetEdgeTexture(nil,1,1,1,0);
  95.         iconTooltip.bg:SetEdgeColor(1,1,1,.12);
  96.  
  97.         iconTooltip.label = WM:CreateControl("$(parent)_Label", iconTooltip, CT_LABEL);
  98.         iconTooltip.label:SetAnchorFill();
  99.         iconTooltip.label:SetFont("$(BOLD_FONT)|18|outline");
  100.         iconTooltip.label:SetColor(1,1,1,1);
  101.         iconTooltip.label:SetText(v);
  102.  
  103.         iconContainer:SetHandler("OnMouseEnter", function(self) AuraMastery:Tooltip(self.iconnr); end);
  104.         iconContainer:SetHandler("OnMouseExit", function(self) AuraMastery:Tooltip(self.iconnr); end);
  105.     end
  106.  
  107. end
  108.  
  109. function AuraMastery:Scroll()
  110.     local offset = WM:GetControlByName("AMTextureContainer_ScrollBar"):GetValue();
  111.     local control = WM:GetControlByName("AuraMastery_ScrollContainer");
  112.     control:ClearAnchors();
  113.     control:SetSimpleAnchor(scrollChild, 0, -offset);
  114. end









Scrolled down one step (1 step = height of one row of icons, padding included):


Cheers,
Letho

Last edited by Letho : 05/10/16 at 05:08 PM. Reason: adding code
  Reply With Quote