Add padding option to natural width and height

This commit is contained in:
david-swift 2024-10-26 21:08:50 +02:00
parent 2d12c57236
commit e2da50703c
3 changed files with 17 additions and 13 deletions

View File

@ -300,15 +300,19 @@ extension AnyView {
} }
/// Whether the view has a width higher or equal to its natural width. /// Whether the view has a width higher or equal to its natural width.
/// - Parameter matches: Whether the content view matches the breakpoint. /// - Parameters:
public func naturalWidth(matches: Binding<Bool>) -> AnyView { /// - matches: Whether the content view matches the breakpoint.
BreakpointBin(condition: .naturalWidth, matches: matches) { self } /// - padding: Increase the natural width by a certain padding.
public func naturalWidth(matches: Binding<Bool>, padding: Int = 0) -> AnyView {
BreakpointBin(condition: .naturalWidth(padding: padding), matches: matches) { self }
} }
/// Whether the view has a height higher or equal to its natural height. /// Whether the view has a height higher or equal to its natural height.
/// - Parameter matches: Whether the content view matches the breakpoint. /// - Parameters:
public func naturalHeight(matches: Binding<Bool>) -> AnyView { /// - matches: Whether the content view matches the breakpoint.
BreakpointBin(condition: .naturalHeight, matches: matches) { self } /// - padding: Increase the natural height by a certain padding.
public func naturalHeight(matches: Binding<Bool>, padding: Int = 0) -> AnyView {
BreakpointBin(condition: .naturalHeight(padding: padding), matches: matches) { self }
} }
} }

View File

@ -32,16 +32,16 @@ public struct BreakpointBin: AdwaitaWidget {
set: { bin, condition, storage in set: { bin, condition, storage in
let string: OpaquePointer let string: OpaquePointer
switch condition { switch condition {
case .naturalWidth: case let .naturalWidth(padding):
let child = adw_breakpoint_bin_get_child(bin.cast()) let child = adw_breakpoint_bin_get_child(bin.cast())
var size: Int32 = 0 var size: Int32 = 0
gtk_widget_measure(child, GTK_ORIENTATION_HORIZONTAL, -1, nil, &size, nil, nil) gtk_widget_measure(child, GTK_ORIENTATION_HORIZONTAL, -1, nil, &size, nil, nil)
string = adw_breakpoint_condition_parse(BreakpointCondition.minWidth(.init(size)).condition) string = adw_breakpoint_condition_parse(BreakpointCondition.minWidth(.init(size) + padding).condition)
case .naturalHeight: case let .naturalHeight(padding):
let child = adw_breakpoint_bin_get_child(bin.cast()) let child = adw_breakpoint_bin_get_child(bin.cast())
var size: Int32 = 0 var size: Int32 = 0
gtk_widget_measure(child, GTK_ORIENTATION_VERTICAL, -1, nil, &size, nil, nil) gtk_widget_measure(child, GTK_ORIENTATION_VERTICAL, -1, nil, &size, nil, nil)
string = adw_breakpoint_condition_parse(BreakpointCondition.minHeight(.init(size)).condition) string = adw_breakpoint_condition_parse(BreakpointCondition.minHeight(.init(size) + padding).condition)
default: default:
string = adw_breakpoint_condition_parse(condition.condition) string = adw_breakpoint_condition_parse(condition.condition)
} }
@ -111,9 +111,9 @@ public enum BreakpointCondition: Equatable {
/// Define a minimum height. /// Define a minimum height.
case minHeight(_ height: Int) case minHeight(_ height: Int)
/// The minimum width is the content's natural width. /// The minimum width is the content's natural width.
case naturalWidth case naturalWidth(padding: Int = 0)
/// The minimum height is the content's natural height. /// The minimum height is the content's natural height.
case naturalHeight case naturalHeight(padding: Int = 0)
/// The condition to parse. /// The condition to parse.
var condition: String? { var condition: String? {

View File

@ -48,7 +48,7 @@ enum Page: String, Identifiable, CaseIterable, Codable, CustomStringConvertible
case .alertDialog: case .alertDialog:
return "Alert Dialog" return "Alert Dialog"
case .passwordChecker: case .passwordChecker:
return "Password Checker is such a long name..." return "Password Checker"
default: default:
return rawValue.capitalized return rawValue.capitalized
} }