From d518a1da6a391861c7dd985dfbfa049606299d3c Mon Sep 17 00:00:00 2001 From: david-swift Date: Thu, 4 Jan 2024 10:13:42 +0100 Subject: [PATCH] Add support for disabling selection in a list box --- Documentation/Reference/classes/ListBox.md | 6 ++++++ Sources/CGTUI/shim.h | 16 ++++++++++++++++ Sources/Libadwaita/GTK/ListBox.swift | 8 ++++++++ 3 files changed, 30 insertions(+) diff --git a/Documentation/Reference/classes/ListBox.md b/Documentation/Reference/classes/ListBox.md index 6f95b6c..dced6d0 100644 --- a/Documentation/Reference/classes/ListBox.md +++ b/Documentation/Reference/classes/ListBox.md @@ -78,3 +78,9 @@ Set the style of the list box to the sidebar style. Add a handler for when the selection changes. - Parameter handler: The handler. - Returns: The list box. + +### `noSelection(_:)` + +Choose whether to use the single selection or no selection mode. +- Parameter noSelection: Whether to use the no selection mode. +- Returns: The list. diff --git a/Sources/CGTUI/shim.h b/Sources/CGTUI/shim.h index 3f133da..7f9c919 100644 --- a/Sources/CGTUI/shim.h +++ b/Sources/CGTUI/shim.h @@ -2286,6 +2286,22 @@ gtui_listbox_remove (uint64_t box, uint64_t widget) gtk_list_box_remove ((GtkListBox *)box, parent); } +static void +gtui_listbox_set_no_selection (uint64_t box, gboolean no_selection) +{ + g_assert_nonnull (box); + g_assert (GTK_IS_LIST_BOX (GTK_LIST_BOX ((void *)box))); + + if (no_selection) + { + gtk_list_box_set_selection_mode (box, GTK_SELECTION_NONE); + } + else + { + gtk_list_box_set_selection_mode (box, GTK_SELECTION_SINGLE); + } +} + static char * gtui_stringlist_get_selected (uint64_t dropdown, uint64_t list) { diff --git a/Sources/Libadwaita/GTK/ListBox.swift b/Sources/Libadwaita/GTK/ListBox.swift index 121d256..17cafe9 100644 --- a/Sources/Libadwaita/GTK/ListBox.swift +++ b/Sources/Libadwaita/GTK/ListBox.swift @@ -128,6 +128,14 @@ public class ListBox: NativeWidgetPeer, InsertableContainer { return self } + /// Choose whether to use the single selection or no selection mode. + /// - Parameter noSelection: Whether to use the no selection mode. + /// - Returns: The list. + public func noSelection(_ noSelection: Bool = true) -> Self { + gtui_listbox_set_no_selection(self.nativePtr, noSelection.cBool) + return self + } + } /// Run this function when a row gets selected.