{"id":"stratiz/KeyGlyph","name":"KeyGlyph","scope":"stratiz","platform":"roblox","description":"Draws a key glyph for any KeyCode or mouse input: Roblox's gamepad images, drawn keyboard and mouse caps cut to the key, and a lettered blank cap for the rest.","version":"1.0.0","latest":"1.0.0","versions":["1.0.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"fa9025dbe76613c15defbdd72c050e8f94e992b9636e00d03e5e31b0fcffac20","likes":0,"downloads":90,"install":"forest install stratiz/KeyGlyph","url":"https://forest.dev/p/roblox/stratiz/KeyGlyph","files":"https://api.forest.dev/ai/package/roblox/stratiz/KeyGlyph/files","readme":"# KeyGlyph\r\n\r\nDraws the glyph for a key, so a UI only passes a `KeyCode` and gets a frame back.\r\n\r\n- Gamepad buttons use Roblox's own images from `UserInputService:GetImageForKeyCode`.\r\n- Keyboard keys and mouse inputs use a drawn key cap from a sprite sheet, cut to the key itself, so there is no padding around it.\r\n- A key the sheet has no drawing for gets Roblox's blank key cap with the key's character on it, from `UserInputService:GetStringForKeyCode`, so it follows the keyboard's layout.\r\n\r\nA glyph keeps the height it was made with and takes the key's width, so Space draws wide and a letter draws square.\r\n\r\n## Usage\r\n\r\n```lua\r\nlocal KeyGlyph = require(path.to.KeyGlyph)\r\n\r\nlocal glyph = KeyGlyph.new(30, Enum.KeyCode.E)\r\nglyph.Instance.Parent = someFrame\r\n\r\nglyph:Set(Enum.KeyCode.ButtonX) -- swap the key\r\nglyph:Set(nil) -- hide it\r\n\r\nglyph:Destroy()\r\n```\r\n\r\nFor UI built some other way, like a React component, `KeyGlyph:GetLook` returns what to draw without making an instance.\r\n\r\n## API\r\n\r\n### KeyGlyph.new(height, input)\r\n\r\nReturns a new glyph whose `Instance` is an unparented `ImageLabel`, `height` px tall, showing `input`. A nil input leaves it hidden until `Set` fills it. Position, name and parent are up to the caller.\r\n\r\n### KeyGlyph:Set(input)\r\n\r\nShows another input and fits the glyph's width to the key's shape. A nil input hides it.\r\n\r\n### KeyGlyph:GetLook(input)\r\n\r\nReturns `{ Image, ImageRectOffset, ImageRectSize, AspectRatio, Text? }` for a `KeyCode` or a mouse `UserInputType`, or nil when there is nothing to draw. `Text` is set only for the lettered blank cap. It works on the module as well as on a glyph.\r\n\r\n### KeyGlyph:Destroy()\r\n\r\nDestroys the glyph's instance.\r\n\r\n## Credits\r\n\r\nThe keyboard sprite sheet and its cell layout come from Quenty's InputImageLibrary in NevermoreEngine (MIT).","readmeTruncated":false}