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

          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_MENU_MATERIALMENU_H_
      24             : #define XENOLITH_RENDERER_MATERIAL2D_COMPONENTS_MENU_MATERIALMENU_H_
      25             : 
      26             : #include "MaterialMenuSource.h"
      27             : #include "MaterialSurface.h"
      28             : #include "XLSubscriptionListener.h"
      29             : #include "XL2dScrollView.h"
      30             : 
      31             : namespace STAPPLER_VERSIONIZED stappler::xenolith::material2d {
      32             : 
      33             : class Menu;
      34             : class MenuButton;
      35             : class MenuSeparator;
      36             : 
      37             : class MenuItemInterface {
      38             : public:
      39          50 :         virtual ~MenuItemInterface() { }
      40             : 
      41          50 :         virtual void setMenu(Menu *m) { _menu = m; }
      42          10 :         virtual Menu *getMenu() const { return _menu; }
      43             : 
      44             : protected:
      45             :         Menu *_menu = nullptr;
      46             : };
      47             : 
      48             : class Menu : public Surface {
      49             : public:
      50             :         constexpr static float MenuVerticalPadding = 16.0f;
      51             :         constexpr static float MenuItemHeight = 48.0f;
      52             :         constexpr static float MenuHorizontalIncrement = 56.0f;
      53             :         constexpr static float MenuLeadingHeight = 4.0f;
      54             :         constexpr static float MenuTrailingHeight = 8.0f;
      55             : 
      56             :         using ButtonCallback = Function<void(MenuButton *button)>;
      57             : 
      58             :         virtual ~Menu();
      59             : 
      60             :         virtual bool init() override;
      61             :         virtual bool init(MenuSource *source);
      62             : 
      63             :         virtual void setMenuSource(MenuSource *);
      64             :         virtual MenuSource *getMenuSource() const;
      65             : 
      66             :         virtual void setEnabled(bool value);
      67             :         virtual bool isEnabled() const;
      68             : 
      69             :         virtual void setMenuButtonCallback(const ButtonCallback &cb);
      70             :         virtual const ButtonCallback & getMenuButtonCallback();
      71             : 
      72             :         virtual void onMenuButtonPressed(MenuButton *button);
      73             :         virtual void layoutSubviews();
      74             : 
      75             :         virtual void onContentSizeDirty() override;
      76             : 
      77             :         virtual ScrollView *getScroll() const;
      78             : 
      79          10 :         virtual DataListener<MenuSource> *getDataListener() const { return _menuListener; }
      80             : 
      81             : protected:
      82             :         virtual void rebuildMenu();
      83             :         virtual Rc<MenuButton> createButton(Menu *m, MenuSourceButton *btn);
      84             :         virtual Rc<MenuSeparator> createSeparator(Menu *m, MenuSourceItem *btn);
      85             : 
      86             :         virtual void handleSourceDirty();
      87             : 
      88             :         ScrollView *_scroll = nullptr;
      89             :         ScrollController *_controller = nullptr;
      90             :         DataListener<MenuSource> *_menuListener = nullptr;
      91             :         ButtonCallback _callback = nullptr;
      92             : };
      93             : 
      94             : }
      95             : 
      96             : #endif /* XENOLITH_RENDERER_MATERIAL2D_COMPONENTS_MENU_MATERIALMENU_H_ */

Generated by: LCOV version 1.14