diff --git a/Sources/SwiftBricks/Controls/VBoxControl.swift b/Sources/SwiftBricks/Controls/VBoxControl.swift index 3b41721..6211443 100644 --- a/Sources/SwiftBricks/Controls/VBoxControl.swift +++ b/Sources/SwiftBricks/Controls/VBoxControl.swift @@ -13,7 +13,7 @@ struct VBoxControl: View { } } .padding(padding) - .frame(maxWidth: .infinity, alignment: .leading) + .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading) .background(backgroundColor) .cornerRadius(cornerRadius) .overlay( @@ -71,7 +71,7 @@ struct HBoxControl: View { } } .padding(padding) - .frame(maxWidth: .infinity, alignment: .leading) + .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading) .background(backgroundColor) .cornerRadius(8) } diff --git a/Sources/SwiftBricks/Controls/VideoPlayerControl.swift b/Sources/SwiftBricks/Controls/VideoPlayerControl.swift index 78c1b9c..fe0b5fb 100644 --- a/Sources/SwiftBricks/Controls/VideoPlayerControl.swift +++ b/Sources/SwiftBricks/Controls/VideoPlayerControl.swift @@ -51,10 +51,7 @@ struct VideoPlayerControl: View { #if os(macOS) private var macOSPlayerView: some View { VideoPlayerView(player: player) - .frame( - width: resolveWidth(schema.options), - height: resolveHeight(schema.options) - ) + .frame(maxWidth: .infinity, maxHeight: .infinity) } private struct VideoPlayerView: NSViewRepresentable { @@ -76,10 +73,7 @@ struct VideoPlayerControl: View { #else private var iOSPlayerView: some View { VideoPlayer(player: player) - .frame( - width: resolveWidth(schema.options), - height: resolveHeight(schema.options) - ) + .frame(maxWidth: .infinity, maxHeight: .infinity) } #endif diff --git a/Sources/SwiftBricks/Renderer/ControlRenderer.swift b/Sources/SwiftBricks/Renderer/ControlRenderer.swift index 71f28ce..c86ca58 100644 --- a/Sources/SwiftBricks/Renderer/ControlRenderer.swift +++ b/Sources/SwiftBricks/Renderer/ControlRenderer.swift @@ -12,12 +12,14 @@ public struct ControlRenderer: View { } public var body: some View { + let pctHeight = parsePercentHeight(schema.options.height) renderWidget(schema) .frame( maxWidth: resolveWidth(schema.options), - maxHeight: resolveHeight(schema.options), + maxHeight: pctHeight != nil ? .infinity : resolveHeight(schema.options), alignment: resolveAlignment(schema.options) ) + .layoutPriority(pctHeight ?? 0) } // MARK: - Widget分发 @@ -154,6 +156,11 @@ public struct ControlRenderer: View { } } + private func parsePercentHeight(_ h: String?) -> Double? { + guard let h = h, h.hasSuffix("%"), let val = Double(h.dropLast()) else { return nil } + return val > 0 ? val : nil + } + private func parsePixels(_ str: String) -> CGFloat? { let cleaned = str.replacingOccurrences(of: "px", with: "") return CGFloat(Double(cleaned) ?? 0)