Skip to content

Commit

Permalink
✨ Implement min / max frame for LuminareView
Browse files Browse the repository at this point in the history
  • Loading branch information
KrLite committed Dec 17, 2024
1 parent 7d687cc commit 6dfdb24
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Sources/Luminare/Main Window/LuminareView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public struct LuminareView<Content>: 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

Expand All @@ -31,11 +33,19 @@ public struct LuminareView<Content>: 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)
Expand Down
2 changes: 2 additions & 0 deletions Sources/Luminare/Utilities/EnvironmentValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 18 additions & 0 deletions Sources/Luminare/Utilities/Extensions/View+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6dfdb24

Please sign in to comment.