fork/m-overlay

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

BkacjiosBugfixes + Dark Mode skina8034e9

v2.1.1
2.0 KiB97 linesraw
1local PANEL = class.create("Tab", "Button")
2
3PANEL:ACCESSOR("Active", "m_bActive", false)
4PANEL:ACCESSOR("ContentPanel", "m_pContentPanel")
5PANEL:ACCESSOR("ActiveColor", "m_cActiveColor")
6
7function PANEL:Tab()
8	self:super()
9	self:SetTextAlignmentX("left")
10	self:TextMargin(28, 0, 0, 0)
11end
12
13function PANEL:OnClick()
14	if self.m_pContentPanel then
15		self.m_pContentPanel:GetParent():SetActivePanel(self.m_pContentPanel)
16	end
17end
18
19function PANEL:SetImage(file)
20	if not file then return end
21	self.m_pImage = graphics.newImage(file)
22end
23
24function PANEL:PrePaint(w, h)
25	gui.skinHook("Paint", "Tab", self, w, h)
26end
27
28function PANEL:Paint(w, h)
29	if self.m_pImage then
30		graphics.setColor(color_white)
31		graphics.easyDraw(self.m_pImage, 4, 4, 0, 16, 16)
32	end
33	self:PaintLabel(w, h)
34end
35
36function PANEL:PaintOverlay(w, h)
37	gui.skinHook("PaintOverlay", "Button", self, w, h)
38end
39
40local PANEL = class.create("TabContents", "Panel")
41
42PANEL:ACCESSOR("Tab", "m_pTab")
43
44function PANEL:TabContents()
45	self:super()
46
47	self:Dock(DOCK_FILL)
48	self:DockMargin(0, 0, 0, 0)
49	self:SetVisible(false)
50end
51
52local PANEL = class.create("TabbedPanel", "Panel")
53
54function PANEL:TabbedPanel()
55	self:super()
56	self:SetDrawPanel(false)
57	self:DockPadding(0, 0, 0, 0)
58
59	-- Collection of all the tabs
60	self.m_pTabBar = self:Add("Panel")
61	self.m_pTabBar:Dock(DOCK_TOP)
62	self.m_pTabBar:DockPadding(0, 0, 0, 0)
63	self.m_pTabBar:DockMargin(0, 0, 0, 0)
64	self.m_pTabBar:SetDrawPanel(false)
65
66	self.m_pActivePanel = nil
67end
68
69function PANEL:SetActivePanel(panel)
70	if self.m_pActivePanel then
71		self.m_pActivePanel:SetVisible(false)
72		self.m_pActivePanel:GetTab():SetActive(false)
73	end
74	panel:SetVisible(true)
75	panel:GetTab():SetActive(true)
76	self.m_pActivePanel = panel
77end
78
79function PANEL:AddTab(name, icon, active)
80	local content = self:Add("TabContents")
81
82	local tab = self.m_pTabBar:Add("Tab")
83	tab:DockMargin(0, 0, 0, 0)
84	tab:Dock(DOCK_LEFT)
85	tab:SetText(name)
86	tab:SetContentPanel(content)
87	tab:SetImage(icon)
88	tab:SetWidth(82)
89
90	content:SetTab(tab)
91
92	if active then
93		self:SetActivePanel(content)
94	end
95
96	return content
97end