gridstack_get_cell_from_pixel
Convert pixel coordinates to grid cell positions for dynamic dashboard layouts, enabling precise widget placement in responsive grid systems.
Instructions
Convert pixel coordinates to grid cell position
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| position | Yes | ||
| useOffset | No | Use offset coordinates |
Implementation Reference
- src/tools/index.ts:1089-1099 (handler)The handler function that executes the tool logic by generating JavaScript code to call GridStack's getCellFromPixel method.
private async getCellFromPixel(params: any): Promise<string> { const { position, useOffset = false } = params; return this.utils.generateGridStackCode("getCellFromPixel", { position, useOffset, code: `const cell = grid.getCellFromPixel(${JSON.stringify( position )}, ${useOffset});`, }); } - src/tools/index.ts:570-592 (schema)The tool schema definition including name, description, and input validation schema.
{ name: "gridstack_get_cell_from_pixel", description: "Convert pixel coordinates to grid cell position", inputSchema: { type: "object", required: ["position"], properties: { position: { type: "object", required: ["top", "left"], properties: { top: { type: "number", description: "Top pixel position" }, left: { type: "number", description: "Left pixel position" }, }, }, useOffset: { type: "boolean", description: "Use offset coordinates", default: false, }, }, }, }, - src/tools/index.ts:831-832 (registration)Registration of the tool handler in the central callTool switch statement.
case "gridstack_get_cell_from_pixel": return this.getCellFromPixel(args);