Line data Source code
1 : /** 2 : Copyright (c) 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_COMPONENTS_SIDEBAR_MATERIALSIDEBAR_H_ 24 : #define XENOLITH_RENDERER_MATERIAL2D_COMPONENTS_SIDEBAR_MATERIALSIDEBAR_H_ 25 : 26 : #include "MaterialSurface.h" 27 : #include "XL2dLayer.h" 28 : 29 : namespace STAPPLER_VERSIONIZED stappler::xenolith::material2d { 30 : 31 : class Sidebar : public Node { 32 : public: 33 : enum Position { 34 : Left, 35 : Right 36 : }; 37 : 38 : using WidthCallback = Function<float(const Size2 &)>; 39 : using BoolCallback = Function<void(bool)>; 40 : 41 : virtual ~Sidebar(); 42 : 43 : virtual bool init(Position); 44 : virtual void onContentSizeDirty() override; 45 : 46 : template <typename T, typename ... Args> 47 10 : auto setNode(const Rc<T> &ptr, Args && ... args) -> T * { 48 10 : setBaseNode(ptr.get(), std::forward<Args>(args)...); 49 10 : return ptr.get(); 50 : } 51 : 52 : virtual void setBaseNode(Node *m, ZOrder zOrder = ZOrder(0)); 53 : virtual Node *getNode() const; 54 : 55 : virtual void setNodeWidth(float); 56 : virtual float getNodeWidth() const; 57 : 58 : virtual void setNodeWidthCallback(const WidthCallback &); 59 : virtual const WidthCallback &getNodeWidthCallback() const; 60 : 61 : virtual void setSwallowTouches(bool); 62 : virtual bool isSwallowTouches() const; 63 : 64 : virtual void setEdgeSwipeEnabled(bool); 65 : virtual bool isEdgeSwipeEnabled() const; 66 : 67 : virtual void setBackgroundActiveOpacity(float); 68 : virtual void setBackgroundPassiveOpacity(float); 69 : 70 : virtual void show(); 71 : virtual void hide(float factor = 1.0f); 72 : 73 : virtual float getProgress() const; 74 : 75 : virtual bool isNodeVisible() const; 76 : virtual bool isNodeEnabled() const; 77 : 78 : virtual void setNodeVisibleCallback(BoolCallback &&); 79 : virtual void setNodeEnabledCallback(BoolCallback &&); 80 : 81 : virtual void setEnabled(bool value); 82 : virtual bool isEnabled() const; 83 : 84 : protected: 85 : virtual void setProgress(float); 86 : 87 : virtual void onSwipeDelta(float); 88 : virtual void onSwipeFinished(float); 89 : 90 : virtual void onNodeEnabled(bool value); 91 : virtual void onNodeVisible(bool value); 92 : 93 : virtual void stopNodeActions(); 94 : 95 : WidthCallback _widthCallback; 96 : float _nodeWidth = 0.0f; 97 : 98 : Position _position = Position::Left; 99 : bool _swallowTouches = true; 100 : bool _edgeSwipeEnabled = true; 101 : float _backgroundActiveOpacity = 0.25f; 102 : float _backgroundPassiveOpacity = 0.0f; 103 : 104 : InputListener *_listener = nullptr; 105 : 106 : Layer *_background = nullptr; 107 : Node *_node = nullptr; 108 : 109 : BoolCallback _visibleCallback = nullptr; 110 : BoolCallback _enabledCallback = nullptr; 111 : }; 112 : 113 : } 114 : 115 : #endif /* XENOLITH_RENDERER_MATERIAL2D_COMPONENTS_SIDEBAR_MATERIALSIDEBAR_H_ */