Skip to content

Commit

Permalink
Add padding that accepts a length
Browse files Browse the repository at this point in the history
  • Loading branch information
danielctull committed Dec 15, 2024
1 parent 55e1838 commit b48312c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/TerminalUI/ViewModifiers/Padding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ extension View {
) -> some View {
padding(set.insets(value))
}

public func padding(_ length: Int) -> some View {
padding(.all, length)
}
}

private struct Padding<Content: View>: Builtin, View {
Expand Down
15 changes: 15 additions & 0 deletions Tests/TerminalUITests/ViewModifiers/PaddingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,19 @@ struct PaddingTests {
Position(x: 3, y: 2): pixel,
])
}

@Test("length")
func length() async throws {

canvas.render(size: Size(width: 4, height: 4)) {
view.padding(1)
}

#expect(canvas.pixels == [
Position(x: 2, y: 2): pixel,
Position(x: 3, y: 2): pixel,
Position(x: 2, y: 3): pixel,
Position(x: 3, y: 3): pixel,
])
}
}

0 comments on commit b48312c

Please sign in to comment.