simple-ui-library.lua

By aintMyCrib (@aintMyCrib)

View and share code snippets on Pastefy.

-- // SIMPLE UI LIBRARY BY AINT

local Library = {}

Library.__index = Library

-- CREATE WINDOW

function Library:CreateWindow(title)

	local sg = Instance.new("ScreenGui")	sg.Name = "AintLib"

	sg.Parent = game:GetService("CoreGui")

	sg.ResetOnSpawn = false

	local main = Instance.new("Frame", sg)

	main.Size = UDim2.new(0,220,0,250)

	main.Position = UDim2.new(0,20,0,120)

	main.BackgroundColor3 = Color3.fromRGB(25,25,25)

	main.Active = true

	Instance.new("UICorner", main)

	-- TITLE

	local titleLbl = Instance.new("TextLabel", main)

	titleLbl.Size = UDim2.new(1,0,0,30)

	titleLbl.BackgroundTransparency = 1

	titleLbl.Text = title or "AintLib"

	titleLbl.TextColor3 = Color3.new(1,1,1)

	titleLbl.TextScaled = true

	-- CONTAINER

	local container = Instance.new("Frame", main)

	container.Size = UDim2.new(1,0,1,-30)

	container.Position = UDim2.new(0,0,0,30)

	container.BackgroundTransparency = 1

	local layout = Instance.new("UIListLayout", container)

	layout.Padding = UDim.new(0,6)

	-- DRAG (MOBILE FIXED)

	local UIS = game:GetService("UserInputService")

	local dragging, dragStart, startPos

	main.InputBegan:Connect(function(input)

		if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then

			dragging = true

			dragStart = input.Position

			startPos = main.Position

		end

	end)

	UIS.InputChanged:Connect(function(input)

		if dragging and (input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseMovement) then

			local delta = input.Position - dragStart

			main.Position = UDim2.new(

				startPos.X.Scale,

				startPos.X.Offset + delta.X,

				startPos.Y.Scale,

				startPos.Y.Offset + delta.Y

			)

		end

	end)

	UIS.InputEnded:Connect(function(input)

		if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then

			dragging = false

		end

	end)

	-- RETURN WINDOW API

	local Window = {}

	-- BUTTON

	function Window:Button(text, callback)

		local btn = Instance.new("TextButton", container)

		btn.Size = UDim2.new(1,0,0,40)

		btn.BackgroundColor3 = Color3.fromRGB(40,40,40)

		btn.Text = text

		btn.TextColor3 = Color3.new(1,1,1)

		btn.TextScaled = true

		Instance.new("UICorner", btn)

		btn.MouseButton1Click:Connect(function()

			if callback then callback() end

		end)

	end

	-- TOGGLE

	function Window:Toggle(text, callback)

		local state = false

		local btn = Instance.new("TextButton", container)

		btn.Size = UDim2.new(1,0,0,40)

		btn.BackgroundColor3 = Color3.fromRGB(40,40,40)

		btn.Text = text .. ": OFF"

		btn.TextColor3 = Color3.new(1,1,1)

		btn.TextScaled = true

		Instance.new("UICorner", btn)

		btn.MouseButton1Click:Connect(function()

			state = not state

			btn.Text = text .. (state and ": ON" or ": OFF")

			if callback then callback(state) end

		end)

	end

	return Window

end

return Library

Tags

gui lang-lua screen-gui ui-library window-creation