Skip to content

Theming ​

SwiftFlow provides a comprehensive theming system for customizing the visual appearance of the entire canvas.

Using Preset Themes ​

Three built-in themes are available:

swift
// Light theme (default)
SwiftFlow(nodes: nodes, edges: edges, ..., theme: .default) { ... }

// Dark theme
SwiftFlow(nodes: nodes, edges: edges, ..., theme: .dark) { ... }

// Explicit light theme (identical to .default)
SwiftFlow(nodes: nodes, edges: edges, ..., theme: .light) { ... }

Creating Custom Themes ​

Create a SwiftFlowTheme instance with your own values:

swift
let customTheme = SwiftFlowTheme(
    edgeColor: .blue.opacity(0.6),
    edgeSelectedColor: .cyan,
    edgeWidth: 2.5,
    edgeSelectedWidth: 4,
    nodeBackgroundColor: .white,
    nodeSelectedBorderColor: .blue,
    nodeSelectedBorderWidth: 2,
    handleColor: .orange,
    handleBorderColor: .white,
    handleSize: 14,
    selectionBoxColor: .blue.opacity(0.1),
    selectionBoxBorderColor: .blue.opacity(0.5),
    canvasBackgroundColor: .clear,
    gridColor: .gray.opacity(0.2),
    gridSpacing: 25,
    minimapBackgroundOpacity: 0.9,
    minimapNodeColor: .blue.opacity(0.3),
    minimapSelectedNodeColor: .cyan,
    snapLineColor: .cyan.opacity(0.5),
    snapLineWidth: 1,
    edgeLabelFont: .system(size: 12, weight: .medium),
    edgeLabelColor: .white,
    edgeLabelBackgroundColor: Color(white: 0.15)
)

SwiftFlow(nodes: nodes, edges: edges, ..., theme: customTheme) { ... }

Modifying an Existing Theme ​

You can start from a preset and selectively override properties:

swift
var theme = SwiftFlowTheme.dark
theme.edgeColor = .mint.opacity(0.5)
theme.edgeSelectedColor = .mint
theme.nodeSelectedBorderColor = .mint
theme.selectionBoxColor = .mint.opacity(0.1)
theme.selectionBoxBorderColor = .mint.opacity(0.5)

SwiftFlow(nodes: nodes, edges: edges, ..., theme: theme) { ... }

Theme Properties Reference ​

Edges ​

PropertyTypeDefault (Light)Description
edgeColorColor.gray.opacity(0.6)Unselected edge stroke color
edgeSelectedColorColor.blueSelected edge stroke color
edgeWidthCGFloat2Unselected edge stroke width
edgeSelectedWidthCGFloat3Selected edge stroke width

Nodes ​

PropertyTypeDefaultDescription
nodeBackgroundColorColor.whiteNode background when Node.style has no backgroundColor
nodeSelectedBorderColorColor.blueSelected node outline color
nodeSelectedBorderWidthCGFloat2Selected node outline width (set to 0 if your node views draw their own selection)

Handles ​

PropertyTypeDefaultDescription
handleColorColor.grayHandle fill color (used when Handle(color:) is nil)
handleBorderColorColor.whiteHandle border color
handleSizeCGFloat12Handle diameter

Handle, MiniMap and the canvas read these values from the theme unless you pass explicit overrides.

Selection ​

PropertyTypeDefaultDescription
selectionBoxColorColor.blue.opacity(0.1)Selection box fill
selectionBoxBorderColorColor.blue.opacity(0.5)Selection box border

Canvas ​

PropertyTypeDefaultDescription
canvasBackgroundColorColor.clearCanvas background fill
gridColorColor.gray.opacity(0.3)Background pattern color
gridSpacingCGFloat20Background pattern gap

MiniMap ​

PropertyTypeDefaultDescription
minimapBackgroundOpacityCGFloat0.9Minimap background opacity
minimapNodeColorColor.gray.opacity(0.5)Node color in minimap (used when MiniMap(nodeColor:) is nil)
minimapSelectedNodeColorColor.blueSelected node color in minimap (used when MiniMap(selectedNodeColor:) is nil)

Snap Lines ​

PropertyTypeDefaultDescription
snapLineColorColor.blue.opacity(0.5)Snap guide color
snapLineWidthCGFloat1Snap guide width

Edge Labels ​

PropertyTypeDefaultDescription
edgeLabelFontFont.system(size: 11)Edge label font
edgeLabelColorColor.blackEdge label text color
edgeLabelBackgroundColorColor.whiteEdge label background

The .dark theme uses .white text on Color(white: 0.2).

ColorMode ​

The colorMode parameter controls which color scheme is used by SwiftFlow components:

swift
// Follow system appearance (default)
SwiftFlow(..., colorMode: .system) { ... }

// Force light mode
SwiftFlow(..., colorMode: .light) { ... }

// Force dark mode
SwiftFlow(..., colorMode: .dark) { ... }
ValueDescription
.lightLight mode colors
.darkDark mode colors
.systemFollows system appearance

Node-Level Styling ​

Individual nodes and edges can override theme defaults via their style property. The canvas applies Node.style (background, falling back to theme.nodeBackgroundColor; border color and width; corner radius; opacity) and EdgeStyle.opacity:

NodeStyle ​

swift
let styledNode = Node(
    id: "styled",
    position: XYPosition(x: 100, y: 100),
    data: "Custom",
    style: NodeStyle(
        backgroundColor: .orange.opacity(0.2),
        borderColor: .orange,
        borderWidth: 2,
        borderRadius: 12,
        opacity: 0.9
    )
)
PropertyTypeDescription
backgroundColorColor?Node fill color (overrides theme)
borderColorColor?Node border color (overrides theme)
borderWidthCGFloat?Node border width (overrides theme)
borderRadiusCGFloat?Node corner radius
opacityDouble?Node opacity

EdgeStyle ​

swift
let styledEdge = FlowEdge(
    id: "styled-edge",
    source: "1", target: "2",
    style: EdgeStyle(
        strokeColor: .purple,
        strokeWidth: 3,
        opacity: 0.8
    )
)
PropertyTypeDescription
strokeColorColor?Edge stroke color (overrides theme)
strokeWidthCGFloat?Edge stroke width (overrides theme)
opacityDouble?Edge opacity

SwiftUI-native node graph editor.