comparison Libs/DF/dropdown.lua @ 39:7944c081e5b4

- framework update. - ToC Update.
author Tercio
date Tue, 19 Jul 2016 13:23:40 -0300
parents 5da06cb420d4
children a960d5372b0c
comparison
equal deleted inserted replaced
38:219f04e5ba55 39:7944c081e5b4
14 local loadstring = loadstring --> lua local 14 local loadstring = loadstring --> lua local
15 local _string_len = string.len --> lua local 15 local _string_len = string.len --> lua local
16 16
17 local cleanfunction = function() end 17 local cleanfunction = function() end
18 local APIDropDownFunctions = false 18 local APIDropDownFunctions = false
19 local DropDownMetaFunctions = {} 19
20 do
21 local metaPrototype = {
22 WidgetType = "dropdown",
23 SetHook = DF.SetHook,
24 RunHooksForWidget = DF.RunHooksForWidget,
25 }
26
27 _G [DF.GlobalWidgetControlNames ["dropdown"]] = _G [DF.GlobalWidgetControlNames ["dropdown"]] or metaPrototype
28 end
29
30 local DropDownMetaFunctions = _G [DF.GlobalWidgetControlNames ["dropdown"]]
20 31
21 ------------------------------------------------------------------------------------------------------------ 32 ------------------------------------------------------------------------------------------------------------
22 --> metatables 33 --> metatables
23 34
24 DropDownMetaFunctions.__call = function (_table, value) 35 DropDownMetaFunctions.__call = function (_table, value)
63 --> menu height 74 --> menu height
64 local gmember_menuheight = function (_object) 75 local gmember_menuheight = function (_object)
65 return _rawget (self, "realsizeH") 76 return _rawget (self, "realsizeH")
66 end 77 end
67 78
68 local get_members_function_index = { 79 DropDownMetaFunctions.GetMembers = DropDownMetaFunctions.GetMembers or {}
69 ["value"] = gmember_value, 80 DropDownMetaFunctions.GetMembers ["value"] = gmember_value
70 ["text"] = gmember_text, 81 DropDownMetaFunctions.GetMembers ["text"] = gmember_text
71 ["shown"] = gmember_shown, 82 DropDownMetaFunctions.GetMembers ["shown"] = gmember_shown
72 ["width"] = gmember_width, 83 DropDownMetaFunctions.GetMembers ["width"] = gmember_width
73 ["menuwidth"] = gmember_menuwidth, 84 DropDownMetaFunctions.GetMembers ["menuwidth"] = gmember_menuwidth
74 ["height"] = gmember_height, 85 DropDownMetaFunctions.GetMembers ["height"] = gmember_height
75 ["menuheight"] = gmember_menuheight, 86 DropDownMetaFunctions.GetMembers ["menuheight"] = gmember_menuheight
76 ["tooltip"] = gmember_tooltip, 87 DropDownMetaFunctions.GetMembers ["tooltip"] = gmember_tooltip
77 ["func"] = gmember_function, 88 DropDownMetaFunctions.GetMembers ["func"] = gmember_function
78 }
79 89
80 DropDownMetaFunctions.__index = function (_table, _member_requested) 90 DropDownMetaFunctions.__index = function (_table, _member_requested)
81 91
82 local func = get_members_function_index [_member_requested] 92 local func = DropDownMetaFunctions.GetMembers [_member_requested]
83 if (func) then 93 if (func) then
84 return func (_table, _member_requested) 94 return func (_table, _member_requested)
85 end 95 end
86 96
87 local fromMe = _rawget (_table, _member_requested) 97 local fromMe = _rawget (_table, _member_requested)
133 --> menu height 143 --> menu height
134 local smember_menuheight = function (_object, _value) 144 local smember_menuheight = function (_object, _value)
135 _object:SetMenuSize (nil, _value) 145 _object:SetMenuSize (nil, _value)
136 end 146 end
137 147
138 local set_members_function_index = { 148 DropDownMetaFunctions.SetMembers = DropDownMetaFunctions.SetMembers or {}
139 ["tooltip"] = smember_tooltip, 149 DropDownMetaFunctions.SetMembers ["tooltip"] = smember_tooltip
140 ["show"] = smember_show, 150 DropDownMetaFunctions.SetMembers ["show"] = smember_show
141 ["hide"] = smember_hide, 151 DropDownMetaFunctions.SetMembers ["hide"] = smember_hide
142 ["width"] = smember_width, 152 DropDownMetaFunctions.SetMembers ["width"] = smember_width
143 ["menuwidth"] = smember_menuwidth, 153 DropDownMetaFunctions.SetMembers ["menuwidth"] = smember_menuwidth
144 ["height"] = smember_height, 154 DropDownMetaFunctions.SetMembers ["height"] = smember_height
145 ["menuheight"] = smember_menuheight, 155 DropDownMetaFunctions.SetMembers ["menuheight"] = smember_menuheight
146 ["func"] = smember_function, 156 DropDownMetaFunctions.SetMembers ["func"] = smember_function
147 }
148 157
149 DropDownMetaFunctions.__newindex = function (_table, _key, _value) 158 DropDownMetaFunctions.__newindex = function (_table, _key, _value)
150 local func = set_members_function_index [_key] 159 local func = DropDownMetaFunctions.SetMembers [_key]
151 if (func) then 160 if (func) then
152 return func (_table, _value) 161 return func (_table, _value)
153 else 162 else
154 return _rawset (_table, _key, _value) 163 return _rawset (_table, _key, _value)
155 end 164 end
281 end 290 end
282 291
283 --> fixed value 292 --> fixed value
284 function DropDownMetaFunctions:SetFixedParameter (value) 293 function DropDownMetaFunctions:SetFixedParameter (value)
285 _rawset (self, "FixedValue", value) 294 _rawset (self, "FixedValue", value)
286 end
287
288 --> hooks
289 function DropDownMetaFunctions:SetHook (hookType, func)
290 if (func) then
291 _rawset (self, hookType.."Hook", func)
292 else
293 _rawset (self, hookType.."Hook", nil)
294 end
295 end 295 end
296 296
297 ------------------------------------------------------------------------------------------------------------ 297 ------------------------------------------------------------------------------------------------------------
298 --> scripts 298 --> scripts
299 299
750 750
751 end 751 end
752 752
753 function DetailsFrameworkDropDownOnEnter (self) 753 function DetailsFrameworkDropDownOnEnter (self)
754 754
755 if (self.MyObject.OnEnterHook) then 755 local capsule = self.MyObject
756 local interrupt = self.MyObject.OnEnterHook (self) 756 local kill = capsule:RunHooksForWidget ("OnEnter", self, capsule)
757 if (interrupt) then 757 if (kill) then
758 return 758 return
759 end
760 end 759 end
761 760
762 if (self.MyObject.onenter_backdrop) then 761 if (self.MyObject.onenter_backdrop) then
763 self:SetBackdropColor (unpack (self.MyObject.onenter_backdrop)) 762 self:SetBackdropColor (unpack (self.MyObject.onenter_backdrop))
764 else 763 else
785 end 784 end
786 785
787 end 786 end
788 787
789 function DetailsFrameworkDropDownOnLeave (self) 788 function DetailsFrameworkDropDownOnLeave (self)
790 if (self.MyObject.OnLeaveHook) then 789 local capsule = self.MyObject
791 local interrupt = self.MyObject.OnLeaveHook (self) 790 local kill = capsule:RunHooksForWidget ("OnLeave", self, capsule)
792 if (interrupt) then 791 if (kill) then
793 return 792 return
794 end
795 end 793 end
796 794
797 if (self.MyObject.onleave_backdrop) then 795 if (self.MyObject.onleave_backdrop) then
798 self:SetBackdropColor (unpack (self.MyObject.onleave_backdrop)) 796 self:SetBackdropColor (unpack (self.MyObject.onleave_backdrop))
799 else 797 else
814 function DetailsFrameworkDropDownOnSizeChanged (self, w, h) 812 function DetailsFrameworkDropDownOnSizeChanged (self, w, h)
815 self.MyObject.label:SetSize (self:GetWidth()-40, 10) 813 self.MyObject.label:SetSize (self:GetWidth()-40, 10)
816 end 814 end
817 815
818 function DetailsFrameworkDropDownOnShow (self) 816 function DetailsFrameworkDropDownOnShow (self)
819 if (self.MyObject and self.MyObject.OnShowHook) then 817 local capsule = self.MyObject
820 local interrupt = self.MyObject.OnShowHook (self) 818 local kill = capsule:RunHooksForWidget ("OnShow", self, capsule)
821 if (interrupt) then 819 if (kill) then
822 return 820 return
823 end
824 end 821 end
825 end 822 end
826 823
827 function DetailsFrameworkDropDownOnHide (self) 824 function DetailsFrameworkDropDownOnHide (self)
828 if (self.MyObject and self.MyObject.OnHideHook) then 825 local capsule = self.MyObject
829 local interrupt = self.MyObject.OnHideHook (self) 826 local kill = capsule:RunHooksForWidget ("OnHide", self, capsule)
830 if (interrupt) then 827 if (kill) then
831 return 828 return
832 end
833 end 829 end
834 830
835 self.MyObject:Close() 831 self.MyObject:Close()
836 end 832 end
837 833
932 if (default == nil) then 928 if (default == nil) then
933 default = 1 929 default = 1
934 end 930 end
935 931
936 --> default members: 932 --> default members:
937 --> hooks
938 DropDownObject.OnEnterHook = nil
939 DropDownObject.OnLeaveHook = nil
940 DropDownObject.OnHideHook = nil
941 DropDownObject.OnShowHook = nil
942 DropDownObject.OnMouseDownHook = nil
943 --> misc 933 --> misc
944 DropDownObject.container = container 934 DropDownObject.container = container
945 DropDownObject.have_tooltip = nil
946 935
947 DropDownObject.dropdown = CreateFrame ("Button", name, parent, "DetailsFrameworkDropDownTemplate") 936 DropDownObject.dropdown = CreateFrame ("Button", name, parent, "DetailsFrameworkDropDownTemplate")
948 DropDownObject.widget = DropDownObject.dropdown 937 DropDownObject.widget = DropDownObject.dropdown
949 938
950 DropDownObject.__it = {nil, nil} 939 DropDownObject.__it = {nil, nil}
1000 --button_down_scripts (DropDownObject, scroll.slider, scroll.baixo) 989 --button_down_scripts (DropDownObject, scroll.slider, scroll.baixo)
1001 990
1002 DropDownObject:HideScroll() 991 DropDownObject:HideScroll()
1003 DropDownObject.label:SetSize (DropDownObject.dropdown:GetWidth()-40, 10) 992 DropDownObject.label:SetSize (DropDownObject.dropdown:GetWidth()-40, 10)
1004 993
994 DropDownObject.HookList = {
995 OnEnter = {},
996 OnLeave = {},
997 OnHide = {},
998 OnShow = {},
999 }
1000
1001 DropDownObject.dropdown:SetScript ("OnShow", DetailsFrameworkDropDownOnShow)
1002 DropDownObject.dropdown:SetScript ("OnHide", DetailsFrameworkDropDownOnHide)
1003 DropDownObject.dropdown:SetScript ("OnEnter", DetailsFrameworkDropDownOnEnter)
1004 DropDownObject.dropdown:SetScript ("OnLeave", DetailsFrameworkDropDownOnLeave)
1005
1005 --> setup class 1006 --> setup class
1006 _setmetatable (DropDownObject, DropDownMetaFunctions) 1007 _setmetatable (DropDownObject, DropDownMetaFunctions)
1007 1008
1008 --> initialize first menu selected 1009 --> initialize first menu selected
1009
1010 if (type (default) == "string") then 1010 if (type (default) == "string") then
1011 DropDownObject:Select (default) 1011 DropDownObject:Select (default)
1012 1012
1013 elseif (type (default) == "number") then 1013 elseif (type (default) == "number") then
1014 if (not DropDownObject:Select (default)) then 1014 if (not DropDownObject:Select (default)) then
1018 1018
1019 if (template) then 1019 if (template) then
1020 DropDownObject:SetTemplate (template) 1020 DropDownObject:SetTemplate (template)
1021 end 1021 end
1022 1022
1023 return DropDownObject 1023 return DropDownObject
1024 1024
1025 end 1025 end