Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
Add support for disabling selection in a list box
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Jan 4, 2024
1 parent 73b82dc commit d518a1d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Documentation/Reference/classes/ListBox.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
16 changes: 16 additions & 0 deletions Sources/CGTUI/shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
8 changes: 8 additions & 0 deletions Sources/Libadwaita/GTK/ListBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d518a1d

Please sign in to comment.