Files
letro-ios/ElementX/Sources/Other/SwiftUI/Layout/ScaledOffsetModifier.swift
Stefan Ceriu 89eae00479 Switch license to AGPL (#3237)
* Switch license file to AGPL

* Update file copyright headers

* Update the default project file header
2024-09-06 16:34:30 +03:00

29 lines
809 B
Swift

//
// Copyright 2024 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only
// Please see LICENSE in the repository root for full details.
//
import SwiftUI
extension View {
func scaledOffset(x: CGFloat = 0, y: CGFloat = 0, relativeTo textStyle: Font.TextStyle = .body) -> some View {
modifier(ScaledOffsetModifier(x: x, y: y, relativeTo: textStyle))
}
}
private struct ScaledOffsetModifier: ViewModifier {
@ScaledMetric var x: CGFloat
@ScaledMetric var y: CGFloat
init(x: CGFloat, y: CGFloat, relativeTo textStyle: Font.TextStyle) {
_x = ScaledMetric(wrappedValue: x, relativeTo: textStyle)
_y = ScaledMetric(wrappedValue: y, relativeTo: textStyle)
}
func body(content: Content) -> some View {
content.offset(x: x, y: y)
}
}