Thread Tools Display Modes
06-23-19, 06:00 PM   #1
galvin
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 265
ACE3 need help with this custom widget

This is a test widget that I need to fully work before I can begin my real work
This appears to work at first, but soon as the widget gets released it breaks.
Here's a video of it breaking
https://www.youtube.com/watch?v=XxK4dMjfG2Q

Code:
local WidgetVersion = 1
local WidgetType = 'GUB_TEST'

AceGUI:RegisterLayout('TestLayout',
  function(Content, Children)
    local Child = Children[1]
    local DropdownFrame = Child.frame

    DropdownFrame:ClearAllPoints()
    DropdownFrame:SetPoint('TOPLEFT', Content, 0, 1)
    DropdownFrame:Show()

    Child:SetWidth(Content:GetWidth() or 0)
    Child:SetHeight(Content:GetHeight() or 0)
    Child.frame:Show()
  end)

local function TestOnAcquire(Widget)
  local Dropdown = AceGUI:Create('Dropdown')

  Widget:SetLayout('TestLayout')
  Widget.SetLayout = function() end

  Widget:AddChild(Dropdown)
  Widget.Dropdown = Dropdown
end

local function TestOnRelease(Widget)
  Widget.Dropdown.frame:ClearAllPoints()
  Widget:SetDisabled(false)
  Widget.Dropdown = nil
end

local function TestConstructor()
  local Frame = CreateFrame('Frame', nil, UIParent)
  Frame:SetSize(50, 50)

  local Content = CreateFrame('Frame', nil, Frame)
  Content:SetAllPoints()

  local Widget = {
    frame = Frame,
    content = Content,
    type = WidgetType
  }

  -- methods
  Widget.OnRelease = TestOnRelease
  Widget.OnAcquire = TestOnAcquire

  Widget.SetText      = function(self, ...) Widget.Dropdown:SetText(...) end
  Widget.SetLabel     = function(self, ...) Widget.Dropdown:SetLabel(...) end
  Widget.SetValue     = function(self, ...) Widget.Dropdown:SetValue(...) end
  Widget.GetValue     = function(self, ...) Widget.Dropdown:GetValue(...) end
  Widget.SetList      = function(self, ...) Widget.Dropdown:SetList(...) end
  Widget.SetDisabled  = function(self, ...) Widget.Dropdown:SetDisabled(...) end

  return AceGUI:RegisterAsContainer(Widget)
end

AceGUI:RegisterWidgetType(WidgetType, TestConstructor, WidgetVersion)
  Reply With Quote
06-24-19, 08:08 PM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
What widget are you trying to create?
  Reply With Quote
06-25-19, 01:12 AM   #3
galvin
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 265
I fixed this with help. Its a solution that appears to work from my testing. And implemented it in my latest release found here https://wow.curseforge.com/projects/...unitbars/files

What it looks like
https://i.imgur.com/XaW7t1W.jpg


The fix is below

Code:
-- Setup pullout
local function SetupPullout(Widget)
  local Dropdown = Widget.dropdown
  local Pullout = Widget.pullout
  local Slider = Pullout.slider
  local ScrollFrame = Pullout.scrollFrame
  local ItemFrame = Pullout.itemFrame

  -- Store original values in userdata
  local UserData = WidgetUserData[Widget]
  if UserData == nil then
    UserData = {}
    WidgetUserData[Widget] = UserData
  end
  local SliderPoints = {}

  -- Save all points
  UserData.SliderPoints = SliderPoints
  for PointIndex = 1, Slider:GetNumPoints() do
    SliderPoints[PointIndex] = { Slider:GetPoint(PointIndex) }
  end

  -- Setup the pullout width and height
  UserData.MaxHeight = Pullout.maxHeight
  Pullout:SetMaxHeight(188)
  Widget:SetPulloutWidth(280)

  -- Move slider a few pixels to the left and make it easier to click
  Slider:SetHitRectInsets(-5, 0, -10, 0)

  UserData.SliderWidth = Slider:GetWidth()
  Slider:SetWidth(12)

  Slider:ClearAllPoints()
  Slider:SetPoint('TOPLEFT', ScrollFrame, 'TOPRIGHT', -20, 0)
  Slider:SetPoint('BOTTOMLEFT', ScrollFrame, 'BOTTOMRIGHT', -20, 0)

  -- Lower the strata of the itemframe so the slider is easier to click
  -- Slider frame strata was set to 'TOOLTIP'
  UserData.ItemFrameStrata = ItemFrame:GetFrameStrata()
  ItemFrame:SetFrameStrata('FULLSCREEN_DIALOG')
end

-- Restore pullout
local function RestorePullout(Widget)
  local UserData = WidgetUserData[Widget]
  local SliderPoints = UserData.SliderPoints
  local Pullout = Widget.pullout
  local Slider = Pullout.slider

  Slider:SetWidth(UserData.SliderWidth)
  Slider:SetHitRectInsets(0, 0, -10, 0)
  Slider:ClearAllPoints()
  for PointIndex = 1, #SliderPoints do
    Slider:SetPoint(unpack(SliderPoints[PointIndex]))
  end
  Pullout:SetMaxHeight(UserData.MaxHeight)
  Pullout.itemFrame:SetFrameStrata(UserData.ItemFrameStrata)

  WidgetUserData[Widget] = nil
end

-------------------------------------------------------------------------------
-- DropdownSelectConstructor
--
-- This uses an existing widget, then changes it into a custom
-- This make a menu have a scroll bar
-------------------------------------------------------------------------------
local function DropdownSelectConstructor()
  local Widget = AceGUI:Create('Dropdown')
  Widget.type = DropdownSelectWidgetType

  -- methods
  local OldOnRelease = Widget.OnRelease
  local OldOnAcquire = Widget.OnAcquire

  Widget.OnRelease = function(self, ...)
    RestorePullout(self)
    OldOnRelease(self, ...)
  end
  Widget.OnAcquire = function(self, ...)
    -- Only call OnAcquire if there is no pullout created
    -- This prevents two calls. Once during Create and
    -- again when this custom control is created
    if Widget.pullout == nil then
      OldOnAcquire(self, ...)
    end

    SetupPullout(self)
  end

  return AceGUI:RegisterAsWidget(Widget)
end

AceGUI:RegisterWidgetType(DropdownSelectWidgetType, DropdownSelectConstructor, DropdownSelectWidgetVersion)
  Reply With Quote
06-26-19, 06:10 PM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Why did you create a new widget entirely? You could have used the Dropdown widget that already exists in AceGUI.
  Reply With Quote
07-04-19, 09:14 PM   #5
galvin
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 265
There are issues with the existing dropdown. Only change I made was make the scrollbar draw properly. And make it show around 10 items before the bar shows up.

The rest is all acegui
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » ACE3 need help with this custom widget

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