2525-- @class file
2626-- @name AceGUI-3.0
2727-- @release $Id$
28- local ACEGUI_MAJOR , ACEGUI_MINOR = " AceGUI-3.0" , 41
28+ local ACEGUI_MAJOR , ACEGUI_MINOR = " AceGUI-3.0" , 50
2929local AceGUI , oldminor = LibStub :NewLibrary (ACEGUI_MAJOR , ACEGUI_MINOR )
3030
3131if not AceGUI then return end -- No upgrade needed
@@ -40,12 +40,29 @@ local math_max, math_min, math_ceil = math.max, math.min, math.ceil
4040-- WoW APIs
4141local UIParent = UIParent
4242
43+ AceGUI .STYLE_CLASSIC = " classic"
44+ AceGUI .STYLE_MODERN = " modern"
45+
4346AceGUI .WidgetRegistry = AceGUI .WidgetRegistry or {}
4447AceGUI .LayoutRegistry = AceGUI .LayoutRegistry or {}
4548AceGUI .WidgetBase = AceGUI .WidgetBase or {}
4649AceGUI .WidgetContainerBase = AceGUI .WidgetContainerBase or {}
4750AceGUI .WidgetVersions = AceGUI .WidgetVersions or {}
4851AceGUI .tooltip = AceGUI .tooltip or CreateFrame (" GameTooltip" , " AceGUITooltip" , UIParent , " GameTooltipTemplate" )
52+ AceGUI .counts = AceGUI .counts or {}
53+
54+ -- migrate widget registry to per-style layout
55+ if oldminor and oldminor < 50 then
56+ local Registry = AceGUI .WidgetRegistry
57+ local Versions = AceGUI .WidgetVersions
58+
59+ AceGUI .WidgetRegistry = { [AceGUI .STYLE_CLASSIC ] = Registry }
60+ AceGUI .WidgetVersions = { [AceGUI .STYLE_CLASSIC ] = Versions }
61+
62+ -- migrate widget counts
63+ local counts = AceGUI .counts
64+ AceGUI .counts = { [AceGUI .STYLE_CLASSIC ] = counts }
65+ end
4966
5067-- local upvalues
5168local WidgetRegistry = AceGUI .WidgetRegistry
88105 AceGUI .objPools = AceGUI .objPools or {}
89106 local objPools = AceGUI .objPools
90107 -- Returns a new instance, if none are available either returns a new table or calls the given contructor
91- function newWidget (widgetType )
92- if not WidgetRegistry [widgetType ] then
108+ function newWidget (widgetType , style )
109+ if not WidgetRegistry [style ] or not WidgetRegistry [ style ][ widgetType ] then
93110 error (" Attempt to instantiate unknown widget type" , 2 )
94111 end
95112
96- if not objPools [widgetType ] then
97- objPools [widgetType ] = {}
113+ local poolKey = widgetType .. style
114+ if not objPools [poolKey ] then
115+ objPools [poolKey ] = {}
98116 end
99117
100- local newObj = next (objPools [widgetType ])
118+ local newObj = next (objPools [poolKey ])
101119 if not newObj then
102- newObj = WidgetRegistry [widgetType ]()
103- newObj .AceGUIWidgetVersion = WidgetVersions [widgetType ]
120+ newObj = WidgetRegistry [style ][widgetType ]()
121+ newObj .AceGUIWidgetVersion = WidgetVersions [style ][widgetType ]
122+ -- save the style for future recycling
123+ newObj .AceGUIWidgetStyle = style
104124 else
105- objPools [widgetType ][newObj ] = nil
125+ objPools [poolKey ][newObj ] = nil
106126 -- if the widget is older then the latest, don't even try to reuse it
107127 -- just forget about it, and grab a new one.
108- if not newObj .AceGUIWidgetVersion or newObj .AceGUIWidgetVersion < WidgetVersions [widgetType ] then
109- return newWidget (widgetType )
128+ if not newObj .AceGUIWidgetVersion or newObj .AceGUIWidgetVersion < WidgetVersions [style ][ widgetType ] then
129+ return newWidget (widgetType , style )
110130 end
111131 end
112132 return newObj
113133 end
114134 -- Releases an instance to the Pool
115- function delWidget (obj ,widgetType )
116- if not objPools [widgetType ] then
117- objPools [widgetType ] = {}
135+ function delWidget (obj ,widgetType ,style )
136+ local poolKey = widgetType .. style
137+ if not objPools [poolKey ] then
138+ objPools [poolKey ] = {}
118139 end
119- if objPools [widgetType ][obj ] then
140+ if objPools [poolKey ][obj ] then
120141 error (" Attempt to Release Widget that is already released" , 2 )
121142 end
122- objPools [widgetType ][obj ] = true
143+ objPools [poolKey ][obj ] = true
123144 end
124145end
125146
@@ -134,10 +155,25 @@ end
134155-- This function will instantiate a new widget (or use one from the widget pool), and call the
135156-- OnAcquire function on it, before returning.
136157-- @param type The type of the widget.
158+ -- @param style The widget style to use. (true for auto-selection, string for a specific style; "classic", "modern")
137159-- @return The newly created widget.
138- function AceGUI :Create (widgetType )
139- if WidgetRegistry [widgetType ] then
140- local widget = newWidget (widgetType )
160+ function AceGUI :Create (widgetType , style )
161+ local widgetStyle
162+
163+ -- style auto-selection
164+ if style == true then
165+ -- TODO: support modern style once implemented
166+ widgetStyle = AceGUI .STYLE_CLASSIC
167+ elseif type (style ) == " string" then
168+ -- string-type styles specify a style directly
169+ widgetStyle = style :lower ()
170+ else
171+ -- fallback to classic style (default)
172+ widgetStyle = AceGUI .STYLE_CLASSIC
173+ end
174+
175+ if WidgetRegistry [widgetStyle ] and WidgetRegistry [widgetStyle ][widgetType ] then
176+ local widget = newWidget (widgetType , widgetStyle )
141177
142178 if rawget (widget , " Acquire" ) then
143179 widget .OnAcquire = widget .Acquire
@@ -203,7 +239,7 @@ function AceGUI:Release(widget)
203239 widget .content .height = nil
204240 end
205241 widget .isQueuedForRelease = nil
206- delWidget (widget , widget .type )
242+ delWidget (widget , widget .type , widget . AceGUIWidgetStyle or AceGUI . STYLE_CLASSIC )
207243end
208244
209245--- Check if a widget is currently in the process of being released
@@ -546,15 +582,25 @@ end
546582-- @param Name The name of the widget
547583-- @param Constructor The widget constructor function
548584-- @param Version The version of the widget
549- function AceGUI :RegisterWidgetType (Name , Constructor , Version )
585+ function AceGUI :RegisterWidgetType (Name , Constructor , Version , Style )
550586 assert (type (Constructor ) == " function" )
551587 assert (type (Version ) == " number" )
588+ assert (Style == nil or type (Style ) == " string" )
589+
590+ local widgetStyle = Style and Style :lower () or AceGUI .STYLE_CLASSIC
591+ if not WidgetRegistry [widgetStyle ] then
592+ WidgetRegistry [widgetStyle ] = {}
593+ end
594+
595+ if not WidgetVersions [widgetStyle ] then
596+ WidgetVersions [widgetStyle ] = {}
597+ end
552598
553- local oldVersion = WidgetVersions [Name ]
599+ local oldVersion = WidgetVersions [widgetStyle ][ Name ]
554600 if oldVersion and oldVersion >= Version then return end
555601
556- WidgetVersions [Name ] = Version
557- WidgetRegistry [Name ] = Constructor
602+ WidgetVersions [widgetStyle ][ Name ] = Version
603+ WidgetRegistry [widgetStyle ][ Name ] = Constructor
558604end
559605
560606--- Registers a Layout Function
@@ -577,31 +623,35 @@ function AceGUI:GetLayout(Name)
577623 return LayoutRegistry [Name ]
578624end
579625
580- AceGUI .counts = AceGUI .counts or {}
581-
582626--- A type-based counter to count the number of widgets created.
583627-- This is used by widgets that require a named frame, e.g. when a Blizzard
584628-- Template requires it.
585- -- @param type The widget type
586- function AceGUI :GetNextWidgetNum (widgetType )
587- if not self .counts [widgetType ] then
588- self .counts [widgetType ] = 0
629+ -- @param widgetType The widget type
630+ -- @param widgetStyle The widget style
631+ function AceGUI :GetNextWidgetNum (widgetType , widgetStyle )
632+ local style = widgetStyle and widgetStyle :lower () or AceGUI .STYLE_CLASSIC
633+ if not self .counts [style ] then
634+ self .counts [style ] = {}
589635 end
590- self .counts [widgetType ] = self .counts [widgetType ] + 1
591- return self .counts [widgetType ]
636+ self .counts [style ][ widgetType ] = ( self .counts [style ][ widgetType ] or 0 ) + 1
637+ return self .counts [style ][ widgetType ]
592638end
593639
594640--- Return the number of created widgets for this type.
595641-- In contrast to GetNextWidgetNum, the number is not incremented.
596642-- @param widgetType The widget type
597- function AceGUI :GetWidgetCount (widgetType )
598- return self .counts [widgetType ] or 0
643+ -- @param widgetStyle The widget style
644+ function AceGUI :GetWidgetCount (widgetType , widgetStyle )
645+ local style = widgetStyle and widgetStyle :lower () or AceGUI .STYLE_CLASSIC
646+ return self .counts [style ] and self .counts [style ][widgetType ] or 0
599647end
600648
601649--- Return the version of the currently registered widget type.
602650-- @param widgetType The widget type
603- function AceGUI :GetWidgetVersion (widgetType )
604- return WidgetVersions [widgetType ]
651+ -- @param widgetStyle The widget style
652+ function AceGUI :GetWidgetVersion (widgetType , widgetStyle )
653+ local style = widgetStyle and widgetStyle :lower () or AceGUI .STYLE_CLASSIC
654+ return WidgetVersions [style ] and WidgetVersions [style ][widgetType ] or nil
605655end
606656
607657---- ---------
0 commit comments