comparison Libs/AceGUI-3.0/widgets/AceGUIWidget-ScrollFrame.lua @ 0:169f5211fc7f

First public revision. At this point ItemAuditor watches mail for auctions sold or purchased, watches for buy/sell (money and 1 item type change) and conversions/tradeskills. Milling isn't working yet because there is too much time between the first event and the last event.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Thu, 20 May 2010 19:22:19 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:169f5211fc7f
1 local AceGUI = LibStub("AceGUI-3.0")
2
3 -- Lua APIs
4 local pairs, assert, type = pairs, assert, type
5 local min, max, floor = math.min, math.max, math.floor
6
7 -- WoW APIs
8 local CreateFrame, UIParent = CreateFrame, UIParent
9
10
11 -------------
12 -- Widgets --
13 -------------
14 --[[
15 Widgets must provide the following functions
16 Acquire() - Called when the object is aquired, should set everything to a default hidden state
17 Release() - Called when the object is Released, should remove any anchors and hide the Widget
18
19 And the following members
20 frame - the frame or derivitive object that will be treated as the widget for size and anchoring purposes
21 type - the type of the object, same as the name given to :RegisterWidget()
22
23 Widgets contain a table called userdata, this is a safe place to store data associated with the wigdet
24 It will be cleared automatically when a widget is released
25 Placing values directly into a widget object should be avoided
26
27 If the Widget can act as a container for other Widgets the following
28 content - frame or derivitive that children will be anchored to
29
30 The Widget can supply the following Optional Members
31
32
33 ]]
34
35 --------------------------
36 -- Scroll Frame --
37 --------------------------
38 do
39 local Type = "ScrollFrame"
40 local Version = 9
41
42 local function OnAcquire(self)
43
44 end
45
46 local function OnRelease(self)
47 self.frame:ClearAllPoints()
48 self.frame:Hide()
49 self.status = nil
50 -- do SetScroll after niling status, but before clearing localstatus
51 -- so the scroll value isnt populated back into status, but not kept in localstatus either
52 self:SetScroll(0)
53 for k in pairs(self.localstatus) do
54 self.localstatus[k] = nil
55 end
56 self.scrollframe:SetPoint("BOTTOMRIGHT",self.frame,"BOTTOMRIGHT",0,0)
57 self.scrollbar:Hide()
58 self.scrollBarShown = nil
59 self.content.height, self.content.width = nil, nil
60 end
61
62 local function SetScroll(self, value)
63 local status = self.status or self.localstatus
64 local viewheight = self.scrollframe:GetHeight()
65 local height = self.content:GetHeight()
66 local offset
67
68 if viewheight > height then
69 offset = 0
70 else
71 offset = floor((height - viewheight) / 1000.0 * value)
72 end
73 self.content:ClearAllPoints()
74 self.content:SetPoint("TOPLEFT", self.scrollframe, "TOPLEFT", 0, offset)
75 self.content:SetPoint("TOPRIGHT", self.scrollframe, "TOPRIGHT", 0, offset)
76 status.offset = offset
77 status.scrollvalue = value
78 end
79
80 local function MoveScroll(self, value)
81 local status = self.status or self.localstatus
82 local height, viewheight = self.scrollframe:GetHeight(), self.content:GetHeight()
83
84 if height > viewheight then
85 self.scrollbar:Hide()
86 else
87 self.scrollbar:Show()
88 local diff = height - viewheight
89 local delta = 1
90 if value < 0 then
91 delta = -1
92 end
93 self.scrollbar:SetValue(min(max(status.scrollvalue + delta*(1000/(diff/45)),0), 1000))
94 end
95 end
96
97
98 local function FixScroll(self)
99 if self.updateLock then return end
100 self.updateLock = true
101 local status = self.status or self.localstatus
102 local height, viewheight = self.scrollframe:GetHeight(), self.content:GetHeight()
103 local offset = status.offset or 0
104 local curvalue = self.scrollbar:GetValue()
105 if viewheight < height then
106 if self.scrollBarShown then
107 self.scrollBarShown = nil
108 self.scrollbar:Hide()
109 self.scrollbar:SetValue(0)
110 self.scrollframe:SetPoint("BOTTOMRIGHT",self.frame,"BOTTOMRIGHT",0,0)
111 self:DoLayout()
112 end
113 else
114 if not self.scrollBarShown then
115 self.scrollBarShown = true
116 self.scrollbar:Show()
117 self.scrollframe:SetPoint("BOTTOMRIGHT", self.frame,"BOTTOMRIGHT",-20,0)
118 self:DoLayout()
119 end
120 local value = (offset / (viewheight - height) * 1000)
121 if value > 1000 then value = 1000 end
122 self.scrollbar:SetValue(value)
123 self:SetScroll(value)
124 if value < 1000 then
125 self.content:ClearAllPoints()
126 self.content:SetPoint("TOPLEFT", self.scrollframe, "TOPLEFT", 0, offset)
127 self.content:SetPoint("TOPRIGHT", self.scrollframe, "TOPRIGHT", 0, offset)
128 status.offset = offset
129 end
130 end
131 self.updateLock = nil
132 end
133
134 local function OnMouseWheel(this, value)
135 this.obj:MoveScroll(value)
136 end
137
138 local function OnScrollValueChanged(this, value)
139 this.obj:SetScroll(value)
140 end
141
142 local function FixScrollOnUpdate(this)
143 this:SetScript("OnUpdate", nil)
144 this.obj:FixScroll()
145 end
146
147 local function OnSizeChanged(this)
148 this:SetScript("OnUpdate", FixScrollOnUpdate)
149 end
150
151 local function LayoutFinished(self, width, height)
152 self.content:SetHeight(height or 0 + 20)
153 self.scrollframe:SetScript("OnUpdate", FixScrollOnUpdate)
154 end
155
156 -- called to set an external table to store status in
157 local function SetStatusTable(self, status)
158 assert(type(status) == "table")
159 self.status = status
160 if not status.scrollvalue then
161 status.scrollvalue = 0
162 end
163 end
164
165 local function OnWidthSet(self, width)
166 local content = self.content
167 content.width = width
168 end
169
170
171 local function OnHeightSet(self, height)
172 local content = self.content
173 content.height = height
174 end
175
176 local function Constructor()
177 local frame = CreateFrame("Frame", nil, UIParent)
178 local self = {}
179 self.type = Type
180
181 self.OnRelease = OnRelease
182 self.OnAcquire = OnAcquire
183
184 self.MoveScroll = MoveScroll
185 self.FixScroll = FixScroll
186 self.SetScroll = SetScroll
187 self.LayoutFinished = LayoutFinished
188 self.SetStatusTable = SetStatusTable
189 self.OnWidthSet = OnWidthSet
190 self.OnHeightSet = OnHeightSet
191
192 self.localstatus = {}
193 self.frame = frame
194 frame.obj = self
195
196 --Container Support
197 local scrollframe = CreateFrame("ScrollFrame", nil, frame)
198 scrollframe.obj = self
199 scrollframe:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, 0)
200 scrollframe:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 0, 0)
201 scrollframe:EnableMouseWheel(true)
202 scrollframe:SetScript("OnMouseWheel", OnMouseWheel)
203 scrollframe:SetScript("OnSizeChanged", OnSizeChanged)
204 self.scrollframe = scrollframe
205
206 local content = CreateFrame("Frame", nil, scrollframe)
207 content.obj = self
208 content:SetPoint("TOPLEFT", scrollframe, "TOPLEFT", 0, 0)
209 content:SetPoint("TOPRIGHT", scrollframe, "TOPRIGHT", 0, 0)
210 content:SetHeight(400)
211 self.content = content
212 scrollframe:SetScrollChild(content)
213
214 local num = AceGUI:GetNextWidgetNum(Type)
215 local name = ("AceConfigDialogScrollFrame%dScrollBar"):format(num)
216 local scrollbar = CreateFrame("Slider", name, scrollframe, "UIPanelScrollBarTemplate")
217 scrollbar.obj = self
218 scrollbar:SetPoint("TOPLEFT", scrollframe, "TOPRIGHT", 4, -16)
219 scrollbar:SetPoint("BOTTOMLEFT", scrollframe, "BOTTOMRIGHT", 4, 16)
220 scrollbar:SetScript("OnValueChanged", OnScrollValueChanged)
221 scrollbar:SetMinMaxValues(0, 1000)
222 scrollbar:SetValueStep(1)
223 scrollbar:SetValue(0)
224 scrollbar:SetWidth(16)
225 scrollbar:Hide()
226 self.scrollbar = scrollbar
227
228 local scrollbg = scrollbar:CreateTexture(nil, "BACKGROUND")
229 scrollbg:SetAllPoints(scrollbar)
230 scrollbg:SetTexture(0, 0, 0, 0.4)
231
232 self.localstatus.scrollvalue = 0
233
234 --self:FixScroll()
235 AceGUI:RegisterAsContainer(self)
236 --AceGUI:RegisterAsWidget(self)
237 return self
238 end
239
240 AceGUI:RegisterWidgetType(Type,Constructor,Version)
241 end