Skip to Content
sdeck docs

Drawing over buttons

One picture across several keys, or the entire deck.

With the overlay permission, plugin.overlays draws one picture over several slots, or the entire deck, on top of the user's buttons (which keep working):

const alarm = plugin.action({
  id: "alarm",
  name: "Alarm",
  permissions: [Permissions.overlay],
  settings: { slots: setting.slots("Where") },
  run: ({ settings, plugin }) => {
    plugin.overlays.show("alarm", {
      slots: settings.slots, // ["key:0", "key:1", "window"]; empty or left out: the entire deck
      gaps: "close",
      content: ({ width, rows }) => {
        const { size, lines } = layoutText("Time to go", { width, rows });
        return (
          <div style={{ display: "flex", width: "100%", height: "100%", background: "#b91c1c" }}>
            {lines.map(({ text, start, ...place }) => (
              <div
                key={start}
                style={{ display: "flex", position: "absolute", fontSize: size, ...place }}
              >
                {text}
              </div>
            ))}
          </div>
        );
      },
    });
    return { undo: () => plugin.overlays.hide("alarm") };
  },
});
  • content gets the size of the whole overlay. Every slot draws all of it and shows its own part, so it has to look the same in each: keep state outside, or read it with useHostState and the other hooks above.
  • gaps: "keep" (the default) lets the picture run on behind the space between keys, as through a window. "close" draws the slots as if they touched, so no letters are lost.
  • rows are the rows of keys and the window. layoutText breaks text into lines, picks the largest size that fits, and keeps every line within one row. fitText only gives the size, for one box.
  • page limits it to one page. Return null from content while there is nothing to show.
  • Showing another under the same id replaces it. All of them go when the plugin stops; show them again in activate if they should survive a restart.