fix: percentage height layout — ControlRenderer uses layoutPriority, VBox/HBox/VideoPlayer fill available space

This commit is contained in:
yumoqing 2026-06-22 20:30:19 +08:00
parent 7bc06097b0
commit 761dcb4d6b
3 changed files with 12 additions and 11 deletions

View File

@ -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)
}

View File

@ -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

View File

@ -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)