Line data Source code
1 : /** 2 : Copyright (c) 2023 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_APPBAR_MATERIALAPPBAR_H_ 24 : #define XENOLITH_RENDERER_MATERIAL2D_COMPONENTS_APPBAR_MATERIALAPPBAR_H_ 25 : 26 : #include "MaterialSurface.h" 27 : #include "MaterialMenuSource.h" 28 : #include "MaterialLabel.h" 29 : #include "XLSubscriptionListener.h" 30 : #include "XLIcons.h" 31 : 32 : namespace STAPPLER_VERSIONIZED stappler::xenolith::material2d { 33 : 34 : enum class AppBarLayout { 35 : CenterAligned, 36 : Small, 37 : Medium, 38 : Large, 39 : Minified 40 : }; 41 : 42 : class AppBar : public Surface { 43 : public: 44 : static constexpr SurfaceStyle DefaultAppBarStyle = SurfaceStyle(NodeStyle::SurfaceTonal, ColorRole::Primary, Elevation::Level0); 45 : 46 20 : virtual ~AppBar() { } 47 : 48 : virtual bool init(AppBarLayout = AppBarLayout::Small, const SurfaceStyle & = DefaultAppBarStyle); 49 : virtual void onContentSizeDirty() override; 50 : 51 : virtual void setLayout(AppBarLayout); 52 0 : virtual AppBarLayout getLayout() const { return _layout; } 53 : 54 : virtual void setTitle(StringView); 55 : virtual StringView getTitle() const; 56 : 57 : virtual void setNavButtonIcon(IconName, float progress = 0.0f); 58 : virtual IconName getNavButtonIcon() const; 59 : 60 : virtual void setMaxActionIcons(size_t value); 61 : virtual size_t getMaxActionIcons() const; 62 : 63 : virtual void setActionMenuSource(MenuSource *); 64 : virtual void replaceActionMenuSource(MenuSource *, size_t maxIcons = maxOf<size_t>()); 65 : virtual MenuSource * getActionMenuSource() const; 66 : 67 : virtual void setBasicHeight(float value); 68 : virtual float getBasicHeight() const; 69 : 70 : virtual void setNavCallback(Function<void()> &&); 71 : virtual const Function<void()> & getNavCallback() const; 72 : 73 : virtual void setSwallowTouches(bool value); 74 : virtual bool isSwallowTouches() const; 75 : 76 : virtual void setBarCallback(Function<void()> &&); 77 : virtual const Function<void()> & getBarCallback() const; 78 : 79 : Button *getNavNode() const; 80 : 81 : protected: 82 : virtual void handleNavTapped(); 83 : 84 : virtual void updateProgress(); 85 : virtual float updateMenu(Node *composer, MenuSource *source, size_t maxIcons); 86 : virtual void layoutSubviews(); 87 : 88 : virtual float getBaseLine() const; 89 : virtual float getRealHeight() const; 90 : 91 : virtual void updateDefaultHeight(); 92 : 93 : AppBarLayout _layout = AppBarLayout::Small; 94 : TypescaleLabel *_label = nullptr; 95 : Button *_navButton = nullptr; 96 : 97 : size_t _maxActionIcons = 3; 98 : DynamicStateNode *_scissorNode = nullptr; 99 : Node *_iconsComposer = nullptr; 100 : Node *_prevComposer = nullptr; 101 : 102 : DataListener<MenuSource> *_actionMenuSourceListener = nullptr; 103 : 104 : Function<void()> _navCallback = nullptr; 105 : Function<void()> _barCallback = nullptr; 106 : 107 : float _replaceProgress = 1.0f; 108 : float _defaultHeight = 56.0f; 109 : float _basicHeight = nan(); 110 : float _iconWidth = 0.0f; 111 : 112 : InputListener *_inputListener = nullptr; 113 : }; 114 : 115 : } 116 : 117 : #endif /* XENOLITH_RENDERER_MATERIAL2D_COMPONENTS_APPBAR_MATERIALAPPBAR_H_ */