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)
|
.padding(padding)
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
|
||||||
.background(backgroundColor)
|
.background(backgroundColor)
|
||||||
.cornerRadius(cornerRadius)
|
.cornerRadius(cornerRadius)
|
||||||
.overlay(
|
.overlay(
|
||||||
@ -71,7 +71,7 @@ struct HBoxControl: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(padding)
|
.padding(padding)
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
|
||||||
.background(backgroundColor)
|
.background(backgroundColor)
|
||||||
.cornerRadius(8)
|
.cornerRadius(8)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,10 +51,7 @@ struct VideoPlayerControl: View {
|
|||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
private var macOSPlayerView: some View {
|
private var macOSPlayerView: some View {
|
||||||
VideoPlayerView(player: player)
|
VideoPlayerView(player: player)
|
||||||
.frame(
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
width: resolveWidth(schema.options),
|
|
||||||
height: resolveHeight(schema.options)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct VideoPlayerView: NSViewRepresentable {
|
private struct VideoPlayerView: NSViewRepresentable {
|
||||||
@ -76,10 +73,7 @@ struct VideoPlayerControl: View {
|
|||||||
#else
|
#else
|
||||||
private var iOSPlayerView: some View {
|
private var iOSPlayerView: some View {
|
||||||
VideoPlayer(player: player)
|
VideoPlayer(player: player)
|
||||||
.frame(
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
width: resolveWidth(schema.options),
|
|
||||||
height: resolveHeight(schema.options)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -12,12 +12,14 @@ public struct ControlRenderer: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
|
let pctHeight = parsePercentHeight(schema.options.height)
|
||||||
renderWidget(schema)
|
renderWidget(schema)
|
||||||
.frame(
|
.frame(
|
||||||
maxWidth: resolveWidth(schema.options),
|
maxWidth: resolveWidth(schema.options),
|
||||||
maxHeight: resolveHeight(schema.options),
|
maxHeight: pctHeight != nil ? .infinity : resolveHeight(schema.options),
|
||||||
alignment: resolveAlignment(schema.options)
|
alignment: resolveAlignment(schema.options)
|
||||||
)
|
)
|
||||||
|
.layoutPriority(pctHeight ?? 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Widget分发
|
// 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? {
|
private func parsePixels(_ str: String) -> CGFloat? {
|
||||||
let cleaned = str.replacingOccurrences(of: "px", with: "")
|
let cleaned = str.replacingOccurrences(of: "px", with: "")
|
||||||
return CGFloat(Double(cleaned) ?? 0)
|
return CGFloat(Double(cleaned) ?? 0)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user