LCOV - code coverage report
Current view: top level - xenolith/renderer/material2d/components/menu - MaterialMenuSeparator.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 29 37 78.4 %
Date: 2024-05-12 00:16:13 Functions: 7 8 87.5 %

          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 "MaterialMenuSeparator.h"
      24             : #include "MaterialStyleMonitor.h"
      25             : 
      26             : namespace STAPPLER_VERSIONIZED stappler::xenolith::material2d {
      27             : 
      28          20 : MenuSeparator::~MenuSeparator() { }
      29             : 
      30          10 : bool MenuSeparator::init(Menu *menu, MenuSourceItem *item) {
      31          10 :         if (!Node::init()) {
      32           0 :                 return false;
      33             :         }
      34             : 
      35          10 :         setCascadeColorEnabled(true);
      36             : 
      37          10 :         _color = addChild(Rc<Layer>::create());
      38          10 :         _color->setOpacity(OpacityValue(32));
      39          10 :         _color->setColor(Color::Black);
      40          10 :         _color->setAnchorPoint(Vec2(0, 0.5f));
      41          10 :         _color->setPosition(Vec2(0, 0));
      42             : 
      43          10 :         _contentSizeDirty = true;
      44             : 
      45          10 :         _itemListener = addComponent(Rc<DataListener<MenuSourceItem>>::create([this] (SubscriptionFlags flags) {
      46          10 :                 handleSourceDirty();
      47          10 :         }));
      48          10 :         _itemListener->setSubscription(item);
      49             : 
      50          10 :         addComponent(Rc<StyleMonitor>::create([this] (const ColorScheme *scheme, const SurfaceStyleData &data) {
      51          10 :                 _color->setColor(scheme->get(ColorRole::Outline));
      52          10 :         }));
      53             : 
      54          10 :         setMenu(menu);
      55             : 
      56          10 :         return true;
      57             : }
      58             : 
      59          10 : void MenuSeparator::onContentSizeDirty() {
      60          10 :         Node::onContentSizeDirty();
      61          10 :         handleSourceDirty();
      62          10 : }
      63             : 
      64           0 : void MenuSeparator::setTopLevel(bool value) {
      65           0 :         if (value != _topLevel) {
      66           0 :                 _topLevel = value;
      67           0 :                 handleSourceDirty();
      68             :         }
      69           0 : }
      70             : 
      71          20 : void MenuSeparator::handleSourceDirty() {
      72          20 :         _color->setContentSize(Size2(_contentSize.width, 2));
      73          20 :         if (_topLevel) {
      74           0 :                 _color->setAnchorPoint(Vec2(0, 1));
      75           0 :                 _color->setPosition(Vec2(0, _contentSize.height));
      76             :         } else {
      77          20 :                 _color->setAnchorPoint(Vec2(0, 0.5f));
      78          20 :                 _color->setPosition(Vec2(0, _contentSize.height / 2));
      79             :         }
      80          20 : }
      81             : 
      82             : }

Generated by: LCOV version 1.14