LCOV - code coverage report
Current view: top level - xenolith/renderer/material2d/base - MaterialSnackbarData.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 29 31 93.5 %
Date: 2024-05-12 00:16:13 Functions: 8 10 80.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_BASE_MATERIALSNACKBARDATA_H_
      24             : #define XENOLITH_RENDERER_MATERIAL2D_BASE_MATERIALSNACKBARDATA_H_
      25             : 
      26             : #include "MaterialConfig.h"
      27             : #include "XLIcons.h"
      28             : 
      29             : namespace STAPPLER_VERSIONIZED stappler::xenolith::material2d {
      30             : 
      31             : struct SnackbarData {
      32             :         String text;
      33             :         Color textColor = Color::White;
      34             :         float textBlendValue = 0.0f;
      35             : 
      36             :         String buttonText;
      37             :         IconName buttonIcon = IconName::None;
      38             :         Function<void()> buttonCallback = nullptr;
      39             :         Color buttonColor = Color::White;
      40             :         float buttonBlendValue = 0.0f;
      41             :         float delayTime = 4.0f; // in float seconds
      42             : 
      43          10 :         SnackbarData() = default;
      44           2 :         SnackbarData(const SnackbarData &) = default;
      45           0 :         SnackbarData(SnackbarData &&) = default;
      46             :         SnackbarData &operator=(const SnackbarData &) = default;
      47          10 :         SnackbarData &operator=(SnackbarData &&) = default;
      48             : 
      49           0 :         SnackbarData(const StringView &str) : text(str.str<Interface>()) { }
      50             : 
      51           2 :         SnackbarData(const StringView &str, const Color &color, float blendValue)
      52           2 :         : text(str.str<Interface>()), textColor(color), textBlendValue(blendValue) { }
      53             : 
      54           2 :         SnackbarData &withButton(const StringView &str, Function<void()> &&cb, const Color &color = Color::White, float buttonBlend = 0.0f) {
      55           2 :                 buttonText = str.str<Interface>();
      56           2 :                 buttonIcon = IconName::None;
      57           2 :                 buttonCallback = cb;
      58           2 :                 buttonColor = color;
      59           2 :                 buttonBlendValue = buttonBlend;
      60           2 :                 return *this;
      61             :         }
      62             : 
      63           2 :         SnackbarData &withButton(const StringView &str, IconName ic, Function<void()> &&cb, const Color &color = Color::White, float buttonBlend = 0.0f) {
      64           2 :                 buttonText = str.str<Interface>();
      65           2 :                 buttonIcon = ic;
      66           2 :                 buttonCallback = cb;
      67           2 :                 buttonColor = color;
      68           2 :                 buttonBlendValue = buttonBlend;
      69           2 :                 return *this;
      70             :         }
      71             : 
      72           2 :         SnackbarData &withButton(IconName ic, Function<void()> &&cb, const Color &color = Color::White, float buttonBlend = 0.0f) {
      73           2 :                 buttonText = String();
      74           2 :                 buttonIcon = ic;
      75           2 :                 buttonCallback = cb;
      76           2 :                 buttonColor = color;
      77           2 :                 buttonBlendValue = buttonBlend;
      78           2 :                 return *this;
      79             :         }
      80             : 
      81           2 :         SnackbarData &delayFor(float value) {
      82           2 :                 delayTime = value;
      83           2 :                 return *this;
      84             :         }
      85             : };
      86             : 
      87             : }
      88             : 
      89             : #endif /* XENOLITH_RENDERER_MATERIAL2D_BASE_MATERIALSNACKBARDATA_H_ */

Generated by: LCOV version 1.14