QmlMaterial 0.1.0
Loading...
Searching...
No Matches
carousel_strategy.hpp
1#pragma once
2
3#include <QVector>
4#include <Qt>
5
6namespace qml_material
7{
8
9// Keep in sync with MD.Enum.CarouselLayout (include/qml_material/core/enum.hpp).
10namespace CarouselLayoutId
11{
12constexpr int Uncontained = 0;
13constexpr int MultiBrowse = 1;
14constexpr int Hero = 2;
15constexpr int HeroCenter = 3;
16constexpr int FullScreen = 4;
17constexpr int UncontainedMultiAspect = 5;
18} // namespace CarouselLayoutId
19
20// Keep in sync with qml_material::token::Carousel (MD.Token.carousel).
21struct CarouselEngineDefaults
22{
23 static constexpr qreal min_peek_px = 16;
24 static constexpr qreal parallax_ratio = 0.35;
25 static constexpr qreal parallax_ratio_uncontained = 0.5;
26 static constexpr int snap_duration = 400;
27 static constexpr qreal min_item_aspect = 9.0 / 16.0;
28 static constexpr qreal max_item_aspect = 16.0 / 9.0;
29};
30
31struct CarouselItemGeometry
32{
33 int index = 0;
34 qreal position = 0;
35 qreal size = 0;
36 qreal mask_start = 0;
37 qreal mask_end = 0;
38 qreal parallax_shift = 0;
39 int size_class = 2; // CarouselSizeLarge
40};
41
42struct CarouselLayoutInput
43{
44 int layout = 0;
45 Qt::Orientation orientation = Qt::Horizontal;
46 qreal viewport_size = 0;
47 qreal cross_size = 0;
48 qreal scroll_offset = 0;
49 qreal item_extent = 180;
50 qreal spacing = 8;
51 qreal small_item_min = 40;
52 qreal small_item_max = 56;
53 qreal content_padding_start = 0;
54 qreal content_padding_end = 0;
55 qreal content_padding_cross = 0;
56 qreal min_peek_px = 16;
57 qreal item_corner_radius = 28;
58 qreal parallax_ratio = 0.35;
59 qreal min_item_aspect = 9.0 / 16.0;
60 qreal max_item_aspect = 16.0 / 9.0;
61 int count = 0;
62 bool reduce_motion = false;
63 QVector<qreal> item_aspects;
64};
65
66struct CarouselLayoutOutput
67{
68 QVector<CarouselItemGeometry> items;
70 QVector<qreal> snap_offsets;
71 qreal content_size = 0;
72 qreal max_scroll_offset = 0;
73 qreal end_snap_offset = 0;
74 qreal scroll_step = 0;
75 int leading_index = 0;
76};
77
78class CarouselStrategy
79{
80public:
81 static auto compute(const CarouselLayoutInput& input) -> CarouselLayoutOutput;
82};
83
84} // namespace qml_material