API Reference

This guide demonstrates real-world usage patterns of InfinityUI through common use cases and best practices.


🏗️ Basic Structure

For a complete system, organize your menus this way:

-- 1. Global variables
local data = {}
local mainMenu
local subMenu1
local subMenu2

-- 2. Network events (if needed)
RegisterNetEvent("myEvent", function(callback)
    -- Handle data
end)

-- 3. Utility functions
local function myFunction()
    -- Logic
end

-- 4. Main command
RegisterCommand("mymenu", function()
    -- Create menus
    mainMenu = InfinityUI.CreateMenu("Title", "Subtitle")
    subMenu1 = InfinityUI.CreateSubMenu(mainMenu, "Sub Menu 1", "Description")
    
    -- Open menu
    InfinityUI.Visible(mainMenu, true)
    
    -- Render loop
    while InfinityUI.Visible(mainMenu) or InfinityUI.Visible(subMenu1) do
        Citizen.Wait(0)
        
        InfinityUI.IsVisible(mainMenu, function()
            -- Main menu content
        end)
        
        InfinityUI.IsVisible(subMenu1, function()
            -- Sub menu content
        end)
    end
end)
circle-info

Key Pattern: Use a single while loop to handle all your menus with or between conditions.


Creating Menu Hierarchy

Pattern: Main Menu with Multiple Sub-Menus

Key Points:

  • ✅ Create all menus before opening

  • ✅ Use one while loop with or conditions

  • ✅ Use RightLabel = ">>>" for navigation buttons (Optional)

  • ✅ Pass the target menu as the last parameter


Pattern: Load Data Before Navigation

When to use:

  • Loading data from database

  • Fetching fresh information

  • Validating permissions before access


📝 Input Forms

Text Input with ox_lib

Pattern: Simple Text Input

Key Points:

  • ✅ Always check if input exists

  • ✅ Access value with input[1]

  • ✅ Set required = true for mandatory fields

  • ✅ Use placeholder for hints


Dynamic Button Labels

Pattern: Show Current Value in Button

Benefits:

  • Shows current state

  • Clear visual feedback

  • Better UX

Formula:


Multi-Field Form

Pattern: Multiple Inputs in One Dialog


Checkbox for Boolean Values

Pattern: Toggle with Checkbox

circle-info

Tip: Both onChecked and onUnChecked should toggle the value to ensure proper synchronization.


🗂️ Dynamic Lists

Rendering Items from Table

Pattern: Loop Through Data

Key Points:

  • ✅ Separate items (key-value) and itemList (array) for different access patterns

  • ✅ Show "No items" message when list is empty

  • ✅ Disable empty state button (false parameter)

  • ✅ Store selection in variable for next menu


Empty State Handling

Pattern: Graceful Empty State


Item Selection Flow

Pattern: List → Select → Details


💾 Data Management

Using a Data Object

Pattern: Centralized Data Storage

Benefits:

  • Single source of truth

  • Easy to reset: data = {}

  • Simple server communication


Resetting Form Data

Pattern: Clear After Submit


Separating Data Structures

Pattern: Dictionary + Array


✅ Validation & Parsing

Position Formatting

Pattern: Get and Format Coordinates


Color Input Validation

Pattern: Parse and Validate RGBA

Validation Checklist:

  • ✅ Check type before parsing

  • ✅ Validate format with regex

  • ✅ Convert to numbers

  • ✅ Range check (0-255)

  • ✅ Show error message if invalid


Number Validation

Pattern: Validate Numeric Input


🌐 Server Integration

Request-Response Pattern

Client Side:

Server Side:


Create/Update/Delete Operations

Client: Create

Client: Delete


Error Handling

Pattern: Handle Server Errors


🎨 Advanced Patterns

Conditional Button Styling

Pattern: Visual Feedback Based on State

Color Guide:


Toggle Menu Visibility

Pattern: Open/Close with Same Command


Conditional Menu Content

Pattern: Show Different Content Based on State


Confirmation Dialog

Pattern: Two-Step Confirmation


Progressive Form

1

Step 1: Basic Info

Pattern: Multi-Step Form first step

2

Step 2: Details

Pattern: Multi-Step Form second step

3

Step 3: Review

Pattern: Multi-Step Form third step


📊 Best Practices Summary

✅ DO

❌ DON'T


🎯 Common Patterns Cheat Sheet

Pattern
Use Case
Code

Navigation

Go to submenu

InfinityUI.Button("Go", nil, {RightLabel = ">>>"}, true, {}, submenu)

Load & Navigate

Fetch before open

{onSelected = function() TriggerServerEvent("load") end}, submenu

Dynamic Label

Show current value

data.field and "Label: " .. data.field or "Label (Default)"

Input

Get user input

lib.inputDialog("Title", {{type='input', label='...'}})

Validation

Check input

if not validate(input) then return end

Empty State

No data

if #list == 0 then Button("No items", nil, {}, false) end

Selection

Pick from list

{onSelected = function() selected = item.id end}, detailsMenu

Confirmation

Two-step delete

local confirm = false + toggle state

Color Coding

Visual feedback

{TextColor = {255, 0, 0}} or {Color = {BackgroundColor = {...}}}

Server Call

Send data

TriggerServerEvent("event", data)


🚀 Complete Example Template

Here's a template you can copy and adapt (Do not forget to implement the server part):


circle-check

chevron-rightNeed more help? (Expand)hashtag
  • Join our Discord: support.md

  • Check the FAQ: faq.md

Last updated