LCOV - code coverage report
Current view: top level - xenolith/renderer/material2d/layout - MaterialFlexibleLayout.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 11 11 100.0 %
Date: 2024-05-12 00:16:13 Functions: 5 6 83.3 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023-2024 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #ifndef XENOLITH_RENDERER_MATERIAL2D_LAYOUT_MATERIALFLEXIBLELAYOUT_H_
      24             : #define XENOLITH_RENDERER_MATERIAL2D_LAYOUT_MATERIALFLEXIBLELAYOUT_H_
      25             : 
      26             : #include "MaterialDecoratedLayout.h"
      27             : #include "MaterialSurface.h"
      28             : #include "XL2dScrollView.h"
      29             : 
      30             : namespace STAPPLER_VERSIONIZED stappler::xenolith::material2d {
      31             : 
      32             : class AppBar;
      33             : 
      34             : class FlexibleLayout : public DecoratedLayout {
      35             : public:
      36             :         struct NodeParams {
      37             :                 enum Mask {
      38             :                         None = 0,
      39             :                         Position = 1 << 0,
      40             :                         ContentSize = 1 << 1,
      41             :                         AnchorPoint = 1 << 2,
      42             :                         Visibility = 1 << 3,
      43             :                 };
      44             : 
      45             :                 void setPosition(float x, float y);
      46             :                 void setPosition(const Vec2 &pos);
      47             :                 void setAnchorPoint(const Vec2 &pt);
      48             :                 void setContentSize(const Size2 &size);
      49             :                 void setVisible(bool value);
      50             :                 void apply(Node *) const;
      51             : 
      52             :                 Mask mask = None;
      53             :                 Vec2 position;
      54             :                 Vec2 anchorPoint;
      55             :                 Size2 contentSize;
      56             :                 bool visible = false;
      57             :         };
      58             : 
      59             :         using HeightFunction = Function<Pair<float, float>()>; // pair< min, max >
      60             : 
      61          12 :         virtual ~FlexibleLayout() { }
      62             : 
      63             :         virtual bool init() override;
      64             :         virtual void onContentSizeDirty() override;
      65             : 
      66             :         template <typename T, typename ... Args>
      67           2 :         auto setBaseNode(const Rc<T> &ptr, Args && ... args) -> T * {
      68           2 :                 setBaseNode(ptr.get(), std::forward<Args>(args)...);
      69           2 :                 return ptr.get();
      70             :         }
      71             : 
      72             :         template <typename T, typename ... Args>
      73           2 :         auto setFlexibleNode(const Rc<T> &ptr, Args && ... args) -> T * {
      74           2 :                 setFlexibleNode(ptr.get(), std::forward<Args>(args)...);
      75           2 :                 return ptr.get();
      76             :         }
      77             : 
      78           2 :         virtual void setBaseNode(ScrollView *node, ZOrder zOrder = ZOrder(2));
      79           2 :         virtual void setFlexibleNode(Surface *, ZOrder zOrder = ZOrder(3));
      80             : 
      81             :         virtual void setFlexibleAutoComplete(bool value);
      82             : 
      83             :         virtual void setFlexibleMinHeight(float height);
      84             :         virtual float getFlexibleMinHeight() const;
      85             : 
      86             :         virtual void setFlexibleMaxHeight(float height);
      87             :         virtual float getFlexibleMaxHeight() const;
      88             : 
      89             :         virtual void setFlexibleBaseNode(bool val);
      90             :         virtual bool isFlexibleBaseNode() const;
      91             : 
      92             :         virtual void setFlexibleHeightFunction(const HeightFunction &);
      93             :         virtual const HeightFunction &getFlexibleHeightFunction() const;
      94             : 
      95             :         virtual float getFlexibleLevel() const;
      96             :         virtual void setFlexibleLevel(float value);
      97             :         virtual void setFlexibleLevelAnimated(float value, float duration);
      98             :         virtual void setFlexibleHeight(float value);
      99             : 
     100             :         virtual void setBaseNodePadding(float);
     101             :         virtual float getBaseNodePadding() const;
     102             : 
     103             :         float getCurrentFlexibleHeight() const;
     104             :         float getCurrentFlexibleMax() const;
     105             : 
     106             :         virtual void onPush(SceneContent2d *l, bool replace) override;
     107             :         virtual void onForegroundTransitionBegan(SceneContent2d *l, SceneLayout2d *overlay) override;
     108             : 
     109             :         // Безопасный триггер препятствует анимации, пока достаточный объём скролла не пройден
     110             :         virtual void setSafeTrigger(bool value);
     111             :         virtual bool isSafeTrigger() const;
     112             : 
     113             :         virtual void expandFlexibleNode(float extraSpace, float animation = 0.0f);
     114             :         virtual void clearFlexibleExpand(float animation = 0.0f);
     115             : 
     116             :         virtual DecorationStatus getDecorationStatus() const override;
     117             : 
     118          10 :         AppBar *getAppBar() const { return _appBar; }
     119             : 
     120             : protected:
     121             :         virtual void updateFlexParams();
     122             :         virtual void onScroll(float delta, bool finished);
     123             :         virtual void onDecorNode(const NodeParams &);
     124             :         virtual void onFlexibleNode(const NodeParams &);
     125             :         virtual void onBaseNode(const NodeParams &, const Padding &, float offset);
     126             : 
     127         210 :         static constexpr int AutoCompleteTag() { return 5; }
     128             : 
     129             :         bool _flexibleAutoComplete = true;
     130             :         bool _flexibleBaseNode = true;
     131             :         bool _safeTrigger = true;
     132             : 
     133             :         float _flexibleLevel = 1.0f;
     134             :         float _baseNodePadding = 4.0f;
     135             : 
     136             :         float _flexibleExtraSpace = 0.0f;
     137             : 
     138             :         float _targetFlexibleMinHeight = 0.0f;
     139             :         float _targetFlexibleMaxHeight = 0.0f;
     140             : 
     141             :         float _realFlexibleMinHeight = 0.0f;
     142             :         float _realFlexibleMaxHeight = 0.0f;
     143             : 
     144             :         HeightFunction _flexibleHeightFunction = nullptr;
     145             : 
     146             :         Surface *_flexibleNode = nullptr;
     147             :         ScrollView *_baseNode = nullptr;
     148             :         AppBar *_appBar = nullptr;
     149             : };
     150             : 
     151             : }
     152             : 
     153             : #endif /* XENOLITH_RENDERER_MATERIAL2D_LAYOUT_MATERIALFLEXIBLELAYOUT_H_ */

Generated by: LCOV version 1.14