pesde goatsoft / lucy

useResponsive

Lucy.useResponsive returns a getter that picks a value from map for the player's current device, input mode, breakpoint or orientation. If you pass a plain value instead of a map, it wraps it in a getter so callers can take either the same way.

Usage

local value = Lucy.useResponsive(app?, map)
ArgumentTypeDefaultWhat it is
appLucy.App?Lucy.App.current()The App tracking device and input state
maptablerequiredTable mapping responsive keys to values

Keys

The first matching key wins, in this order:

  1. device: "mobile", "tablet", "desktop", "console"
  2. mode: "touch", "gamepad", "keyboard", "mouse"
  3. breakpoint: "compact", "regular", "wide"
  4. orientation: "portrait", "landscape"
  5. default: Used when nothing above matches

See Responsive values.

Returns

NameTypeWhat it is
value() -> anyResolved responsive value

Example: responsive HUD spacing

Widen the gap between items on touch screens and console TVs:

local function DanceFloorHUD(h)
    local gap = Lucy.useResponsive(h.app, {
        console = 24,
        touch = 16,
        default = 8,
    })

    return Lucy.new "Frame" {
        Size = UDim2.fromScale(1, 1),
        Lucy.new "UIListLayout" {
            Padding = function()
                return UDim.new(0, gap())
            end,
            FillDirection = Enum.FillDirection.Horizontal,
        },
    }
end