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

Commit

Permalink
Optionally support long swipes in an AdwCarousel
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Jan 4, 2024
1 parent 7f5eec8 commit 73b82dc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Documentation/Reference/classes/Carousel.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ Remove all widgets.
Get the content widgets.
- Returns: The carousel.

### `longSwipes(_:)`

Allow swiping more than one page at a time.
- Parameter longSwipes: Allow long swiping.
- Returns: The carousel.

### `addIndicatorDots(top:)`

Add indicator dots to the carousel.
Expand Down
9 changes: 9 additions & 0 deletions Sources/CGTUI/shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,15 @@ gtui_carousel_remove (uint64_t carousel, uint64_t widget)
adw_carousel_remove (carousel, widget);
}

static void
gtui_carousel_allow_long_swipes (uint64_t carousel, gboolean long_swipes)
{
g_assert_nonnull (carousel);
g_assert (ADW_IS_CAROUSEL (ADW_CAROUSEL ((void *)carousel)));

adw_carousel_set_allow_long_swipes (carousel, long_swipes);
}

static uint64_t
gtui_create_carouselindicatordots (uint64_t carousel)
{
Expand Down
8 changes: 8 additions & 0 deletions Sources/Libadwaita/Adwaita/Carousel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public class Carousel: NativeWidgetPeer, InsertableContainer {
/// - Returns: The carousel.
public func getContent() -> [NativeWidgetPeer] { self.peers }

/// Allow swiping more than one page at a time.
/// - Parameter longSwipes: Allow long swiping.
/// - Returns: The carousel.
public func longSwipes(_ longSwipes: Bool = true) -> Carousel {
gtui_carousel_allow_long_swipes(self.nativePtr, longSwipes.cBool)
return self
}

/// Add indicator dots to the carousel.
/// - Parameter top: Whether the dots should be at the top.
/// - Returns: The carousel and the dots.
Expand Down
2 changes: 1 addition & 1 deletion Tests/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public class MyApplication: Application {
.append(TextDropDown().append("FOO").append("BAR"))
.frame(maxSize: 400)
)
.append(carousel.addIndicatorDots())
.append(carousel.longSwipes().addIndicatorDots())
.padding()
.vexpand()
)
Expand Down

0 comments on commit 73b82dc

Please sign in to comment.