LCOV - code coverage report
Current view: top level - xenolith/scene/nodes - XLSceneContent.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 56 60 93.3 %
Date: 2024-05-12 00:16:13 Functions: 12 13 92.3 %

          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             : #include "XLSceneContent.h"
      24             : #include "XLInputListener.h"
      25             : #include "XLDirector.h"
      26             : #include "XLView.h"
      27             : 
      28             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      29             : 
      30          21 : SceneContent::~SceneContent() { }
      31             : 
      32          21 : bool SceneContent::init() {
      33          21 :         if (!DynamicStateNode::init()) {
      34           0 :                 return false;
      35             :         }
      36             : 
      37          21 :         _inputListener = addInputListener(Rc<InputListener>::create());
      38          21 :         _inputListener->setPriority(-1);
      39          21 :         _inputListener->setDedicatedFocus(maxOf<uint32_t>());
      40          21 :         _inputListener->addKeyRecognizer([this] (GestureData data) {
      41          42 :                 if (data.event == GestureEvent::Ended) {
      42          21 :                         return onBackButton();
      43             :                 }
      44          21 :                 return data.event == GestureEvent::Began;
      45          21 :         }, InputListener::makeKeyMask({InputKeyCode::ESCAPE}));
      46             : 
      47          21 :         _inputListener->setBackgroudCallback([this] (bool val) -> bool {
      48          42 :                 handleBackgroundTransition(val);
      49          42 :                 return true;
      50             :         });
      51             : 
      52          21 :         return true;
      53             : }
      54             : 
      55          21 : void SceneContent::onEnter(Scene *scene) {
      56          21 :         DynamicStateNode::onEnter(scene);
      57             : 
      58          21 :         if (_retainBackButton && !_backButtonRetained) {
      59           0 :                 _director->getView()->retainBackButton();
      60           0 :                 _backButtonRetained = true;
      61             :         }
      62             : 
      63          21 :         if (_handlesViewDecoration) {
      64          21 :                 if (_decorationVisible) {
      65          21 :                         showViewDecoration();
      66             :                 } else {
      67           0 :                         hideViewDecoration();
      68             :                 }
      69             :         }
      70          21 : }
      71             : 
      72          21 : void SceneContent::onExit() {
      73          21 :         if (_retainBackButton && _backButtonRetained) {
      74          21 :                 _director->getView()->releaseBackButton();
      75          21 :                 _backButtonRetained = false;
      76             :         }
      77             : 
      78          21 :         DynamicStateNode::onExit();
      79          21 : }
      80             : 
      81          42 : void SceneContent::onContentSizeDirty() {
      82          42 :         Node::onContentSizeDirty();
      83          42 : }
      84             : 
      85             : SP_COVERAGE_TRIVIAL
      86             : void SceneContent::updateBackButtonStatus() { }
      87             : 
      88          42 : void SceneContent::handleBackgroundTransition(bool val) { }
      89             : 
      90             : SP_COVERAGE_TRIVIAL
      91             : bool SceneContent::onBackButton() {
      92             :         return false;
      93             : }
      94             : 
      95          84 : void SceneContent::setHandlesViewDecoration(bool value) {
      96          84 :         if (_handlesViewDecoration != value) {
      97          84 :                 _handlesViewDecoration = value;
      98          84 :                 if (_decorationVisible) {
      99          42 :                         showViewDecoration();
     100             :                 } else {
     101          42 :                         hideViewDecoration();
     102             :                 }
     103             :         }
     104          84 : }
     105             : 
     106         191 : void SceneContent::showViewDecoration() {
     107         191 :         if (_decorationVisible != true) {
     108          42 :                 if (_running && _handlesViewDecoration) {
     109          42 :                         _director->getView()->setDecorationVisible(true);
     110             :                 }
     111          42 :                 _decorationVisible = true;
     112             :         }
     113         191 : }
     114             : 
     115          84 : void SceneContent::hideViewDecoration() {
     116          84 :         if (_decorationVisible != false) {
     117          42 :                 if (_running && _handlesViewDecoration) {
     118          42 :                         _director->getView()->setDecorationVisible(false);
     119             :                 }
     120          42 :                 _decorationVisible = false;
     121             :         }
     122          84 : }
     123             : 
     124         231 : void SceneContent::setDecorationPadding(Padding padding) {
     125         231 :         if (padding != _decorationPadding) {
     126          21 :                 _decorationPadding = padding;
     127          21 :                 _contentSizeDirty = true;
     128             :         }
     129         231 : }
     130             : 
     131             : }

Generated by: LCOV version 1.14