Skip to content

Commit

Permalink
Fix ComboRow not selecting value at initialization
Browse files Browse the repository at this point in the history
Fixes #28
  • Loading branch information
david-swift committed May 9, 2024
1 parent 9618985 commit e44f3d7
Show file tree
Hide file tree
Showing 46 changed files with 185 additions and 176 deletions.
39 changes: 24 additions & 15 deletions Sources/Adwaita/View/Forms/ComboRow+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,32 @@ extension ComboRow {
let list = gtk_string_list_new(nil)
storage.fields[Self.stringList] = list
adw_combo_row_set_model(storage.pointer?.cast(), list)
Self.updateContent(storage: storage, values: values, element: Element.self)
}
updateFunctions.append { storage, _, _ in
if let list = storage.fields[Self.stringList] as? OpaquePointer {
let old = storage.fields[Self.values] as? [Element] ?? []
old.identifiableTransform(
to: values,
functions: .init { index, element in
gtk_string_list_remove(list, .init(index))
gtk_string_list_append(list, element.description)
} delete: { index in
gtk_string_list_remove(list, .init(index))
} insert: { _, element in
gtk_string_list_append(list, element.description)
}
)
storage.fields[Self.values] = values
}
Self.updateContent(storage: storage, values: values, element: Element.self)
}
}

static func updateContent<Element>(
storage: ViewStorage,
values: [Element],
element: Element.Type
) where Element: Identifiable, Element: CustomStringConvertible {
if let list = storage.fields[Self.stringList] as? OpaquePointer {
let old = storage.fields[Self.values] as? [Element] ?? []
old.identifiableTransform(
to: values,
functions: .init { index, element in
gtk_string_list_remove(list, .init(index))
gtk_string_list_append(list, element.description)
} delete: { index in
gtk_string_list_remove(list, .init(index))
} insert: { _, element in
gtk_string_list_append(list, element.description)
}
)
storage.fields[Self.values] = values
}
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Adwaita/View/Generated/ActionRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ActionRow.swift
// Adwaita
//
// Created by auto-generation on 21.04.24.
// Created by auto-generation on 09.05.24.
//

import CAdw
Expand Down Expand Up @@ -113,6 +113,9 @@ public struct ActionRow: Widget {
/// - Returns: The view storage.
public func container(modifiers: [(View) -> View]) -> ViewStorage {
let storage = ViewStorage(adw_action_row_new()?.opaque())
for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true)
if let activatableWidgetStorage = activatableWidget?().widget(modifiers: modifiers).storage(modifiers: modifiers) {
storage.content["activatableWidget"] = [activatableWidgetStorage]
Expand All @@ -131,9 +134,6 @@ public struct ActionRow: Widget {
adw_action_row_add_prefix(storage.pointer?.cast(), prefixStorage.last?.pointer?.cast())
}
storage.content["prefix"] = prefixStorage
for function in appearFunctions {
function(storage, modifiers)
}
return storage
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Adwaita/View/Generated/Avatar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Avatar.swift
// Adwaita
//
// Created by auto-generation on 21.04.24.
// Created by auto-generation on 09.05.24.
//

import CAdw
Expand Down Expand Up @@ -66,11 +66,11 @@ public struct Avatar: Widget {
/// - Returns: The view storage.
public func container(modifiers: [(View) -> View]) -> ViewStorage {
let storage = ViewStorage(adw_avatar_new(size.cInt, text, showInitials.cBool)?.opaque())
update(storage, modifiers: modifiers, updateProperties: true)

for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true)

return storage
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Adwaita/View/Generated/Banner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Banner.swift
// Adwaita
//
// Created by auto-generation on 21.04.24.
// Created by auto-generation on 09.05.24.
//

import CAdw
Expand Down Expand Up @@ -70,11 +70,11 @@ public struct Banner: Widget {
/// - Returns: The view storage.
public func container(modifiers: [(View) -> View]) -> ViewStorage {
let storage = ViewStorage(adw_banner_new(title)?.opaque())
update(storage, modifiers: modifiers, updateProperties: true)

for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true)

return storage
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Adwaita/View/Generated/Bin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Bin.swift
// Adwaita
//
// Created by auto-generation on 21.04.24.
// Created by auto-generation on 09.05.24.
//

import CAdw
Expand Down Expand Up @@ -40,15 +40,15 @@ public struct Bin: Widget {
/// - Returns: The view storage.
public func container(modifiers: [(View) -> View]) -> ViewStorage {
let storage = ViewStorage(adw_bin_new()?.opaque())
for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true)
if let childStorage = child?().widget(modifiers: modifiers).storage(modifiers: modifiers) {
storage.content["child"] = [childStorage]
adw_bin_set_child(storage.pointer?.cast(), childStorage.pointer?.cast())
}

for function in appearFunctions {
function(storage, modifiers)
}
return storage
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Adwaita/View/Generated/Box.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Box.swift
// Adwaita
//
// Created by auto-generation on 21.04.24.
// Created by auto-generation on 09.05.24.
//

import CAdw
Expand Down Expand Up @@ -78,6 +78,9 @@ public struct Box: Widget {
/// - Returns: The view storage.
public func container(modifiers: [(View) -> View]) -> ViewStorage {
let storage = ViewStorage(gtk_box_new(GTK_ORIENTATION_VERTICAL, spacing.cInt)?.opaque())
for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true)

var appendStorage: [ViewStorage] = []
Expand All @@ -92,9 +95,6 @@ public struct Box: Widget {
gtk_box_prepend(storage.pointer?.cast(), prependStorage.last?.pointer?.cast())
}
storage.content["prepend"] = prependStorage
for function in appearFunctions {
function(storage, modifiers)
}
return storage
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Adwaita/View/Generated/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Button.swift
// Adwaita
//
// Created by auto-generation on 21.04.24.
// Created by auto-generation on 09.05.24.
//

import CAdw
Expand Down Expand Up @@ -94,15 +94,15 @@ public struct Button: Widget {
/// - Returns: The view storage.
public func container(modifiers: [(View) -> View]) -> ViewStorage {
let storage = ViewStorage(gtk_button_new()?.opaque())
for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true)
if let childStorage = child?().widget(modifiers: modifiers).storage(modifiers: modifiers) {
storage.content["child"] = [childStorage]
gtk_button_set_child(storage.pointer?.cast(), childStorage.pointer?.cast())
}

for function in appearFunctions {
function(storage, modifiers)
}
return storage
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Adwaita/View/Generated/ButtonContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ButtonContent.swift
// Adwaita
//
// Created by auto-generation on 21.04.24.
// Created by auto-generation on 09.05.24.
//

import CAdw
Expand Down Expand Up @@ -83,11 +83,11 @@ public struct ButtonContent: Widget {
/// - Returns: The view storage.
public func container(modifiers: [(View) -> View]) -> ViewStorage {
let storage = ViewStorage(adw_button_content_new()?.opaque())
update(storage, modifiers: modifiers, updateProperties: true)

for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true)

return storage
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Adwaita/View/Generated/Carousel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Carousel.swift
// Adwaita
//
// Created by auto-generation on 21.04.24.
// Created by auto-generation on 09.05.24.
//

import CAdw
Expand Down Expand Up @@ -81,11 +81,11 @@ public struct Carousel<Element>: Widget where Element: Identifiable {
/// - Returns: The view storage.
public func container(modifiers: [(View) -> View]) -> ViewStorage {
let storage = ViewStorage(adw_carousel_new()?.opaque())
update(storage, modifiers: modifiers, updateProperties: true)

for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true)

return storage
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Adwaita/View/Generated/CenterBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// CenterBox.swift
// Adwaita
//
// Created by auto-generation on 21.04.24.
// Created by auto-generation on 09.05.24.
//

import CAdw
Expand Down Expand Up @@ -90,6 +90,9 @@ public struct CenterBox: Widget {
/// - Returns: The view storage.
public func container(modifiers: [(View) -> View]) -> ViewStorage {
let storage = ViewStorage(gtk_center_box_new()?.opaque())
for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true)
if let centerWidgetStorage = centerWidget?().widget(modifiers: modifiers).storage(modifiers: modifiers) {
storage.content["centerWidget"] = [centerWidgetStorage]
Expand All @@ -104,9 +107,6 @@ public struct CenterBox: Widget {
gtk_center_box_set_start_widget(storage.pointer, startWidgetStorage.pointer?.cast())
}

for function in appearFunctions {
function(storage, modifiers)
}
return storage
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Adwaita/View/Generated/CheckButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// CheckButton.swift
// Adwaita
//
// Created by auto-generation on 21.04.24.
// Created by auto-generation on 09.05.24.
//

import CAdw
Expand Down Expand Up @@ -123,15 +123,15 @@ public struct CheckButton: Widget {
/// - Returns: The view storage.
public func container(modifiers: [(View) -> View]) -> ViewStorage {
let storage = ViewStorage(gtk_check_button_new()?.opaque())
for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true)
if let childStorage = child?().widget(modifiers: modifiers).storage(modifiers: modifiers) {
storage.content["child"] = [childStorage]
gtk_check_button_set_child(storage.pointer?.cast(), childStorage.pointer?.cast())
}

for function in appearFunctions {
function(storage, modifiers)
}
return storage
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Adwaita/View/Generated/Clamp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Clamp.swift
// Adwaita
//
// Created by auto-generation on 21.04.24.
// Created by auto-generation on 09.05.24.
//

import CAdw
Expand Down Expand Up @@ -68,15 +68,15 @@ public struct Clamp: Widget {
/// - Returns: The view storage.
public func container(modifiers: [(View) -> View]) -> ViewStorage {
let storage = ViewStorage(adw_clamp_new()?.opaque())
for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true)
if let childStorage = child?().widget(modifiers: modifiers).storage(modifiers: modifiers) {
storage.content["child"] = [childStorage]
adw_clamp_set_child(storage.pointer, childStorage.pointer?.cast())
}

for function in appearFunctions {
function(storage, modifiers)
}
return storage
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Adwaita/View/Generated/ComboRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ComboRow.swift
// Adwaita
//
// Created by auto-generation on 21.04.24.
// Created by auto-generation on 09.05.24.
//

import CAdw
Expand Down Expand Up @@ -137,6 +137,9 @@ public struct ComboRow: Widget {
/// - Returns: The view storage.
public func container(modifiers: [(View) -> View]) -> ViewStorage {
let storage = ViewStorage(adw_combo_row_new()?.opaque())
for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true)
if let activatableWidgetStorage = activatableWidget?().widget(modifiers: modifiers).storage(modifiers: modifiers) {
storage.content["activatableWidget"] = [activatableWidgetStorage]
Expand All @@ -155,9 +158,6 @@ public struct ComboRow: Widget {
adw_action_row_add_prefix(storage.pointer?.cast(), prefixStorage.last?.pointer?.cast())
}
storage.content["prefix"] = prefixStorage
for function in appearFunctions {
function(storage, modifiers)
}
return storage
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/Adwaita/View/Generated/EntryRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// EntryRow.swift
// Adwaita
//
// Created by auto-generation on 21.04.24.
// Created by auto-generation on 09.05.24.
//

import CAdw
Expand Down Expand Up @@ -105,6 +105,9 @@ public struct EntryRow: Widget {
/// - Returns: The view storage.
public func container(modifiers: [(View) -> View]) -> ViewStorage {
let storage = ViewStorage(adw_entry_row_new()?.opaque())
for function in appearFunctions {
function(storage, modifiers)
}
update(storage, modifiers: modifiers, updateProperties: true)

var suffixStorage: [ViewStorage] = []
Expand All @@ -119,9 +122,6 @@ public struct EntryRow: Widget {
adw_entry_row_add_prefix(storage.pointer?.cast(), prefixStorage.last?.pointer?.cast())
}
storage.content["prefix"] = prefixStorage
for function in appearFunctions {
function(storage, modifiers)
}
return storage
}

Expand Down
Loading

0 comments on commit e44f3d7

Please sign in to comment.