LCOV - code coverage report
Current view: top level - xenolith/renderer/material2d/components/sidebar - MaterialNavigationDrawer.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 23 46 50.0 %
Date: 2024-05-12 00:16:13 Functions: 6 13 46.2 %

          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             : #include "MaterialNavigationDrawer.h"
      24             : #include "MaterialMenuSource.h"
      25             : #include "MaterialMenu.h"
      26             : #include "MaterialMenuButton.h"
      27             : #include "MaterialStyleContainer.h"
      28             : #include "MaterialScene.h"
      29             : #include "XLEventListener.h"
      30             : #include "XLInputListener.h"
      31             : 
      32             : namespace STAPPLER_VERSIONIZED stappler::xenolith::material2d {
      33             : 
      34             : XL_DECLARE_EVENT_CLASS(NavigationDrawer, onNavigation);
      35             : 
      36          20 : NavigationDrawer::~NavigationDrawer() { }
      37             : 
      38          10 : bool NavigationDrawer::init() {
      39          10 :         if (!Sidebar::init(Sidebar::Left)) {
      40           0 :                 return false;
      41             :         }
      42             : 
      43          10 :         _navigation = setNode(Rc<Menu>::create(), ZOrder(1));
      44          10 :         _navigation->setAnchorPoint(Vec2(0, 0));
      45          10 :         _navigation->setMenuButtonCallback([this] (MenuButton *b) {
      46           0 :                 if (!b->getMenuSourceButton()->getNextMenu()) {
      47           0 :                         hide();
      48             :                 }
      49           0 :         });
      50          10 :         _navigation->setEnabled(false);
      51             : 
      52             :         /*_statusBarLayer = _navigation->addChild(Rc<Layer>::create(), 100);
      53             :         _statusBarLayer->setColor(Color::Grey_500);
      54             :         _statusBarLayer->setAnchorPoint(Vec2(0.0f, 1.0f));*/
      55             : 
      56          10 :         setBackgroundPassiveOpacity(0.0f);
      57          10 :         setBackgroundActiveOpacity(0.5f);
      58             : 
      59          10 :         _navigation->setEnabled(false);
      60          10 :         _listener->setEnabled(false);
      61             : 
      62          10 :         setNodeWidthCallback([] (const Size2 &size) {
      63          10 :                 return std::min(size.width - 56, 64.0f * 5.0f);
      64             :         });
      65             : 
      66          10 :         return true;
      67             : }
      68             : 
      69          10 : void NavigationDrawer::onContentSizeDirty() {
      70          10 :         Sidebar::onContentSizeDirty();
      71             : 
      72          10 :         if (auto source = _navigation->getMenuSource()) {
      73           0 :                 source->setDirty();
      74             :         }
      75          10 : }
      76             : 
      77           0 : Menu *NavigationDrawer::getNavigationMenu() const {
      78           0 :         return _navigation;
      79             : }
      80             : 
      81           0 : MenuSource *NavigationDrawer::getMenuSource() const {
      82           0 :         return _navigation->getMenuSource();
      83             : }
      84           0 : void NavigationDrawer::setMenuSource(MenuSource *source) {
      85           0 :         _listener->setEnabled(source != nullptr);
      86           0 :         _navigation->setMenuSource(source);
      87           0 : }
      88             : 
      89           0 : void NavigationDrawer::setStyle(const SurfaceStyle &style) {
      90           0 :         _navigation->setStyle(style);
      91           0 : }
      92             : 
      93           0 : void NavigationDrawer::setStatusBarColor(const Color &color) {
      94           0 :         _statusBarLayer->setColor(color);
      95           0 : }
      96             : 
      97           0 : void NavigationDrawer::onNodeEnabled(bool value) {
      98           0 :         Sidebar::onNodeEnabled(value);
      99           0 :         _navigation->setEnabled(value);
     100           0 : }
     101             : 
     102          10 : void NavigationDrawer::onNodeVisible(bool value) {
     103          10 :         Sidebar::onNodeVisible(value);
     104          10 :         _navigation->getScroll()->setScrollDirty(true);
     105          10 :         onNavigation(this, value);
     106          10 : }
     107             : 
     108             : }

Generated by: LCOV version 1.14