Skip to content

Commit

Permalink
Merge remote-tracking branch 'GitHub/main' into feature/macro-extraction
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/build-all-targets.yml
  • Loading branch information
r-dent committed Feb 28, 2024
2 parents 61d2889 + 2966b78 commit 787b54f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 26 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build-all-targets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
- uses: actions/checkout@v4

- name: Build Simulator
run: |
set -o pipefail && xcodebuild -scheme StreamDeckSimulator -destination "platform=iOS Simulator,name=iPad Air (5th generation),OS=latest" -skipMacroValidation | xcpretty
run: set -o pipefail && xcodebuild -scheme StreamDeckSimulator -destination "platform=iOS Simulator,name=iPad Air (5th generation),OS=latest" -skipMacroValidation | xcpretty

- name: Build Example
run: |
Expand Down
27 changes: 13 additions & 14 deletions Sources/StreamDeckKit/Layout/StreamDeckLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,20 @@ public struct StreamDeckLayout<KeyArea: View, WindowArea: View>: View {
let caps = context.device.capabilities

VStack(alignment: .leading, spacing: 0) {
if let keyAreaSize = caps.keyAreaRect?.size {
let keyAreaContext = context.with(
dirtyMarker: .screen,
size: keyAreaSize,
index: -1
)
let keyAreaSize = caps.keyAreaRect?.size ?? .zero
let keyAreaContext = context.with(
dirtyMarker: .screen,
size: keyAreaSize,
index: -1
)

keyArea()
.frame(width: keyAreaSize.width, height: keyAreaSize.height)
.padding(.top, caps.keyAreaTopSpacing)
.padding(.leading, caps.keyAreaLeadingSpacing)
.padding(.trailing, caps.keyAreaTrailingSpacing)
.padding(.bottom, caps.keyAreaBottomSpacing)
.environment(\.streamDeckViewContext, keyAreaContext)
}
keyArea()
.frame(width: keyAreaSize.width, height: keyAreaSize.height)
.padding(.top, caps.keyAreaTopSpacing)
.padding(.leading, caps.keyAreaLeadingSpacing)
.padding(.trailing, caps.keyAreaTrailingSpacing)
.padding(.bottom, caps.keyAreaBottomSpacing)
.environment(\.streamDeckViewContext, keyAreaContext)

if let windowRect = caps.windowRect {
let windowSize = windowRect.size
Expand Down
10 changes: 2 additions & 8 deletions Sources/StreamDeckKit/Layout/StreamDeckLayoutRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@ final class StreamDeckLayoutRenderer {

init() {}

@MainActor
init<Content: View>(content: Content, device: StreamDeck) {
render(content, on: device)
}

@MainActor
func render<Content: View>(_ content: Content, on device: StreamDeck) {
cancellable?.cancel()

dirtyViews = .init([.screen])
dirtyViews = [.screen]

let context = StreamDeckViewContext(
device: device,
Expand Down Expand Up @@ -90,7 +84,7 @@ final class StreamDeckLayoutRenderer {

defer { dirtyViews.removeAll(keepingCapacity: true) }

log("requires updates of \(Array(dirtyViews))")
log("requires updates of \(dirtyViews)")

guard !dirtyViews.contains(.screen) else {
log("complete screen required")
Expand Down
1 change: 1 addition & 0 deletions Sources/StreamDeckKit/Layout/StreamDeckViewContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public struct StreamDeckViewContext {

@MainActor
public func updateRequired() {
guard size != .zero else { return } // Pedal
device.renderer.updateRequired(dirtyMarker)
}

Expand Down
7 changes: 5 additions & 2 deletions Tests/StreamDeckSDKTests/Helper/StreamDeckRobot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,18 @@ final class StreamDeckRobot {
func use<Content: View>(
_ product: StreamDeckProduct,
rendering content: Content,
waitForLayout: Bool = true,
file: StaticString = #file,
line: UInt = #line
) async throws {
use(product)

await device.render(content)

try await recorder.$screens.waitFor(file: file, line: line) {
!$0.isEmpty
if waitForLayout {
try await recorder.$screens.waitFor(file: file, line: line) {
!$0.isEmpty
}
}
}

Expand Down
35 changes: 35 additions & 0 deletions Tests/StreamDeckSDKTests/StreamDeckLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,39 @@ final class StreamDeckLayoutTests: XCTestCase {
await robot.assertSnapshot(\.windowImages[section].image, as: .image, named: "section_\(section)")
}
}

// MARK: Pedal

func test_key_events_on_pedal() async throws {
var events = [(index: Int, pressed: Bool)]()

try await robot.use(.pedal, rendering: StreamDeckLayout(keyArea: {
StreamDeckKeyAreaLayout { context in
StreamDeckKeyView { pressed in
events.append((index: context.index, pressed: pressed))
} content: { EmptyView() }
}
}), waitForLayout: false)

for key in 0 ..< 3 {
try await robot.keyPress(key, pressed: true, waitForLayout: false)
try await robot.keyPress(key, pressed: false, waitForLayout: false)
}

await robot.digest()

robot.assertEqual(\.screens.count, 0)
robot.assertEqual(\.keys.count, 0)

XCTAssertEqual(events.count, 6)

for key in 0 ..< 3 {
XCTAssertEqual(events[key * 2].index, key)
XCTAssertEqual(events[key * 2 + 1].index, key)

XCTAssertTrue(events[key * 2].pressed)
XCTAssertFalse(events[key * 2 + 1].pressed)
}
}

}

0 comments on commit 787b54f

Please sign in to comment.