Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// Clean Universal UI Library (FULL, ALIGNED, SQUARE TABS)
- local Lib = {}
- Lib.__index = Lib
- -- Services
- local Players = game:GetService("Players")
- local TweenService = game:GetService("TweenService")
- local LocalPlayer = Players.LocalPlayer
- -- Constants
- local ROW_HEIGHT = 36
- local PADDING = 12
- local SPACING = 8
- -- Create Window
- function Lib:CreateWindow(cfg)
- local self = setmetatable({}, Lib)
- local gui = Instance.new("ScreenGui")
- gui.Name = "UILibrary"
- gui.ResetOnSpawn = false
- gui.Parent = LocalPlayer:WaitForChild("PlayerGui")
- self.Gui = gui
- local main = Instance.new("Frame", gui)
- main.Size = UDim2.fromOffset(cfg.SizeX or 550, cfg.SizeY or 450)
- main.Position = UDim2.fromScale(0.5,0.5)
- main.AnchorPoint = Vector2.new(0.5,0.5)
- main.BackgroundColor3 = Color3.fromRGB(25,25,30)
- main.BorderSizePixel = 0
- self.Main = main
- Instance.new("UICorner", main).CornerRadius = UDim.new(0,8)
- -- Title bar
- local title = Instance.new("TextLabel", main)
- title.Size = UDim2.new(1,0,0,44)
- title.BackgroundColor3 = Color3.fromRGB(30,30,40)
- title.BorderSizePixel = 0
- title.Text = " "..(cfg.Title or "UI")
- title.TextXAlignment = Left
- title.Font = Enum.Font.GothamBold
- title.TextSize = 18
- title.TextColor3 = Color3.fromRGB(230,230,240)
- -- Tabs
- local tabBar = Instance.new("Frame", main)
- tabBar.Position = UDim2.new(0,10,0,54)
- tabBar.Size = UDim2.new(0,140,1,-64)
- tabBar.BackgroundTransparency = 1
- self.TabBar = tabBar
- local tabLayout = Instance.new("UIListLayout", tabBar)
- tabLayout.Padding = UDim.new(0,6)
- -- Content
- local content = Instance.new("Frame", main)
- content.Position = UDim2.new(0,160,0,54)
- content.Size = UDim2.new(1,-170,1,-64)
- content.BackgroundTransparency = 1
- self.Content = content
- self.SelectedTab = nil
- return self
- end
- -- Add Tab (Square)
- function Lib:AddTab(name)
- local tab = {}
- local btn = Instance.new("TextButton", self.TabBar)
- btn.Size = UDim2.new(1,0,0,40)
- btn.BackgroundColor3 = Color3.fromRGB(40,40,55)
- btn.Text = name
- btn.Font = Enum.Font.GothamSemibold
- btn.TextSize = 14
- btn.TextColor3 = Color3.fromRGB(210,210,230)
- btn.AutoButtonColor = false
- local page = Instance.new("ScrollingFrame", self.Content)
- page.Size = UDim2.new(1,0,1,0)
- page.ScrollBarThickness = 4
- page.Visible = false
- page.CanvasSize = UDim2.new(0,0,0,0)
- page.BackgroundTransparency = 1
- local pad = Instance.new("UIPadding", page)
- pad.PaddingLeft = UDim.new(0,PADDING)
- pad.PaddingRight = UDim.new(0,PADDING)
- pad.PaddingTop = UDim.new(0,PADDING)
- local layout = Instance.new("UIListLayout", page)
- layout.Padding = UDim.new(0,SPACING)
- layout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
- page.CanvasSize = UDim2.new(0,0,0,layout.AbsoluteContentSize.Y + 10)
- end)
- btn.MouseButton1Click:Connect(function()
- if self.SelectedTab then
- self.SelectedTab.Page.Visible = false
- self.SelectedTab.Button.BackgroundColor3 = Color3.fromRGB(40,40,55)
- end
- page.Visible = true
- btn.BackgroundColor3 = Color3.fromRGB(60,60,85)
- self.SelectedTab = tab
- end)
- if not self.SelectedTab then
- self.SelectedTab = tab
- page.Visible = true
- btn.BackgroundColor3 = Color3.fromRGB(60,60,85)
- end
- tab.Button = btn
- tab.Page = page
- -- Toggle
- function tab:AddToggle(text, default, cb)
- local row = Instance.new("Frame", page)
- row.Size = UDim2.new(1,0,0,ROW_HEIGHT)
- row.BackgroundTransparency = 1
- local label = Instance.new("TextLabel", row)
- label.Size = UDim2.new(1,-70,1,0)
- label.BackgroundTransparency = 1
- label.Text = text
- label.Font = Enum.Font.Gotham
- label.TextSize = 14
- label.TextXAlignment = Left
- label.TextColor3 = Color3.fromRGB(230,230,240)
- local toggle = Instance.new("TextButton", row)
- toggle.Size = UDim2.fromOffset(56,24)
- toggle.Position = UDim2.new(1,-56,0.5,-12)
- toggle.Font = Enum.Font.GothamBold
- toggle.TextSize = 12
- toggle.TextColor3 = Color3.new(1,1,1)
- toggle.AutoButtonColor = false
- local state = default
- local function draw()
- toggle.Text = state and "ON" or "OFF"
- toggle.BackgroundColor3 = state and Color3.fromRGB(80,200,120) or Color3.fromRGB(70,70,90)
- end
- draw()
- toggle.MouseButton1Click:Connect(function()
- state = not state
- draw()
- if cb then cb(state) end
- end)
- end
- -- Slider
- function tab:AddSlider(text,min,max,default,cb)
- local row = Instance.new("Frame", page)
- row.Size = UDim2.new(1,0,0,ROW_HEIGHT+10)
- row.BackgroundTransparency = 1
- local label = Instance.new("TextLabel", row)
- label.Size = UDim2.new(1,0,0,18)
- label.BackgroundTransparency = 1
- label.Text = text.." ("..default..")"
- label.Font = Enum.Font.Gotham
- label.TextSize = 13
- label.TextXAlignment = Left
- label.TextColor3 = Color3.fromRGB(220,220,235)
- local bar = Instance.new("Frame", row)
- bar.Position = UDim2.new(0,0,0,24)
- bar.Size = UDim2.new(1,0,0,6)
- bar.BackgroundColor3 = Color3.fromRGB(60,60,80)
- local fill = Instance.new("Frame", bar)
- fill.Size = UDim2.new((default-min)/(max-min),0,1,0)
- fill.BackgroundColor3 = Color3.fromRGB(120,140,255)
- bar.InputBegan:Connect(function(i)
- if i.UserInputType == Enum.UserInputType.MouseButton1 then
- local x = (i.Position.X - bar.AbsolutePosition.X)/bar.AbsoluteSize.X
- local val = math.clamp(math.floor(min + (max-min)*x),min,max)
- fill.Size = UDim2.new((val-min)/(max-min),0,1,0)
- label.Text = text.." ("..val..")"
- if cb then cb(val) end
- end
- end)
- end
- -- Button
- function tab:AddButton(text,cb)
- local btn = Instance.new("TextButton", page)
- btn.Size = UDim2.new(1,0,0,ROW_HEIGHT)
- btn.BackgroundColor3 = Color3.fromRGB(70,70,95)
- btn.Text = text
- btn.Font = Enum.Font.GothamSemibold
- btn.TextSize = 14
- btn.TextColor3 = Color3.new(1,1,1)
- btn.AutoButtonColor = false
- btn.MouseButton1Click:Connect(function()
- if cb then cb() end
- end)
- end
- -- Input
- function tab:AddInput(text,placeholder,cb)
- local box = Instance.new("TextBox", page)
- box.Size = UDim2.new(1,0,0,ROW_HEIGHT)
- box.BackgroundColor3 = Color3.fromRGB(45,45,60)
- box.PlaceholderText = placeholder
- box.Text = ""
- box.Font = Enum.Font.Gotham
- box.TextSize = 14
- box.TextColor3 = Color3.fromRGB(230,230,240)
- box.FocusLost:Connect(function()
- if cb then cb(box.Text) end
- end)
- end
- -- Dropdown
- function tab:AddDropdown(text,options,default,cb)
- local holder = Instance.new("Frame", page)
- holder.Size = UDim2.new(1,0,0,ROW_HEIGHT)
- holder.ClipsDescendants = true
- holder.BackgroundTransparency = 1
- local current = default or options[1]
- local open = false
- local main = Instance.new("TextButton", holder)
- main.Size = UDim2.new(1,0,0,ROW_HEIGHT)
- main.BackgroundColor3 = Color3.fromRGB(45,45,65)
- main.Text = text..": "..current
- main.Font = Enum.Font.Gotham
- main.TextSize = 14
- main.TextColor3 = Color3.fromRGB(230,230,240)
- main.AutoButtonColor = false
- local list = Instance.new("Frame", holder)
- list.Position = UDim2.new(0,0,0,ROW_HEIGHT)
- list.BackgroundColor3 = Color3.fromRGB(40,40,55)
- list.Size = UDim2.new(1,0,0,#options*28)
- list.Visible = false
- local lay = Instance.new("UIListLayout", list)
- for _,opt in ipairs(options) do
- local o = Instance.new("TextButton", list)
- o.Size = UDim2.new(1,0,0,28)
- o.Text = opt
- o.Font = Enum.Font.Gotham
- o.TextSize = 13
- o.TextColor3 = Color3.fromRGB(220,220,235)
- o.BackgroundTransparency = 1
- o.MouseButton1Click:Connect(function()
- current = opt
- main.Text = text..": "..opt
- list.Visible = false
- holder.Size = UDim2.new(1,0,0,ROW_HEIGHT)
- open = false
- if cb then cb(opt) end
- end)
- end
- main.MouseButton1Click:Connect(function()
- open = not open
- list.Visible = open
- holder.Size = open
- and UDim2.new(1,0,0,ROW_HEIGHT + (#options*28))
- or UDim2.new(1,0,0,ROW_HEIGHT)
- end)
- end
- return tab
- end
- return Lib
Advertisement
Add Comment
Please, Sign In to add comment