| 1 | // Copyright (C) 2025 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICKFLEXBOXLAYOUTITEM_P_H |
| 5 | #define QQUICKFLEXBOXLAYOUTITEM_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtQuick/private/qquickitem_p.h> |
| 19 | #include <QtQuickLayouts/private/qquickflexboxlayout_p.h> |
| 20 | #include <yoga/Yoga.h> |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | struct SizeHints { |
| 25 | inline QSizeF &min() { return array[Qt::MinimumSize]; } |
| 26 | inline QSizeF &pref() { return array[Qt::PreferredSize]; } |
| 27 | inline QSizeF &max() { return array[Qt::MaximumSize]; } |
| 28 | QSizeF array[Qt::NSizeHints]; |
| 29 | }; |
| 30 | |
| 31 | class QQuickFlexboxLayoutItem |
| 32 | { |
| 33 | public: |
| 34 | explicit QQuickFlexboxLayoutItem(QQuickItem *item); |
| 35 | ~QQuickFlexboxLayoutItem(); |
| 36 | |
| 37 | void resetDefault(); |
| 38 | void resetMargins(); |
| 39 | void resetPaddings(); |
| 40 | void resetSize(); |
| 41 | |
| 42 | QQuickItem *quickItem() const { return m_item; } |
| 43 | YGNodeRef yogaItem() const { return m_yogaNode; } |
| 44 | |
| 45 | void insertChild(QQuickFlexboxLayoutItem *item, int index); |
| 46 | |
| 47 | // Adapter APIs to the yoga library |
| 48 | void setMinSize(const QSizeF &size); |
| 49 | void setSize(const QSizeF &size); |
| 50 | void setWidth(const qreal &width); |
| 51 | void setHeight(const qreal &height); |
| 52 | void setMaxSize(const QSizeF &size); |
| 53 | void setFlexBasis(qreal value, bool reset = false); |
| 54 | void setFlexDirection(QQuickFlexboxLayout::FlexboxDirection direction); |
| 55 | void setFlexWrap(QQuickFlexboxLayout::FlexboxWrap wrap); |
| 56 | void setFlexAlignItemsProperty(QQuickFlexboxLayout::FlexboxAlignment align); |
| 57 | void setFlexAlignSelfProperty(QQuickFlexboxLayout::FlexboxAlignment align); |
| 58 | void setFlexAlignContentProperty(QQuickFlexboxLayout::FlexboxAlignment align); |
| 59 | void setFlexJustifyContentProperty(QQuickFlexboxLayout::FlexboxJustify justify); |
| 60 | void setItemGrowAlongMainAxis(qreal value); |
| 61 | void setItemShrinkAlongMainAxis(qreal value); |
| 62 | void setFlexMargin(QQuickFlexboxLayout::FlexboxEdge edge, qreal value); |
| 63 | void setFlexPadding(QQuickFlexboxLayout::FlexboxEdge edge, qreal value); |
| 64 | void setItemStretchAlongCrossSection(); |
| 65 | void setFlexGap(QQuickFlexboxLayout::FlexboxGap gap, qreal value); |
| 66 | void inheritItemStretchAlongCrossSection(); |
| 67 | |
| 68 | bool hasMeasureFunc() const; |
| 69 | void resetMeasureFunc(); |
| 70 | QPoint position() const; |
| 71 | QSizeF size() const; |
| 72 | bool isFlexBasisUndefined() const; |
| 73 | bool isItemStreched() const; |
| 74 | QSizeF computedLayoutSize() { return m_computedLayoutSize; } |
| 75 | SizeHints &cachedItemSizeHints() const; |
| 76 | void computeLayout(const QSizeF &size = QSizeF()); |
| 77 | |
| 78 | private: |
| 79 | QQuickItem *m_item; |
| 80 | YGNodeRef m_yogaNode; |
| 81 | QSizeF m_computedLayoutSize; |
| 82 | mutable SizeHints m_cachedSizeHint; |
| 83 | }; |
| 84 | |
| 85 | QT_END_NAMESPACE |
| 86 | |
| 87 | #endif // QQUICKFLEXBOXLAYOUTITEM_P_H |
| 88 |
