Add support for setting a window's minimum size
Some checks are pending
Deploy Docs / publish (push) Waiting to run
SwiftLint / SwiftLint (push) Waiting to run

This commit is contained in:
david-swift 2025-04-19 18:37:23 +02:00
parent f209c8387c
commit a996be3f16

View File

@ -35,6 +35,10 @@ public struct Window: AdwaitaSceneElement {
var width: Binding<Int>?
/// The binding for the window's height.
var height: Binding<Int>?
/// The window's minimum width.
var minWidth: Int?
/// The window's minimum height.
var minHeight: Int?
/// The window's default width.
var defaultWidth: Int?
/// The window's default height.
@ -127,6 +131,9 @@ public struct Window: AdwaitaSceneElement {
let width = template.width?.wrappedValue ?? template.defaultWidth ?? -1
let height = template.height?.wrappedValue ?? template.defaultHeight ?? -1
gtk_window_set_default_size(window.pointer?.cast(), .init(width), .init(height))
if minWidth != nil || minHeight != nil {
gtk_widget_set_size_request(window.pointer?.cast(), .init(minWidth ?? -1), .init(minHeight ?? -1))
}
update(storage, app: app, updateProperties: true)
return storage
}
@ -335,6 +342,17 @@ public struct Window: AdwaitaSceneElement {
return newSelf
}
/// Set the window's minimum width and height.
/// - Parameters:
/// - minWidth: The window's minimum width.
/// - minHeight: The window's minimum height.
public func minSize(width: Int = -1, height: Int = -1) -> Self {
var newSelf = self
newSelf.minWidth = width
newSelf.minHeight = height
return newSelf
}
/// Get and set whether the window is maximized.
/// - Parameter maximized: Whether the window is maximized.
/// - Returns: The window.