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