diff --git a/README.md b/README.md index 948c6f2..1b7f28e 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,55 @@ struct OnSizeChangeExample: View { } ``` +### equalWidthPreferred +Views with `.equalWidthPreferred()` inside a view with `.equalWidthContainer()` will have widths equal to the largest view. If space is limited views will shrink equally, each to a minimum size that fits the content. It works in `HStack`, `VStack` and even custom layouts like `HFlow` + +This works especially well in macOS when you want all buttons on a window to have the same width while still allowing some shrinking. + +```swift +HStack { + Button { } label: { + Text("More Information") + .equalWidthPreferred() + } + Spacer() + + Button { } label: { + Text("Cancel") + .equalWidthPreferred() + } + + Spacer() + + Button { } label: { + Text("OK") + .equalWidthPreferred() + } +} +.equalWidthContainer() +.frame(maxWidth: 400) +.padding() +``` + +### equalHeightPreferred +Views with `.equalHeightPreferred()` inside a view with `.equalHeightContainer()` will have heights equal to the largest view. If space is limited views will shrink equally, each to a minimum size that fits the content. It works in `HStack`, `VStack` and even custom layouts like `VFlow` + +```swift +HStack { + Group { + Text("Here's something with some text") + + Text("And more") + } + .foregroundColor(.white) + .padding() + .equalHeightPreferred() + .background(Color.blue.cornerRadius(10)) +} +.equalHeightContainer() +.frame(maxWidth: 200) +``` + ### keyboardHeight An environment variable that will update with animation as the iOS keyboard appears and disappears. It will always be zero for non-iOS platforms. diff --git a/Sources/FrameUp/FrameAdjustment/EqualSize/EqualHeight.swift b/Sources/FrameUp/FrameAdjustment/EqualSize/EqualHeight.swift index e308f09..a47bbbe 100644 --- a/Sources/FrameUp/FrameAdjustment/EqualSize/EqualHeight.swift +++ b/Sources/FrameUp/FrameAdjustment/EqualSize/EqualHeight.swift @@ -60,10 +60,12 @@ struct EqualHeightContainerViewModifier: ViewModifier { } public extension View { + /// This view will have a height equal to the largest view with this modifier inside a view with `.equalHeightContainer()`. If space is limited views will shrink equally, each to a minimum fixed size that fits the content. func equalHeightPreferred() -> some View { modifier(EqualHeightViewModifier()) } + /// Views inside this view using `.equalHeightPreferred()` will have a height equal to the largest view with that modifier. If space is limited these views will shrink equally, each to a minimum fixed size that fits the content. func equalHeightContainer() -> some View { modifier(EqualHeightContainerViewModifier()) } diff --git a/Sources/FrameUp/FrameAdjustment/EqualSize/EqualWidth.swift b/Sources/FrameUp/FrameAdjustment/EqualSize/EqualWidth.swift index e90b8bd..09516ed 100644 --- a/Sources/FrameUp/FrameAdjustment/EqualSize/EqualWidth.swift +++ b/Sources/FrameUp/FrameAdjustment/EqualSize/EqualWidth.swift @@ -60,13 +60,12 @@ private struct EqualWidthContainerViewModifier: ViewModifier { } public extension View { - /// Adds an action to perform when parent view size value changes. - /// - Parameter action: The action to perform when the size changes. The action closure passes the new value as its parameter. - /// - Returns: A view with an invisible background `GeometryReader` that detects and triggers an action when the size changes. + /// This view will have a width equal to the largest view with this modifier inside a view with `.equalWidthContainer()`. If space is limited views will shrink equally, each to a minimum fixed size that fits the content. func equalWidthPreferred() -> some View { modifier(EqualWidthViewModifier()) } + /// Views inside this view using `.equalWidthPreferred()` will have a width equal to the largest view with that modifier. If space is limited these views will shrink equally, each to a minimum fixed size that fits the content. func equalWidthContainer() -> some View { modifier(EqualWidthContainerViewModifier()) } @@ -78,6 +77,7 @@ public extension View { Text("More Information") .equalWidthPreferred() } + Spacer() Button { } label: {