Skip to content

About

A GUI storyboard interface for SwiftUI

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

StoryBoards

A Freeform-style, SwiftData-backed visual canvas for SwiftUI — pan, zoom, drag, multi-select, rubber-band select, connect things with arrows, drop free-form text notes, and export the whole thing as a shareable PNG.

Originally built for MyDeck to diagram Magic: The Gathering combo lines (cards connected by labeled arrows), then pulled out into its own package because the canvas engine itself has nothing to do with cards — it's a general-purpose "place things on a board and connect them" interaction layer.

What you get

  • Pan & zoom on a large fixed-extent canvas, with a host-driven zoom toolbar (+/−/reset/fit-to-content).
  • Drag, multi-select, and rubber-band select across a mix of your own content and free-form text boxes.
  • Group move — drag one selected element and the rest of the selection moves with it, rigidly.
  • Duplicate, reorder (front/back), and delete for both single and multi-element selections.
  • Arrows connecting two elements (auto-follow when either end moves), or free-floating — with color, line weight, and an optional relationship icon badge, all editable from a floating selection bar.
  • Inline text editing for text boxes, positioned as a real, undistorted editor over the zoomed/panned canvas (a plain TextEditor under a non-1.0 .scaleEffect has broken cursor placement — this works around that SwiftUI limitation).
  • PNG export & sharing of the board's content (transparent background, cropped to content), wired into ShareLink on iOS and a native NSSharingServicePicker on macOS (SwiftUI's ShareLink can't get Photos into the destination list on macOS — see StoryboardImageExporter's doc comment for why).
  • SwiftData-native. Storyboard, StoryboardElement, and StoryboardArrow are @Model types your app adds directly to its own schema — no separate store, no sync layer.

What you bring

The package doesn't know what a "card" (or a photo, a recipe step, or whatever else you want to place on the board) is. A StoryboardElement of kind .payload carries only an opaque payloadID: String? that your app defines the meaning of. You supply:

  1. How a payload renders — a payloadContent view builder, given the element, current scale, selection state, and tap/group-move callbacks.
  2. How a payload gets added — the contents of the toolbar's "Add" menu, as an addPayloadMenuContent view builder that receives the canvas point to insert at. Your menu buttons create the StoryboardElement and set its payloadID themselves.

Everything else — arrows, text boxes, selection, zoom, export — needs no input from you.

Requirements

  • iOS 17+ / macOS 14+
  • Swift 6.4+
  • SwiftData

Installation

Add it to your Package.swift or via Xcode's File → Add Package Dependencies…:

.package(url: "https://github.com/dyerlab/StoryBoards", from: "1.0.0")

Add the three model types to your app's own Schema:

import StoryBoards

let schema = Schema([
    // ...your own models...
    Storyboard.self,
    StoryboardElement.self,
    StoryboardArrow.self,
])

Core types

  • Storyboard — one canvas. title, summary, snapToGrid, and the elements/arrows it owns (both cascade-deleted with it). ownerID is an opaque string for whatever your app considers this board's owner (a deck, a project, a recipe) — SwiftData @Model types can't be generic, so there's no typed relationship here. Deleting the owner does not cascade-delete its storyboards automatically; fetch and delete them by ownerID as part of your own delete path.
  • StoryboardElement — one placed item, .payload or .text, with a center point (x/y), explicit width/height, and a zIndex. A .payload element carries your payloadID; a .text element carries text, textColor, and textSize. The package applies no aspect-ratio logic — if your payload wants a fixed aspect ratio (a playing card, say), set height accordingly when you create it.
  • StoryboardArrow — a straight line between two elements (or two free points), with arrowColor, arrowWeight, and an optional arrowVerb badge. Fully generic; no changes needed to use it as-is.
  • StoryboardConfiguration — sizing/behavior knobs (canvas extent, grid spacing, zoom bounds, minimum text size, duplicate offset, corner radius, selection-bar button size). Apply your own via .storyboardConfiguration(_:) anywhere above a StoryboardView; every field has a sensible default if you don't.

Usage

import SwiftUI
import SwiftData
import StoryBoards

struct RecipeBoardView: View {
    @Bindable var storyboard: Storyboard
    @Environment(\.modelContext) private var context

    // Your own lookup from a payloadID back to your own model.
    var ingredients: [Ingredient]

    var body: some View {
        StoryboardView(
            storyboard: storyboard,
            isAddPayloadMenuEmpty: ingredients.isEmpty
        ) { element, scale, isSelected, onTap, onGroupMove in
            // Render a `.payload` element — implement drag yourself here,
            // the same way StoryboardTextElementView does, if you want
            // draggable payloads (see the package's source for the pattern).
            if let ingredient = ingredients.first(where: { $0.id.uuidString == element.payloadID }) {
                IngredientTile(ingredient: ingredient)
            }
        } addPayloadMenuContent: { insertionPoint in
            ForEach(ingredients) { ingredient in
                Button(ingredient.name) {
                    let element = StoryboardElement(
                        storyboard: storyboard,
                        kind: .payload,
                        x: insertionPoint.x,
                        y: insertionPoint.y,
                        zIndex: storyboard.nextZIndex,
                        width: 140,
                        height: 140
                    )
                    element.payloadID = ingredient.id.uuidString
                    context.insert(element)
                    try? context.save()
                }
            }
        }
    }
}

What's intentionally NOT in here

  • A grid/list view of a host's storyboards (e.g. "all boards for this deck") — that's a thin, app-specific navigation shell with little to reuse; build it against Storyboard/StoryboardConfiguration directly.
  • Any persistence beyond SwiftData itself — no SchemaMigrationPlan, no CloudKit configuration. That's your app's ModelContainer setup.
  • Payload-specific selection-bar controls — StoryboardSelectionBar shows no style controls for .payload elements (only reorder/duplicate/delete), matching how card elements behaved in the original app. A host wanting payload-specific controls needs its own selection bar for now.

License

Copyright © Dyerlab LLC. All rights reserved.

About

A GUI storyboard interface for SwiftUI

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages