Add additional options for navigation split view
- Whether it is collapsed - Whether the content is visible if it is collapsed
This commit is contained in:
parent
84ac558249
commit
a53b4e084b
@ -14,6 +14,10 @@ public struct NavigationSplitView: Widget {
|
||||
var sidebar: () -> Body
|
||||
/// The split view's main content.
|
||||
var content: () -> Body
|
||||
/// Whether the split view is collapsed.
|
||||
var collapsed = false
|
||||
/// Whether the content is visible (if the split view is collapsed).
|
||||
var showContent: Binding<Bool>?
|
||||
|
||||
/// The sidebar content's id.
|
||||
let sidebarID = "sidebar"
|
||||
@ -48,7 +52,14 @@ public struct NavigationSplitView: Widget {
|
||||
adw_navigation_split_view_set_content(.init(splitView), mainPage?.cast())
|
||||
content[contentID] = [mainContent]
|
||||
|
||||
return .init(.init(splitView), content: content)
|
||||
let storage = ViewStorage(.init(splitView), content: content)
|
||||
update(storage, modifiers: modifiers, updateProperties: true)
|
||||
|
||||
storage.notify(name: "show-content") {
|
||||
showContent?.wrappedValue = adw_navigation_split_view_get_show_content(storage.pointer) != 0
|
||||
}
|
||||
|
||||
return storage
|
||||
}
|
||||
|
||||
/// Update the view storage of the navigation split view widget.
|
||||
@ -67,6 +78,35 @@ public struct NavigationSplitView: Widget {
|
||||
.widget(modifiers: modifiers)
|
||||
.update(storage, modifiers: modifiers, updateProperties: updateProperties)
|
||||
}
|
||||
guard updateProperties else {
|
||||
return
|
||||
}
|
||||
let collapsed = adw_navigation_split_view_get_collapsed(storage.pointer) != 0
|
||||
if collapsed != self.collapsed {
|
||||
adw_navigation_split_view_set_collapsed(storage.pointer, self.collapsed.cBool)
|
||||
}
|
||||
let showContent = adw_navigation_split_view_get_show_content(storage.pointer) != 0
|
||||
if let binding = self.showContent, showContent != binding.wrappedValue {
|
||||
adw_navigation_split_view_set_show_content(storage.pointer, binding.wrappedValue.cBool)
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the navigation split view is collapsed, meaning in its compact form.
|
||||
/// - Parameter collapsed: Whether the view is collapsed.
|
||||
/// - Returns: The navigation split view.
|
||||
public func collapsed(_ collapsed: Bool) -> Self {
|
||||
var newSelf = self
|
||||
newSelf.collapsed = collapsed
|
||||
return newSelf
|
||||
}
|
||||
|
||||
/// Whether the content view is visible if the split view is collapsed.
|
||||
/// - Parameter showContent: Whether the content view is visible.
|
||||
/// - Returns: The navigation split view.
|
||||
public func showContent(_ showContent: Binding<Bool>) -> Self {
|
||||
var newSelf = self
|
||||
newSelf.showContent = showContent
|
||||
return newSelf
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user