LCOV - code coverage report
Current view: top level - xenolith/renderer/material2d/components/menu - MaterialTabBar.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2024-05-12 00:16:13 Functions: 2 2 100.0 %

          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_MENU_MATERIALTABBAR_H_
      24             : #define XENOLITH_RENDERER_MATERIAL2D_COMPONENTS_MENU_MATERIALTABBAR_H_
      25             : 
      26             : #include "MaterialMenuSource.h"
      27             : #include "MaterialButton.h"
      28             : #include "MaterialLabel.h"
      29             : #include "XLSubscriptionListener.h"
      30             : #include "XL2dScrollView.h"
      31             : #include "XL2dLayer.h"
      32             : 
      33             : namespace STAPPLER_VERSIONIZED stappler::xenolith::material2d {
      34             : 
      35             : class TabBar : public Surface {
      36             : public:
      37             :         enum class ButtonStyle {
      38             :                 Title,
      39             :                 Icon,
      40             :                 TitleIcon,
      41             :         };
      42             : 
      43             :         enum class BarStyle {
      44             :                 Layout,
      45             :                 Scroll,
      46             :         };
      47             : 
      48             :         using Alignment = Label::TextAlign;
      49             : 
      50           4 :         virtual ~TabBar() { }
      51             : 
      52             :         virtual bool init(MenuSource *, ButtonStyle = ButtonStyle::Title, BarStyle = BarStyle::Layout, Alignment = Alignment::Center);
      53             :         virtual void onContentSizeDirty() override;
      54             : 
      55             :         virtual void setMenuSource(MenuSource *);
      56             :         virtual MenuSource *getMenuSource() const;
      57             : 
      58             :         virtual void setAccentColor(const ColorRole &);
      59             :         virtual ColorRole getAccentColor() const;
      60             : 
      61             :         virtual void setButtonStyle(const ButtonStyle &);
      62             :         virtual const ButtonStyle & getButtonStyle() const;
      63             : 
      64             :         virtual void setBarStyle(const BarStyle &);
      65             :         virtual const BarStyle & getBarStyle() const;
      66             : 
      67             :         virtual void setAlignment(const Alignment &);
      68             :         virtual const Alignment & getAlignment() const;
      69             : 
      70             :         virtual void setSelectedIndex(size_t);
      71             :         virtual size_t getSelectedIndex() const;
      72             : 
      73             :         virtual void setProgress(float prog);
      74             : 
      75             : protected:
      76             :         virtual void setSelectedTabIndex(size_t);
      77             :         virtual void onMenuSource();
      78             :         virtual void onScrollPosition();
      79             :         virtual void onScrollPositionProgress(float);
      80             : 
      81             :         virtual float getItemSize(const String &, bool extended = false, bool selected = false) const;
      82             :         virtual Rc<Node> onItem(MenuSourceButton *, bool wrapped);
      83             :         virtual void onTabButton(Button *, MenuSourceButton *);
      84             : 
      85             :         virtual void applyStyle(StyleContainer *, const SurfaceStyleData &style) override;
      86             : 
      87             :         Alignment _alignment = Alignment::Center;
      88             :         ButtonStyle _buttonStyle = ButtonStyle::Title;
      89             :         BarStyle _barStyle = BarStyle::Layout;
      90             :         ColorRole _accentColor = ColorRole::PrimaryContainer;
      91             :         ScrollView *_scroll = nullptr;
      92             : 
      93             :         Layer *_layer = nullptr;
      94             :         IconSprite *_left = nullptr;
      95             :         IconSprite *_right = nullptr;
      96             :         DataListener<MenuSource> *_source = nullptr;
      97             :         Rc<MenuSource> _extra;
      98             :         size_t _buttonCount = 0;
      99             :         float _scrollWidth = 0.0f;
     100             : 
     101             :         size_t _selectedIndex = maxOf<size_t>();
     102             :         Vector<Pair<float, float>> _positions;
     103             : };
     104             : 
     105             : class TabBarButton : public Button {
     106             : public:
     107             :         using TabButtonCallback = Function<void(Button *, MenuSourceButton *)>;
     108             : 
     109             :         virtual bool init(MenuSourceButton *, const TabButtonCallback &cb, TabBar::ButtonStyle, bool swallow, bool wrapped);
     110             :         virtual bool init(MenuSource *, const TabButtonCallback &cb, TabBar::ButtonStyle, bool swallow, bool wrapped);
     111             : 
     112             : protected:
     113             :         virtual void initialize(const TabButtonCallback &, TabBar::ButtonStyle, bool swallow, bool wrapped);
     114             : 
     115             :         virtual void onTabButton();
     116             : 
     117             :         virtual void layoutContent() override;
     118             : 
     119             :         TabBar::ButtonStyle _tabStyle;
     120             :         bool _wrapped = false;
     121             :         TabButtonCallback _tabButtonCallback = nullptr;
     122             : };
     123             : 
     124             : }
     125             : 
     126             : #endif /* XENOLITH_RENDERER_MATERIAL2D_COMPONENTS_MENU_MATERIALTABBAR_H_ */

Generated by: LCOV version 1.14