fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosMusicProbability page overhaul (Will show directories and their respected files like a tree) Fixed Label not obeying TextMargins when in wrapped mode Don't invalidate panel layout when calling DockLayout ValidateLayout should now rebuild the layout of all children and parents recursively InvalidateLayout will now invalidate all parent panels52bc85d

v2.1.1b
2.1 KiB98 linesraw
1local PANEL = class.create("ScrollPanel", "Panel")
2
3function PANEL:ScrollPanel()	
4	self:super() -- Initialize our baseclass
5	self:DockPadding(0,0,0,0)
6
7	self.m_pCanvas = self:Add("Panel")
8	self.m_pCanvas:SetBGColor(color(215, 215, 215))
9	
10	-- Create the scroll bar
11	self.m_pVBar = self:Add("ScrollBar")
12	self.m_pVBar:DockMargin(-1,0,0,0)
13	self.m_pVBar:Dock(DOCK_RIGHT)
14
15	-- Disable us from setting padding after creation
16	self.DockPadding = function() end
17
18	-- Adding things to the ScrollPanel will actually be adding it to the canvas
19	self.Add = function(this, class)
20		return this.m_pCanvas:Add(class)
21	end
22end
23
24function PANEL:OnChildAdded(child)
25end
26
27function PANEL:SizeToContents()
28	self:SetSize(self.m_pCanvas:GetSize())
29end
30
31function PANEL:GetVBar()
32	return self.m_pVBar
33end
34
35function PANEL:GetCanvas()
36	return self.m_pCanvas
37end
38
39function PANEL:InnerWidth()
40	return self:GetCanvas():GetWidth()
41end
42
43function PANEL:Rebuild()
44	self:GetCanvas():SizeToChildren(false, true)
45	if self.m_bNoSizing and self:GetCanvas():GetHeight() < self:GetHeight() then
46		self:GetCanvas():SetPos(0, (self:GetHeight()-self:GetCanvas():GetHeight()) * 0.5)
47	end
48end
49
50function PANEL:OnMouseWheeled(x, y)
51	return self.m_pVBar:OnMouseWheeled(x, y)
52end
53
54function PANEL:OnVScroll(iOffset)
55	self.m_pCanvas:SetPos(0, iOffset)
56end
57
58function PANEL:ScrollToChild(panel)
59	self:PerformLayout()
60
61	local x, y = self.m_pCanvas:GetChildPosition(panel)
62	local w, h = panel:GetSize()
63
64	y = y + h * 0.5;
65	y = y - self:GetHeight() * 0.5;
66
67	self.m_pVBar:SetY(y)
68	--self.m_pVBar:AnimateTo(y, 0.5, 0, 0.5);
69end
70
71function PANEL:PerformLayout()
72	local wide = self:GetWidth()
73	local ypos = 0
74	local xpos = 0
75
76	self.m_pVBar:SetUp(self:GetHeight(), self.m_pCanvas:GetHeight())
77	ypos = self.m_pVBar:GetOffset()
78
79	if self.m_pVBar.m_bEnabled then
80		wide = wide - self.m_pVBar:GetWidth()
81		wide = wide - self.m_pVBar.m_tDockMargins.left - self.m_pVBar.m_tDockMargins.right
82	end
83
84	self.m_pCanvas:SetPos(0, ypos)
85	self.m_pCanvas:SetWidth(wide)
86
87	self:Rebuild()
88end
89
90function PANEL:SetScroll(scroll)
91	self.m_pVBar:SetScroll(scroll)
92end
93
94function PANEL:Clear()
95	self.m_pVBar:SetScroll(0)
96	self.m_pCanvas:Clear()
97	self:InvalidateLayout()
98end