Make breakpoints check condition when initializing
This commit is contained in:
parent
e2da50703c
commit
d93bc321a2
@ -27,7 +27,7 @@ let package = Package(
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://git.aparoksha.dev/aparoksha/meta", from: "0.1.0"),
|
.package(url: "https://git.aparoksha.dev/aparoksha/meta", branch: "main"),
|
||||||
.package(url: "https://git.aparoksha.dev/aparoksha/meta-sqlite", from: "0.1.0"),
|
.package(url: "https://git.aparoksha.dev/aparoksha/meta-sqlite", from: "0.1.0"),
|
||||||
.package(
|
.package(
|
||||||
url: "https://git.aparoksha.dev/aparoksha/levenshtein-transformations",
|
url: "https://git.aparoksha.dev/aparoksha/levenshtein-transformations",
|
||||||
|
|||||||
@ -30,34 +30,34 @@ public struct BreakpointBin: AdwaitaWidget {
|
|||||||
/// The condition.
|
/// The condition.
|
||||||
@Property(
|
@Property(
|
||||||
set: { bin, condition, storage in
|
set: { bin, condition, storage in
|
||||||
let string: OpaquePointer
|
var condition = condition
|
||||||
switch condition {
|
switch condition {
|
||||||
case let .naturalWidth(padding):
|
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) + padding).condition)
|
condition = .minWidth(.init(size) + padding)
|
||||||
case let .naturalHeight(padding):
|
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) + padding).condition)
|
condition = .minHeight(.init(size) + padding)
|
||||||
default:
|
default:
|
||||||
string = adw_breakpoint_condition_parse(condition.condition)
|
break
|
||||||
}
|
}
|
||||||
|
storage.fields["condition"] = condition
|
||||||
|
let string = adw_breakpoint_condition_parse(condition.condition)
|
||||||
if let breakpoint = storage.fields["breakpoint"] as? OpaquePointer {
|
if let breakpoint = storage.fields["breakpoint"] as? OpaquePointer {
|
||||||
g_object_unref(adw_breakpoint_get_condition(breakpoint)?.cast())
|
g_object_unref(adw_breakpoint_get_condition(breakpoint)?.cast())
|
||||||
adw_breakpoint_set_condition(breakpoint, string)
|
adw_breakpoint_set_condition(breakpoint, string)
|
||||||
} else {
|
} else {
|
||||||
let breakpoint = adw_breakpoint_new(string); adw_breakpoint_bin_add_breakpoint(bin.cast(), breakpoint)
|
let breakpoint = adw_breakpoint_new(string)
|
||||||
|
adw_breakpoint_bin_add_breakpoint(bin.cast(), breakpoint)
|
||||||
storage.fields["breakpoint"] = breakpoint
|
storage.fields["breakpoint"] = breakpoint
|
||||||
if let bin = storage.content["_content"]?.first?.content["append"]?.first {
|
if let matches = storage.fields["binding"] as? Binding<Bool> {
|
||||||
adw_breakpoint_add_setter(
|
Idle {
|
||||||
breakpoint,
|
condition.initialize(child: adw_breakpoint_bin_get_child(bin.cast()), matches: matches)
|
||||||
bin.opaquePointer?.cast(),
|
}
|
||||||
"visible",
|
|
||||||
false.gValue
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -71,6 +71,7 @@ public struct BreakpointBin: AdwaitaWidget {
|
|||||||
storage.notify(name: "current-breakpoint") {
|
storage.notify(name: "current-breakpoint") {
|
||||||
matches.wrappedValue = adw_breakpoint_bin_get_current_breakpoint(bin.cast()) != nil
|
matches.wrappedValue = adw_breakpoint_bin_get_current_breakpoint(bin.cast()) != nil
|
||||||
}
|
}
|
||||||
|
storage.fields["binding"] = matches
|
||||||
},
|
},
|
||||||
set: { _, _, _ in },
|
set: { _, _, _ in },
|
||||||
pointer: OpaquePointer.self
|
pointer: OpaquePointer.self
|
||||||
@ -131,4 +132,23 @@ public enum BreakpointCondition: Equatable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Initialize the breakpoint when initializing the view.
|
||||||
|
/// - Parameters:
|
||||||
|
/// - child: The widget.
|
||||||
|
/// - matches: The matches binding.
|
||||||
|
func initialize(child: UnsafeMutablePointer<GtkWidget>?, matches: Binding<Bool>) {
|
||||||
|
switch self {
|
||||||
|
case let .maxWidth(width):
|
||||||
|
matches.wrappedValue = gtk_widget_get_width(child) <= width
|
||||||
|
case let .minWidth(width):
|
||||||
|
matches.wrappedValue = gtk_widget_get_width(child) >= width
|
||||||
|
case let .maxHeight(height):
|
||||||
|
matches.wrappedValue = gtk_widget_get_height(child) <= height
|
||||||
|
case let .minHeight(height):
|
||||||
|
matches.wrappedValue = gtk_widget_get_height(child) >= height
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user