fix: percentage height layout — ControlRenderer uses layoutPriority, VBox/HBox/VideoPlayer fill available space
This commit is contained in:
parent
7bc06097b0
commit
761dcb4d6b
@ -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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user