diff --git a/Sources/Luminare/Main Window/LuminareView.swift b/Sources/Luminare/Main Window/LuminareView.swift index 585abd2..4b24816 100644 --- a/Sources/Luminare/Main Window/LuminareView.swift +++ b/Sources/Luminare/Main Window/LuminareView.swift @@ -17,6 +17,8 @@ public struct LuminareView: View where Content: View { @Environment(\.luminareTint) private var tint @Environment(\.luminareWindow) private var window + @Environment(\.luminareWindowMinFrame) private var minFrame + @Environment(\.luminareWindowMaxFrame) private var maxFrame // MARK: Fields @@ -31,11 +33,19 @@ public struct LuminareView: View where Content: View { .background { GeometryReader { proxy in Color.clear - .onAppear(perform: { setSize(size: proxy.size, animate: false) }) - .onChange(of: proxy.size, perform: { setSize(size: $0, animate: true) }) + .onAppear { + setSize(size: proxy.size, animate: false) + } + .onChange(of: proxy.size) { + setSize(size: $0, animate: true) + } } } - .frame(minWidth: 100, maxWidth: .infinity, minHeight: 100, maxHeight: .infinity, alignment: .leading) + .frame( + minWidth: minFrame.width, maxWidth: maxFrame.width, + minHeight: minFrame.height, maxHeight: maxFrame.height, + alignment: .leading + ) .focusable(false) .buttonStyle(.luminare) .overrideTint(tint) diff --git a/Sources/Luminare/Utilities/EnvironmentValues.swift b/Sources/Luminare/Utilities/EnvironmentValues.swift index e9be267..9ecc2c1 100644 --- a/Sources/Luminare/Utilities/EnvironmentValues.swift +++ b/Sources/Luminare/Utilities/EnvironmentValues.swift @@ -27,6 +27,8 @@ public extension EnvironmentValues { // MARK: Window @Entry var luminareWindow: NSWindow? + @Entry var luminareWindowMinFrame: CGSize = .init(width: 100, height: 100) + @Entry var luminareWindowMaxFrame: CGSize = .init(width: CGFloat.infinity, height: CGFloat.infinity) @Entry var luminareClickedOutside: Bool = false } diff --git a/Sources/Luminare/Utilities/Extensions/View+Extensions.swift b/Sources/Luminare/Utilities/Extensions/View+Extensions.swift index 56cc428..21f99c2 100644 --- a/Sources/Luminare/Utilities/Extensions/View+Extensions.swift +++ b/Sources/Luminare/Utilities/Extensions/View+Extensions.swift @@ -119,6 +119,24 @@ public extension View { @ViewBuilder func luminareAnimationFast(_ animation: Animation) -> some View { environment(\.luminareAnimationFast, animation) } + + @ViewBuilder func luminareWindowFrame( + minFrame: CGSize = .init(width: 100, height: 100), + maxFrame: CGSize = .init(width: CGFloat.infinity, height: CGFloat.infinity) + ) -> some View { + environment(\.luminareWindowMinFrame, minFrame) + .environment(\.luminareWindowMaxFrame, maxFrame) + } + + @ViewBuilder func luminareWindowFrame( + minWidth: CGFloat = 100, maxWidth: CGFloat = .infinity, + minHeight: CGFloat = 100, maxHeight: CGFloat = .infinity + ) -> some View { + luminareWindowFrame( + minFrame: .init(width: minWidth, height: minHeight), + maxFrame: .init(width: maxWidth, height: maxHeight) + ) + } } public extension View {