Skip to content

useDensity

Lucy.useDensity returns a getter for the theme’s active density profile ("default", "touch" or "tv"). Every call in the same App reads one shared value.

Usage

local density = Lucy.useDensity(app?)
ArgumentTypeDefaultWhat it is
appLucy.App?Lucy.App.current()The App to read density from

Returns

NameTypeWhat it is
density() -> "default" | "touch" | "tv"Active density profile

Example: responsive badge

Swap text or layout for touch screens and TVs:

local function DanceFloorBadge(h)
    local density = Lucy.useDensity(h.app)

    return Lucy.new "TextLabel" {
        Text = function()
            if density() == "touch" then
                return "Floor: Active (Touch)"
            elseif density() == "tv" then
                return "Dance Floor: Live Set"
            end
            return "Floor: Active"
        end,
        Tags = { "ui-badge" },
    }
end