Loading...
Searching...
No Matches
ml::Carousel Class Reference

A scrollable container that presents a collection of Core objects. More...

#include <Carousel.h>

Inheritance diagram for ml::Carousel:

Public Types

using ArrowPlacement = CarouselManifest::ArrowPlacement
 Convenience alias for CarouselManifest::ArrowPlacement.
using ArrowSide = CarouselManifest::ArrowSide
 Convenience alias for CarouselManifest::ArrowSide.
using Flag = CarouselManifest::Flag
 Convenience alias for CarouselManifest::Flag.
using State = CarouselManifest::State
 Convenience alias for CarouselManifest::State.
using Style = CarouselManifest::Style
 Convenience alias for CarouselManifest::Style.

Public Member Functions

 Carousel ()
void add (ml::Core &component)
 Add a Core object to the carousel.
void clearArrowPosition (ArrowSide side)
 Revert an arrow to its placement-preset position.
sf::FloatRect getGlobalBounds () const override
sf::Vector2f getPosition () const override
int getPreviewCount () const
 Return the current visible item count.
sf::RenderStates getRenderStates () const override
ShaderLibrary::ParamsgetShaderParams ()
 Return a mutable reference to the current shader parameters.
float getSpacing () const
 Return the current item spacing in pixels.
float getSpeed () const
 Return the current scroll speed.
Style getStyle () const
 Return the currently active built-in style.
void next ()
 Scroll to the next item (right).
void previous ()
 Scroll to the previous item (left).
void remove (ml::Core &component)
 Remove a Core object from the carousel.
void setArrowColor (sf::Color color)
 Set the default fill color of the navigation arrows.
void setArrowHoverColor (sf::Color color)
 Set the fill color of a navigation arrow on hover.
void setArrowPlacement (ArrowPlacement placement)
 Set the layout strategy for navigation arrows.
void setArrowPosition (ArrowSide side, sf::Vector2f position)
 Override the auto-computed position of one arrow.
void setArrowSize (float size)
 Set the size of both navigation arrows.
void setArrowTexture (ArrowSide side, sf::Texture texture)
 Replace the default arrow rectangle with a custom texture.
void setPosition (const sf::Vector2f &position) override
void setPreviewCount (int count)
 Set how many items are visible in the carousel window at once.
void setShader (sf::Shader *shader, std::function< void(sf::Shader &)> uniformSetter)
 Set a custom GLSL shader with a per-frame uniform setter.
void setShaderParams (const ShaderLibrary::Params &params)
 Set parameters forwarded to the active ShaderLibrary style.
void setSpacing (float spacing)
 Set the pixel gap between items.
void setSpeed (float speed)
 Set the scroll animation speed.
void setStyle (Style style)
 Set a built-in shader style from ShaderLibrary.
void showArrows (bool show)
 Show or hide the navigation arrows.

Protected Member Functions

void draw (sf::RenderTarget &target, sf::RenderStates states) const override

Detailed Description

A scrollable container that presents a collection of Core objects.

Carousel renders its child components into an internal sf::RenderTexture and displays a windowed view of them, supporting smooth animated scrolling, optional navigation arrows, and GLSL shader effects via ShaderLibrary.

Adding and removing items

ml::Carousel carousel;
carousel.setSize({800.f, 200.f}); // via setPreviewCount + item sizes
carousel.setPosition({50.f, 100.f});
carousel.add(thumbnailA);
carousel.add(thumbnailB);
carousel.add(thumbnailC);
addComponent(carousel);

Navigation

carousel.next(); // scroll right by one item
carousel.previous(); // scroll left by one item
// Or show built-in arrows
carousel.showArrows(true);

Shader effects

carousel.setStyle(ml::CarouselManifest::Style::ARC); // built-in shader
// Or supply a custom shader
carousel.setShader(&myShader, [](sf::Shader& s){
s.setUniform("uTime", clock.getElapsedTime().asSeconds());
});
void setUniform(const std::string &name, float x)
See also
CarouselManifest, ComponentWith, ShaderLibrary

Definition at line 111 of file Carousel.h.

Member Typedef Documentation

◆ ArrowPlacement

◆ ArrowSide

Convenience alias for CarouselManifest::ArrowSide.

Definition at line 123 of file Carousel.h.

◆ Flag

Convenience alias for CarouselManifest::Flag.

Definition at line 115 of file Carousel.h.

◆ State

Convenience alias for CarouselManifest::State.

Definition at line 117 of file Carousel.h.

◆ Style

Convenience alias for CarouselManifest::Style.

Definition at line 119 of file Carousel.h.

Constructor & Destructor Documentation

◆ Carousel()

ml::Carousel::Carousel ( )

Member Function Documentation

◆ add()

void ml::Carousel::add ( ml::Core & component)

Add a Core object to the carousel.

Items are displayed in insertion order. The carousel takes a non-owning pointer; the caller is responsible for the item's lifetime.

Parameters
componentThe component to add.

◆ clearArrowPosition()

void ml::Carousel::clearArrowPosition ( ArrowSide side)

Revert an arrow to its placement-preset position.

Parameters
sideWhich arrow to reset.

◆ draw()

void ml::Carousel::draw ( sf::RenderTarget & target,
sf::RenderStates states ) const
overrideprotected

◆ getGlobalBounds()

sf::FloatRect ml::Carousel::getGlobalBounds ( ) const
override

◆ getPosition()

sf::Vector2f ml::Carousel::getPosition ( ) const
override

◆ getPreviewCount()

int ml::Carousel::getPreviewCount ( ) const

Return the current visible item count.

◆ getRenderStates()

sf::RenderStates ml::Carousel::getRenderStates ( ) const
override

◆ getShaderParams()

ShaderLibrary::Params & ml::Carousel::getShaderParams ( )

Return a mutable reference to the current shader parameters.

Returns
Reference to the internal ShaderLibrary::Params.

◆ getSpacing()

float ml::Carousel::getSpacing ( ) const

Return the current item spacing in pixels.

◆ getSpeed()

float ml::Carousel::getSpeed ( ) const

Return the current scroll speed.

◆ getStyle()

Style ml::Carousel::getStyle ( ) const

Return the currently active built-in style.

◆ next()

void ml::Carousel::next ( )

Scroll to the next item (right).

Animates the view toward the next item at the current speed. Sets Flag::SCROLLING and State::SCROLL_RIGHT while animating.

◆ previous()

void ml::Carousel::previous ( )

Scroll to the previous item (left).

Animates the view toward the previous item at the current speed. Sets Flag::SCROLLING and State::SCROLL_LEFT while animating.

◆ remove()

void ml::Carousel::remove ( ml::Core & component)

Remove a Core object from the carousel.

Parameters
componentThe component to remove. Safe to call even if component is not currently in the carousel.

◆ setArrowColor()

void ml::Carousel::setArrowColor ( sf::Color color)

Set the default fill color of the navigation arrows.

Parameters
colorFill color when the mouse is not hovering.

◆ setArrowHoverColor()

void ml::Carousel::setArrowHoverColor ( sf::Color color)

Set the fill color of a navigation arrow on hover.

Parameters
colorFill color when the mouse is hovering over an arrow.

◆ setArrowPlacement()

void ml::Carousel::setArrowPlacement ( ArrowPlacement placement)

Set the layout strategy for navigation arrows.

Parameters
placementOne of SIDES, TOP, or OVERLAY.

◆ setArrowPosition()

void ml::Carousel::setArrowPosition ( ArrowSide side,
sf::Vector2f position )

Override the auto-computed position of one arrow.

Bypasses the ArrowPlacement preset for the specified side. Call clearArrowPosition to revert.

Parameters
sideWhich arrow to reposition.
positionAbsolute world-space position for the arrow.

◆ setArrowSize()

void ml::Carousel::setArrowSize ( float size)

Set the size of both navigation arrows.

Parameters
sizeArrow width/height in pixels.

◆ setArrowTexture()

void ml::Carousel::setArrowTexture ( ArrowSide side,
sf::Texture texture )

Replace the default arrow rectangle with a custom texture.

Parameters
sideWhich arrow to replace (LEFT or RIGHT).
textureThe sf::Texture to use.

◆ setPosition()

void ml::Carousel::setPosition ( const sf::Vector2f & position)
override

◆ setPreviewCount()

void ml::Carousel::setPreviewCount ( int count)

Set how many items are visible in the carousel window at once.

Parameters
countNumber of visible items. Defaults to 5.

◆ setShader()

void ml::Carousel::setShader ( sf::Shader * shader,
std::function< void(sf::Shader &)> uniformSetter )

Set a custom GLSL shader with a per-frame uniform setter.

The uniformSetter is called once per frame before rendering so you can update time-dependent or state-dependent uniforms.

Parameters
shaderPointer to the sf::Shader to use. Must remain valid for the lifetime of the carousel.
uniformSetterCallback invoked each frame with the shader reference, used to push uniform values.

◆ setShaderParams()

void ml::Carousel::setShaderParams ( const ShaderLibrary::Params & params)

Set parameters forwarded to the active ShaderLibrary style.

Parameters
paramsParameter struct with style-specific fields.

◆ setSpacing()

void ml::Carousel::setSpacing ( float spacing)

Set the pixel gap between items.

Parameters
spacingGap in pixels. Defaults to 10.

◆ setSpeed()

void ml::Carousel::setSpeed ( float speed)

Set the scroll animation speed.

Parameters
speedPixels per frame (or per tick). Defaults to 1.

◆ setStyle()

void ml::Carousel::setStyle ( Style style)

Set a built-in shader style from ShaderLibrary.

Loads and activates one of the pre-built GLSL shaders. Replaces any previously set custom shader.

Parameters
styleThe ShaderLibrary::Style to apply.

◆ showArrows()

void ml::Carousel::showArrows ( bool show)

Show or hide the navigation arrows.

Parameters
showtrue to show arrows, false to hide.

The documentation for this class was generated from the following file: