WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   ACE3 need help with this custom widget (https://www.wowinterface.com/forums/showthread.php?t=57223)

galvin 06-23-19 06:00 PM

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)


myrroddin 06-24-19 08:08 PM

What widget are you trying to create?

galvin 06-25-19 01:12 AM

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)


myrroddin 06-26-19 06:10 PM

Why did you create a new widget entirely? You could have used the Dropdown widget that already exists in AceGUI.

galvin 07-04-19 09:14 PM

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


All times are GMT -6. The time now is 07:41 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI