Add support for min/max width/height
This commit is contained in:
parent
a740e4ff27
commit
080483c89e
@ -16,6 +16,14 @@ public struct ModifierWrapper: WinUIWidget, CommandBarWidget {
|
||||
var width: Double?
|
||||
/// The view's height.
|
||||
var height: Double?
|
||||
/// The view's minimum width.
|
||||
var minWidth: Double?
|
||||
/// The view's minimum height.
|
||||
var minHeight: Double?
|
||||
/// The view's maximum width.
|
||||
var maxWidth: Double?
|
||||
/// The view's maximum height.
|
||||
var maxHeight: Double?
|
||||
// swiftlint:disable large_tuple
|
||||
/// The view's margin.
|
||||
var margin: (Double, Double, Double, Double)?
|
||||
@ -39,6 +47,10 @@ public struct ModifierWrapper: WinUIWidget, CommandBarWidget {
|
||||
/// - view: The content.
|
||||
/// - width: The view's width.
|
||||
/// - height: The view's height.
|
||||
/// - minWidth: The view's minimum width.
|
||||
/// - minHeight: The view's minimum height.
|
||||
/// - maxWidth: The view's maximum width.
|
||||
/// - maxHeight: The view's maximum height.
|
||||
/// - margin: The view's margin.
|
||||
/// - horizontalAlignment: The horizontal alignment.
|
||||
/// - verticalAlignment: The vertical alignment.
|
||||
@ -50,6 +62,10 @@ public struct ModifierWrapper: WinUIWidget, CommandBarWidget {
|
||||
view: AnyView,
|
||||
width: Double? = nil,
|
||||
height: Double? = nil,
|
||||
minWidth: Double? = nil,
|
||||
minHeight: Double? = nil,
|
||||
maxWidth: Double? = nil,
|
||||
maxHeight: Double? = nil,
|
||||
margin: (Double, Double, Double, Double)? = nil,
|
||||
horizontalAlignment: HorizontalAlignment? = nil,
|
||||
verticalAlignment: VerticalAlignment? = nil,
|
||||
@ -61,6 +77,10 @@ public struct ModifierWrapper: WinUIWidget, CommandBarWidget {
|
||||
self.view = view
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.minWidth = minWidth
|
||||
self.minHeight = minHeight
|
||||
self.maxWidth = maxWidth
|
||||
self.maxHeight = maxHeight
|
||||
self.margin = margin
|
||||
self.horizontalAlignment = horizontalAlignment
|
||||
self.verticalAlignment = verticalAlignment
|
||||
@ -112,6 +132,18 @@ public struct ModifierWrapper: WinUIWidget, CommandBarWidget {
|
||||
if let height, previousState?.height != height {
|
||||
view.height = height
|
||||
}
|
||||
if let minWidth, previousState?.minWidth != minWidth {
|
||||
view.minWidth = minWidth
|
||||
}
|
||||
if let minHeight, previousState?.minHeight != minHeight {
|
||||
view.minHeight = minHeight
|
||||
}
|
||||
if let maxWidth, previousState?.maxWidth != maxWidth {
|
||||
view.maxWidth = maxWidth
|
||||
}
|
||||
if let maxHeight, previousState?.maxHeight != maxHeight {
|
||||
view.maxHeight = maxHeight
|
||||
}
|
||||
if let margin, previousState?.margin ?? (0, 0, 0, 0) != margin {
|
||||
view.margin = .init(left: margin.0, top: margin.1, right: margin.2, bottom: margin.3)
|
||||
}
|
||||
|
@ -16,6 +16,20 @@ extension AnyView {
|
||||
ModifierWrapper(view: self, width: width)
|
||||
}
|
||||
|
||||
/// Set the view's minimum width.
|
||||
/// - Parameter width: The minimum width.
|
||||
/// - Returns: The view.
|
||||
public func minWidth(_ width: Double?) -> AnyView {
|
||||
ModifierWrapper(view: self, minWidth: width)
|
||||
}
|
||||
|
||||
/// Set the view's maximum width.
|
||||
/// - Parameter width: The maximum width.
|
||||
/// - Returns: The view.
|
||||
public func maxWidth(_ width: Double?) -> AnyView {
|
||||
ModifierWrapper(view: self, maxWidth: width)
|
||||
}
|
||||
|
||||
/// Set the view's height.
|
||||
/// - Parameter height: The height.
|
||||
/// - Returns: The view.
|
||||
@ -23,6 +37,20 @@ extension AnyView {
|
||||
ModifierWrapper(view: self, height: height)
|
||||
}
|
||||
|
||||
/// Set the view's minimum height.
|
||||
/// - Parameter height: The minimum height.
|
||||
/// - Returns: The view.
|
||||
public func minHeight(_ height: Double?) -> AnyView {
|
||||
ModifierWrapper(view: self, minHeight: height)
|
||||
}
|
||||
|
||||
/// Set the view's maximum height.
|
||||
/// - Parameter height: The maximum height.
|
||||
/// - Returns: The view.
|
||||
public func maxHeight(_ height: Double?) -> AnyView {
|
||||
ModifierWrapper(view: self, maxHeight: height)
|
||||
}
|
||||
|
||||
/// Set the view's margin.
|
||||
/// - Parameters:
|
||||
/// - value: The value of the margin.
|
||||
|
Loading…
Reference in New Issue
Block a user