From 079fa0275567dd68b8c1f2dbc8e0bcea0346b6c8 Mon Sep 17 00:00:00 2001 From: david-swift Date: Tue, 15 Oct 2024 22:46:43 +0200 Subject: [PATCH] Update navigation titles in navigation split view --- Sources/Adwaita/View/NavigationSplitView.swift | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Sources/Adwaita/View/NavigationSplitView.swift b/Sources/Adwaita/View/NavigationSplitView.swift index 2e325aa..e6afca3 100644 --- a/Sources/Adwaita/View/NavigationSplitView.swift +++ b/Sources/Adwaita/View/NavigationSplitView.swift @@ -60,6 +60,9 @@ public struct NavigationSplitView: AdwaitaWidget { let storage = ViewStorage(splitView?.opaque(), content: content) update(storage, data: data, updateProperties: true, type: type) + storage.fields["sidebar-page"] = sidebarPage?.opaque() + storage.fields["main-page"] = mainPage?.opaque() + storage.notify(name: "show-content") { showContent?.wrappedValue = adw_navigation_split_view_get_show_content(storage.opaquePointer) != 0 } @@ -79,13 +82,19 @@ public struct NavigationSplitView: AdwaitaWidget { updateProperties: Bool, type: Data.Type ) where Data: ViewRenderData { - if let storage = storage.content[contentID]?[safe: 0] { + if let cStorage = storage.content[contentID]?[safe: 0] { content - .updateStorage(storage, data: data, updateProperties: updateProperties, type: type) + .updateStorage(cStorage, data: data, updateProperties: updateProperties, type: type) + if updateProperties, let mainPage = storage.fields["main-page"] as? OpaquePointer { + adw_navigation_page_set_title(mainPage.cast(), cStorage.fields[.navigationLabel] as? String ?? "") + } } - if let storage = storage.content[sidebarID]?[safe: 0] { + if let sStorage = storage.content[sidebarID]?[safe: 0] { sidebar - .updateStorage(storage, data: data, updateProperties: updateProperties, type: type) + .updateStorage(sStorage, data: data, updateProperties: updateProperties, type: type) + if updateProperties, let sidebarPage = storage.fields["sidebar-page"] as? OpaquePointer { + adw_navigation_page_set_title(sidebarPage.cast(), sStorage.fields[.navigationLabel] as? String ?? "") + } } guard updateProperties else { return