Skip to content

Commit

Permalink
Update example to use new Layout options
Browse files Browse the repository at this point in the history
  • Loading branch information
emorydunn committed Jan 27, 2025
1 parent 4f77bf4 commit f710cb8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 27 deletions.
10 changes: 5 additions & 5 deletions Examples/counter/Sources/counter/Actions/RotaryAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RotaryAction: EncoderAction {

static var icon: String = "Icons/actionIcon"

static var encoder: RotaryEncoder? = RotaryEncoder(layout: "Layouts/counter.json",
static var encoder: RotaryEncoder? = RotaryEncoder(layout: .counter,
stackColor: "#f1184c",
icon: "Icons/stopwatch",
rotate: "Count",
Expand Down Expand Up @@ -70,10 +70,10 @@ class RotaryAction: EncoderAction {
bgColor = .white
}

setFeedback([
"count-text": count.formatted(),
"count-bar" : ["value": count, "bar_fill_c": bgColor.formatted(.hex)],
])
let feedback = CounterSettings(countText: TextLayoutSettings(value: count.formatted()),
countBar: BarLayoutSettings(bar_fill_c: bgColor))

setFeedback(feedback)
}

}
41 changes: 41 additions & 0 deletions Examples/counter/Sources/counter/Counter Layout.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Counter Layout.swift
// CounterPlugin
//
// Created by Emory Dunn on 1/27/25.
//
import StreamDeck

extension LayoutName {
static let counter: LayoutName = "counter"
}

extension Layout {
static let counter = Layout(id: .counter) {
// The title of the layout
Text(title: "Current Count")
.textAlignment(.center)
.frame(width: 180, height: 24)
.position(x: (200 - 180) / 2, y: 10)

// A large counter label
Text(key: "countText", value: "0")
.textAlignment(.center)
.font(size: 16, weight: 600)
.frame(width: 180, height: 24)
.position(x: (200 - 180) / 2, y: 30)

// A bar that shows the current count
Bar(key: "countBar", value: 0, range: -50...50)
.frame(width: 180, height: 20)
.position(x: (200 - 180) / 2, y: 60)
.barBackground(.black)
.barStyle(.doubleTrapezoid)
.barBorder("#943E93")
}
}

struct CounterSettings: LayoutSettings {
var countText: TextLayoutSettings
var countBar: BarLayoutSettings
}
23 changes: 1 addition & 22 deletions Examples/counter/Sources/counter/CounterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,7 @@ class CounterPlugin: Plugin {
}

static var layouts: [Layout] {
Layout(id: "counter") {
// The title of the layout
Text(title: "Current Count")
.textAlignment(.center)
.frame(width: 180, height: 24)
.position(x: (200 - 180) / 2, y: 10)

// A large counter label
Text(key: "count-text", value: "0")
.textAlignment(.center)
.font(size: 16, weight: 600)
.frame(width: 180, height: 24)
.position(x: (200 - 180) / 2, y: 30)

// A bar that shows the current count
Bar(key: "count-bar", value: 0, range: -50..<50)
.frame(width: 180, height: 20)
.position(x: (200 - 180) / 2, y: 60)
.barBackground(.black)
.barStyle(.doubleTrapezoid)
.barBorder("#943E93")
}
Layout.counter
}

@GlobalSetting(\.count) var count
Expand Down

0 comments on commit f710cb8

Please sign in to comment.