Tooltip Module V2
NOTE:This is my first open-sourced project on the DevForums, so if there are errors in documentation or bugs in the code or anything you’d like to point out, please do.
About
Tooltip Module is something I made about a month ago just because I was bored, and I decided to make it open-source, mainly for the fact that I couldn’t find any other tooltip module out here on the DevForums. I’m not going to keep this in active development, as I’m involved in other projects right now, but I sure will fix bugs or even add suggested features if requested.
Links
Get the Tooltip Module here: https://www.roblox.com/library/6894459128/Tooltip-Module
GitHub RAW: https://raw.githubusercontent.com/pranvexploder/Roblox/main/Tooltip%20Module/V2
Uncopylocked Test Place: https://www.roblox.com/games/6784339790/Tooltip-Module-Open-Source
Update Log
• Rewrote the module to more of an OOP (metatable) approach
• Now you can set Label properties directly via the tooltip object, thanks to __newindex
(its mentioned in the docs below)
• Added some aliases to functions:
- tooltip:Disconnect()
- tooltip:disconnect()
, tooltip:Destroy()
, tooltip.destroy()
- tooltip:Show()
- tooltip:show()
- tooltip:Hide()
- tooltip:hide()
Documentation
Documentation is already given at the top of the ModuleScript, but let me write it down here anyways.
Constructor
TooltipModule(<Your UI Object> [Instance], <Tooltip Text> [String])
- Creates a new tooltip
- Object parameter is required
- Text parameter is optional. If not passed, defaults to “Tooltip”
- Returns object: tooltip
--Example:
local module = require(Tooltip)
local tooltip = module(script.Parent.TextButton, "This is my tooltip text!")
Object tooltip functions
1. tooltip:Show()
- Makes the tooltip visible
- Returns object: tooltip
--Example:
local tooltip2 = tooltip:Show() --tooltip2 and tooltip are the same
2. tooltip:Hide()
- Gets the tooltip out of view
- Returns object: tooltip
--Example:
local tooltip2 = tooltip:Hide() --tooltip2 and tooltip are the same
3. tooltip:SetText(<Your Text> [String])
- Changes the tooltip text
- Text parameter is required
- Returns object: tooltip
--Example:
local tooltip2 = tooltip:SetText("I changed the text") --tooltip2 and tooltip are the same
4. tooltip:SetOffset(<Your Offset> [UDim2])
- Changes the tooltip offset relative to the mouse position
- Offset parameter is required
- Returns object: tooltip
--Example:
local offset = UDim2.new(0.035, 0, 0.15, 0)
local tooltip2 = tooltip:SetOffset(offset) --tooltip2 and tooltip are the same
5. tooltip:SetPadding(<Your Padding> [Vector2])
- Changes the padding between text and frame
- Padding parameter is required
- Returns object: tooltip
--Example:
local padding = Vector2.new(0.25, 0.25)
local tooltip2 = tooltip:SetPadding(padding) --tooltip2 and tooltip are the same
6. tooltip:Disconnect()
- Deletes the tooltip
--Example:
tooltip:Disconnect()
Object tooltip properties
1. tooltip.Gui [Instance]
- The tooltip gui
- Consists of Frame > TextLabel
- Can be easily customizable
2. tooltip.Text [String]
- Changes the tooltip text
- The function need not necessarily used but using the function is recommended
3. tooltip.Offset
- Changes the tooltip offset relative to the mouse position
- The function need not necessarily used but using the function is recommended
4. tooltip.Padding
- Changes the padding between text and frame
- The function need not necessarily used but using the function is recommended
5. tooltip[any_textlabel_property]
- Changes the specified property of the “HoverText” TextLabel in the Tooltip gui
Example Code
local module = require(script.Parent.Parent.Tooltip) -- Require the Tooltip Module
local tooltip = module(script.Parent, "Test Tooltip") -- Pass the object to lay the tooltip on and the tooltip text
wait(10)
tooltip.TextColor3 = Color3.new(1, 0 ,0)
tooltip:SetText("Tooltip Text + TextLabel Color Changed") -- SetText function, allows to change the tooltip text
wait(10)
tooltip.TextColor3 = Color3.new(1, 1, 1)
tooltip.Gui.Frame.AnchorPoint = Vector2.new(0, 0) -- Customizing the tooltip gui, changing the Frame's AnchorPoint to be specific
tooltip:SetOffset(UDim2.new(0.025, 0, 0, 0)) -- Set a Tooltip offset relative to mouse position
tooltip:SetText("Tooltip Offset + Frame AnchorPoint Changed") -- Change text as in line 4
wait(10)
tooltip:Disconnect() -- Disconnect the tooltip, basically wipe it off from existence lol
warn("Tooltip disconnected")
--[[
Tooltip Gui hierarchy:
> Tooltip.Gui Instance [ScreenGui]
> Tooltip.Gui.Frame Instance [Frame]
> Tooltip.Gui.Frame.HoverText Instance [TextLabel]
]]--
Conclusion
As mentioned above, this is my first open-source project on the DevForums, so please leave feedback on it down in the replies. Please point out if there are bugs or errors in documentation or literally anything that I have to fix. Constructive critisism is appreciated.
If you plan on using this module, you need not give credit but credits are always appreciated!