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#include "qml_material/export.hpp"
7
8namespace qml_material
9{
10
11// Keep in sync with MD.Enum.CarouselLayout (include/qml_material/core/enum.hpp).
12namespace CarouselLayoutId
13{
14constexpr int Uncontained = 0;
15constexpr int MultiBrowse = 1;
16constexpr int Hero = 2;
17constexpr int HeroCenter = 3;
18constexpr int FullScreen = 4;
19constexpr int UncontainedMultiAspect = 5;
20} // namespace CarouselLayoutId
21
22// Keep in sync with qml_material::token::Carousel (MD.Token.carousel).
23struct CarouselEngineDefaults {
24 static constexpr qreal min_peek_px = 16;
25 static constexpr qreal parallax_ratio = 0.35;
26 static constexpr qreal parallax_ratio_uncontained = 0.5;
27 static constexpr int snap_duration = int(token::Duration {}.medium4);
28 static constexpr qreal min_item_aspect = 9.0 / 16.0;
29 static constexpr qreal max_item_aspect = 16.0 / 9.0;
30};
31
32struct CarouselItemGeometry {
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 int layout = 0;
44 Qt::Orientation orientation = Qt::Horizontal;
45 qreal viewport_size = 0;
46 qreal cross_size = 0;
47 qreal scroll_offset = 0;
48 qreal item_extent = 180;
49 qreal spacing = 8;
50 qreal small_item_min = 40;
51 qreal small_item_max = 56;
52 qreal content_padding_start = 0;
53 qreal content_padding_end = 0;
54 qreal content_padding_cross = 0;
55 qreal min_peek_px = 16;
56 qreal item_corner_radius = 28;
57 qreal parallax_ratio = 0.35;
58 qreal min_item_aspect = 9.0 / 16.0;
59 qreal max_item_aspect = 16.0 / 9.0;
60 int count = 0;
61 bool reduce_motion = false;
62 QVector<qreal> item_aspects;
63};
64
65struct CarouselLayoutOutput {
66 QVector<CarouselItemGeometry> items;
68 QVector<qreal> snap_offsets;
69 qreal content_size = 0;
70 qreal max_scroll_offset = 0;
71 qreal end_snap_offset = 0;
72 qreal scroll_step = 0;
73 int leading_index = 0;
74};
75
76class QML_MATERIAL_API CarouselStrategy {
77public:
78 static auto compute(const CarouselLayoutInput& input) -> CarouselLayoutOutput;
79};
80
81} // namespace qml_material