forked from aparoksha/adwaita-swift
Add padding option to natural width and height
This commit is contained in:
parent
2d12c57236
commit
e2da50703c
@ -300,15 +300,19 @@ extension AnyView {
|
||||
}
|
||||
|
||||
/// Whether the view has a width higher or equal to its natural width.
|
||||
/// - Parameter matches: Whether the content view matches the breakpoint.
|
||||
public func naturalWidth(matches: Binding<Bool>) -> AnyView {
|
||||
BreakpointBin(condition: .naturalWidth, matches: matches) { self }
|
||||
/// - Parameters:
|
||||
/// - matches: Whether the content view matches the breakpoint.
|
||||
/// - 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.
|
||||
/// - Parameter matches: Whether the content view matches the breakpoint.
|
||||
public func naturalHeight(matches: Binding<Bool>) -> AnyView {
|
||||
BreakpointBin(condition: .naturalHeight, matches: matches) { self }
|
||||
/// - Parameters:
|
||||
/// - matches: Whether the content view matches the breakpoint.
|
||||
/// - 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 }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -32,16 +32,16 @@ public struct BreakpointBin: AdwaitaWidget {
|
||||
set: { bin, condition, storage in
|
||||
let string: OpaquePointer
|
||||
switch condition {
|
||||
case .naturalWidth:
|
||||
case let .naturalWidth(padding):
|
||||
let child = adw_breakpoint_bin_get_child(bin.cast())
|
||||
var size: Int32 = 0
|
||||
gtk_widget_measure(child, GTK_ORIENTATION_HORIZONTAL, -1, nil, &size, nil, nil)
|
||||
string = adw_breakpoint_condition_parse(BreakpointCondition.minWidth(.init(size)).condition)
|
||||
case .naturalHeight:
|
||||
string = adw_breakpoint_condition_parse(BreakpointCondition.minWidth(.init(size) + padding).condition)
|
||||
case let .naturalHeight(padding):
|
||||
let child = adw_breakpoint_bin_get_child(bin.cast())
|
||||
var size: Int32 = 0
|
||||
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:
|
||||
string = adw_breakpoint_condition_parse(condition.condition)
|
||||
}
|
||||
@ -111,9 +111,9 @@ public enum BreakpointCondition: Equatable {
|
||||
/// Define a minimum height.
|
||||
case minHeight(_ height: Int)
|
||||
/// 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.
|
||||
case naturalHeight
|
||||
case naturalHeight(padding: Int = 0)
|
||||
|
||||
/// The condition to parse.
|
||||
var condition: String? {
|
||||
|
||||
@ -48,7 +48,7 @@ enum Page: String, Identifiable, CaseIterable, Codable, CustomStringConvertible
|
||||
case .alertDialog:
|
||||
return "Alert Dialog"
|
||||
case .passwordChecker:
|
||||
return "Password Checker is such a long name..."
|
||||
return "Password Checker"
|
||||
default:
|
||||
return rawValue.capitalized
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user