Class Carousel

All Implemented Interfaces:
PointerInterface

public class Carousel extends Widget
A paginated scrolling widget.

<picture>
<source srcset="carousel-dark.png" media="(prefers-color-scheme: dark)">
<img src="carousel.png" alt="carousel">
</picture>

The `AdwCarousel` widget can be used to display a set of pages with
swipe-based navigation between them.

[class@CarouselIndicatorDots] and [class@CarouselIndicatorLines] can be used
to provide page indicators for `AdwCarousel`.

## CSS nodes

`AdwCarousel` has a single CSS node with name `carousel`.

https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.Carousel.html

  • Field Details

  • Constructor Details

    • Carousel

      public Carousel(PointerContainer pointer)
    • Carousel

      public Carousel()
      Creates a new `AdwCarousel`.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • append

      public void append(@Nonnull Widget child)
      Appends @child to @self.
      Parameters:
      child - a widget to add
    • getAllowLongSwipes

      public boolean getAllowLongSwipes()
      Gets whether to allow swiping for more than one page at a time.
      Returns:
      `TRUE` if long swipes are allowed
    • getAllowMouseDrag

      public boolean getAllowMouseDrag()
      Sets whether @self can be dragged with mouse pointer.
      Returns:
      whether @self can be dragged with mouse pointer
    • getAllowScrollWheel

      public boolean getAllowScrollWheel()
      Gets whether @self will respond to scroll wheel events.
      Returns:
      `TRUE` if @self will respond to scroll wheel events
    • getInteractive

      public boolean getInteractive()
      Gets whether @self can be navigated.
      Returns:
      whether @self can be navigated
    • getNPages

      public int getNPages()
      Gets the number of pages in @self.
      Returns:
      the number of pages in @self
    • getNthPage

      public Widget getNthPage(int n)
      Gets the page at position @n.
      Parameters:
      n - index of the page
      Returns:
      the page
    • getPosition

      public double getPosition()
      Gets current scroll position in @self, unitless.

      1 matches 1 page. Use [method@Carousel.scroll_to] for changing it.
      Returns:
      the scroll position
    • getRevealDuration

      public int getRevealDuration()
      Gets the page reveal duration, in milliseconds.
      Returns:
      the duration
    • getScrollParams

      public SpringParams getScrollParams()
      Gets the scroll animation spring parameters for @self.
      Returns:
      the animation parameters
    • getSpacing

      public int getSpacing()
      Gets spacing between pages in pixels.
      Returns:
      spacing between pages
    • insert

      public void insert(@Nonnull Widget child, int position)
      Inserts @child into @self at position @position.

      If position is -1, or larger than the number of pages,
      @child will be appended to the end.
      Parameters:
      child - a widget to add
      position - the position to insert @child at
    • prepend

      public void prepend(@Nonnull Widget child)
      Prepends @child to @self.
      Parameters:
      child - a widget to add
    • remove

      public void remove(@Nonnull Widget child)
      Removes @child from @self.
      Parameters:
      child - a widget to remove
    • reorder

      public void reorder(@Nonnull Widget child, int position)
      Moves @child into position @position.

      If position is -1, or larger than the number of pages, @child will be moved
      at the end.
      Parameters:
      child - a widget to add
      position - the position to move @child to
    • scrollTo

      public void scrollTo(@Nonnull Widget widget, boolean animate)
      Scrolls to @widget.

      If @animate is `TRUE`, the transition will be animated.
      Parameters:
      widget - a child of @self
      animate - whether to animate the transition
    • setAllowLongSwipes

      public void setAllowLongSwipes(boolean allow_long_swipes)
      Sets whether to allow swiping for more than one page at a time.

      If @allow_long_swipes is `FALSE`, each swipe can only move to the adjacent
      pages.
      Parameters:
      allow_long_swipes - whether to allow long swipes
    • setAllowMouseDrag

      public void setAllowMouseDrag(boolean allow_mouse_drag)
      Sets whether @self can be dragged with mouse pointer.

      If @allow_mouse_drag is `FALSE`, dragging is only available on touch.
      Parameters:
      allow_mouse_drag - whether @self can be dragged with mouse pointer
    • setAllowScrollWheel

      public void setAllowScrollWheel(boolean allow_scroll_wheel)
      Sets whether @self will respond to scroll wheel events.

      If @allow_scroll_wheel is `FALSE`, wheel events will be ignored.
      Parameters:
      allow_scroll_wheel - whether @self will respond to scroll wheel events
    • setInteractive

      public void setInteractive(boolean interactive)
      Sets whether @self can be navigated.

      This can be used to temporarily disable the carousel to only allow navigating
      it in a certain state.
      Parameters:
      interactive - whether @self can be navigated
    • setRevealDuration

      public void setRevealDuration(int reveal_duration)
      Sets the page reveal duration, in milliseconds.

      Reveal duration is used when animating adding or removing pages.
      Parameters:
      reveal_duration - the new reveal duration value
    • setScrollParams

      public void setScrollParams(@Nonnull SpringParams params)
      Sets the scroll animation spring parameters for @self.

      The default value is equivalent to:

      ```c
      adw_spring_params_new (1, 0.5, 500)
      ```
      Parameters:
      params - the new parameters
    • setSpacing

      public void setSpacing(int spacing)
      Sets spacing between pages in pixels.
      Parameters:
      spacing - the new spacing value
    • onPageChanged

      public SignalHandler onPageChanged(Carousel.OnPageChanged signal)
      Connect to signal "page-changed".
      See Carousel.OnPageChanged.onPageChanged(int) for signal description.
      Field SIGNAL_ON_PAGE_CHANGED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • asSwipeable

      public Swipeable asSwipeable()
      Implements interface Swipeable. Call this to get access to interface functions.
      Returns:
      Swipeable
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class Widget
      Returns:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class Widget
      Returns:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class Widget
      Returns:
      ConstraintTarget
    • asOrientable

      public Orientable asOrientable()
      Implements interface Orientable. Call this to get access to interface functions.
      Returns:
      Orientable
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()